I have a batch process where the callback_batch_operation() functions are never called, as showed when logging with some Devel dd()
calls.
Here is the involved code fundamental parts (all this in the same multilang.admin.inc
file):
function multilang_default_form_submit($form, &$form_state) {
$operations = array();
if ($categories = $form_state['values']['default']) {
foreach ($categories as $category) {
if ($category) {
$operations[] = array('multilang_default_process', $category);
}
}
}
$batch = array(
'title' => '...',
'init_message' => '...',
'operations' => $operations,
'finished' => 'multilang_default_finished',
'file' => drupal_get_path('module', 'multilang') . '/multilang.admin.inc',
);
dd($batch, '$batch'); ## log
batch_set($batch);
}
function multilang_default_process($category, &$context) {
dd(func_get_args(), 'default_process'); ## log
// ...do the desired job...
}
function multilang_default_finished($success, $results, $operations) {
dd(func_get_args(), 'multilang_default_finished() args'); ## log
// ...send appropriate messages...
}
And here is the log result, in a case where only one operation was required:
$batch: Array
(
[title] => Resetting Multilang configuration
[operations] => Array
(
[0] => Array
(
[0] => multilang_default_process
[1] => multilang_exclude_paths
)
)
[finished] => multilang_default_finished
[file] => sites/all/modules/multilang/multilang.admin.inc
)
default_finished: Array
(
[0] => 1
[1] => Array
(
)
[2] => Array
(
)
[3] => 0 sec
)
The above log shows that the multilang_default_process()
function is not called, though correctly stated as callback_batch_operation in $batch
.
Obviously the first suspicion after the function's correct spelling, goes to its localization through the file
index in $batch
.
But not only I multiple checked it, but also we can notice that the default_finished()
function gets called, while it is localized through the same file
index.
This is also ensured by the fact that, if I intentionally set file
to another, incorrect value, then the default_finished()
function is not called.
Another puzzling thing (at least at my eyes) is the default_finished()
passed arguments: despite no callback_batch_operation was called, $success
(index 0) is set to TRUE
and (remaining to process) $operations
(index 2) is empty.
Am I missing (like it happens too often :-) something stupidly obvious...?