8.5.x form.api.php callback_batch_finished($success, $results, $operations)
8.0.x form.api.php callback_batch_finished($success, $results, $operations)
8.1.x form.api.php callback_batch_finished($success, $results, $operations)
8.2.x form.api.php callback_batch_finished($success, $results, $operations)
8.3.x form.api.php callback_batch_finished($success, $results, $operations)
8.4.x form.api.php callback_batch_finished($success, $results, $operations)
8.6.x form.api.php callback_batch_finished($success, $results, $operations)
7.x form.api.php callback_batch_finished($success, $results, $operations)

Complete a batch process.

Callback for batch_set().

This callback may be specified in a batch to perform clean-up operations, or to analyze the results of the batch operations.

Parameters

$success: A boolean indicating whether the batch has completed successfully.

$results: The value set in $context['results'] by callback_batch_operation().

$operations: If $success is FALSE, contains the operations that remained unprocessed.

Related topics

File

modules/system/form.api.php, line 107
Callbacks provided by the form system.

Code

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

    // Here we do something meaningful with the results.
    $message = t("!count items were processed.", array(
      '!count' => count($results),
    ));
    $message .= theme('item_list', array(
      'items' => $results,
    ));
    drupal_set_message($message);
  }
  else {

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