You are here

function batch_example_finished in Examples for Developers 7

Same name and namespace in other branches
  1. 8 batch_example/batch_example.module \batch_example_finished()
  2. 6 batch_example/batch_example.module \batch_example_finished()
  3. 3.x modules/batch_example/batch_example.module \batch_example_finished()

Batch 'finished' callback used by both batch 1 and batch 2.

Related topics

2 string references to 'batch_example_finished'
batch_example_batch_1 in batch_example/batch_example.module
Batch 1 definition: Load the node with the lowest nid 1000 times.
batch_example_batch_2 in batch_example/batch_example.module
Batch 2 : Prepare a batch definition that will load all nodes 20 times.

File

batch_example/batch_example.module, line 262
Outlines how a module can use the Batch API.

Code

function batch_example_finished($success, $results, $operations) {
  if ($success) {

    // Here we could do something meaningful with the results.
    // We just display the number of nodes we processed...
    drupal_set_message(t('@count results processed in @requests HTTP requests.', array(
      '@count' => count($results),
      '@requests' => _batch_example_get_http_requests(),
    )));
    drupal_set_message(t('The final result was "%final"', array(
      '%final' => end($results),
    )));
  }
  else {

    // An error occurred.
    // $operations contains the operations that remained unprocessed.
    $error_operation = reset($operations);
    drupal_set_message(t('An error occurred while processing @operation with arguments : @args', array(
      '@operation' => $error_operation[0],
      '@args' => print_r($error_operation[0], TRUE),
    )), 'error');
  }
}