First, make sure you set the finished process in your batch process.
$batch = array(
'title' => t('Merging content ...'),
'operations' => array(
array('batch_import_import', array($col1, $col2), //Note we pass 2 variables here.
),
'finished' => 'batch_import_finished', // set this!
'init_message' => t('Connectng to the base site ...'),
'progress_message' => t('Processed @current out of @total.'),
'error_message' => t('An error occurred during processing'),
'progressive' => FALSE
);
...
batch_set('admin/content');
Then, in your worker function, you can take the last argument passed to it as $context.
For an example, from above example above, your worker function should be something like this:
function batch_import_import($col1, $col2, &$context) {
//do the stuff.
if (!isset($context['results']['created'], $context['results']['updated'])) {
$context['results']['created'] = 0;
$context['results']['updated'] = 0;
}
$context['results']['created']++; // is_new == TRUE or some logic.
$context['results']['updated']++; // add some logic to determine created or updated.
}
and then in the finish function, you get $context['results']
as the second argument.
batch_import_finished($success, $results, $operations) {
if ($success) {
$message = t('Nodes created: @count', array('@count' => $results['created'])).'<br />';
$message .= t('Nodes updated: @count', array('@count' => $results['updated']));
}
else {
$message = t('some errors');
}
drupal_set_message($message);
}
I have also corrected the $message as you can use t()
function here.
Note that you pass $context
by reference.
See batch_api examples for more information. This is just some code copied from a module I was developing the other day.
In the finished function, $operations
contain unprocessed items.