I am trying to run a batch job of importing items from a csv file. When I click submit on my form and my batch process starts, I do get a batch process bar which says its progressing, but it never calls my callback function or my finished function. I've done a dpm()
of th $batch array before I run it, and it seems to be in order. What am I missing?
$count = 1;
while($count <= count($csv) ) {
$operations[] = array('ons_institutional_subscriber_importer_import', array(array_slice($csv, $count, $count + 10)));
$count = $count + 10;
}
$batch = array(
'title' => t('Importing Institutional Subscribers'),
'operations' => $operations,
'finished' => 'ons_institutional_subscriber_importer_finished',
'init_message' => t('Import is starting.'),
'progress_message' => t('Processed @current out of @total.'),
'error_message' => t('Import has encountered an error.'),
);
dpm($batch);
batch_set($batch);
batch_process();
and my callback functions
function ons_institutional_subscriber_importer_import($csv, &$context) {
dpm('hello');
//more code here...
}
function ons_institutional_subscriber_importer_finished($success, $results, $operations) {
if ($success) {
$message = format_plural(count($results), 'One post processed.', '@count posts processed.');
}
else {
$message = t('Finished with an error.');
}
drupal_set_message($message);
}
<pre>
prevents syntax highlight and makes reading code harder than it needs to be.$batch['file']
to specify the file.