Hello every one!
I'm using this extension for my grocerycrud implementation (GC v. 1.6.1 over CI 3.1.11): https://github.com/greysama/extension_grocery_crud
Everything works good except when I try to do an after delete callback.
My controller's method looks like this:
public function master()
{
try {
$crud = new Extension_grocery_CRUD();
$crud->gc_initialize('entregas', 'entrega');
$crud->order_by('fecha_entrega', 'DESC');
$crud->columns('recoleccion', 'codigo_entrega', 'fecha_entrega', 'id_vehiculo', 'id_chofer');
[ more staff here ]
$crud->callback_after_delete( array($this,'after_delete_entrega') );
$output = $crud->render();
$this->_theme_output($output);
} catch (Exception $e) {
show_error($e->getMessage() . ' --- ' . $e->getTraceAsString());
}
}
the callback within the same controller is:
public function after_delete_entrega($primary_key){
log_message('DEBUG','HOLA3 HOLA3 HOLA3 HOLA3 HOLA3 '); // NEVER LOGGED
$this->db->query("DELETE FROM entregas_detalle WHERE id_entrega=$primary_key");
}
When it reaches callback_after_delete() in the extended library it jumps from 1 ==> to 2 ==> without passing or calling extended_callback_after_delete() therefore it never reaches after_delete_entrega() in the controller.
this is in the extention:
public function callback_after_delete($callback = null,$override_all=0){
if(!$override_all){
$this->callback_after_delete_ext[] = $callback;
if($this->callback_after_delete == null){
1 ==> $this->callback_after_delete = array($this,'extended_callback_after_delete') ;
}
}else{
parent::callback_after_delete($callback);
}
2 ==> return $this;
}
protected function extended_callback_after_delete($primary_key){
$continue=1;
foreach ($this->callback_after_delete_ext as $key => $callback) {
if($continue){
log_message('DEBUG','CALLBACK CALLBACK CALLBACK CALLBACK '); // NEVER LOGGED
$continue = call_user_func($callback, $primary_key);
}
}
return $continue;
}
My guess is that when I (soft) delete a record and the function soft_delete_me() is called (by the way the soft deletion works perfect!), it is not returning true or that the "delete" process was completed successfully so the after delete callback is never called
public function soft_delete_me($primary_key)
{
$field = $this->extension_extras['soft_delete']['field'];
$value = $this->extension_extras['soft_delete']['deleted_value'];
return $this->_ci->db->update($this->basic_db_table, array($field => $value, 'sys_deleted_on' => date("Y-m-d H:i:s")), array($this->get_primary_key() => $primary_key));
}
I've also tried passing 1 to run the callback as the grocerycrud library but didn't work;
$crud->callback_after_delete( array($this,'after_delete_entrega') , 1 );
When I do this it never calls the callback_after_delete() function in the extension because of the extra parameter of course.
Am I missing something or is related whit the soft deletion process?
NOTE: 1 ==> and 2 ==> are just for reference and they are not part of my code.