function batch_set


Error message

User warning: The following module is missing from the file system: theme/theme. For information about how to fix this, see the documentation page. in _drupal_trigger_error_with_delayed_logging() (line 1156 of /var/www/html/elmsln_community/
cis7 batch_set($batch_definition)
cle7 batch_set($batch_definition)
elmsmedia7 batch_set($batch_definition)
icor7 batch_set($batch_definition)
meedjum_blog7 batch_set($batch_definition)
mooc7 batch_set($batch_definition)

Adds a new batch.

Batch operations are added as new batch sets. Batch sets are used to spread processing (primarily, but not exclusively, forms processing) over several page requests. This helps to ensure that the processing is not interrupted due to PHP timeouts, while users are still able to receive feedback on the progress of the ongoing operations. Combining related operations into distinct batch sets provides clean code independence for each batch set, ensuring that two or more batches, submitted independently, can be processed without mutual interference. Each batch set may specify its own set of operations and results, produce its own UI messages, and trigger its own 'finished' callback. Batch sets are processed sequentially, with the progress bar starting afresh for each new set.


$batch_definition: An associative array defining the batch, with the following elements (all are optional except as noted):

  • operations: (required) Array of function calls to be performed. Example:
      array('my_function_1', array($arg1)),
      array('my_function_2', array($arg2_1, $arg2_2)),
  • title: A safe, translated string to use as the title for the progress page. Defaults to t('Processing').
  • init_message: Message displayed while the processing is initialized. Defaults to t('Initializing.').
  • progress_message: Message displayed while processing the batch. Available placeholders are @current, @remaining, @total, @percentage, @estimate and @elapsed. Defaults to t('Completed @current of @total.').
  • error_message: Message displayed if an error occurred while processing the batch. Defaults to t('An error has occurred.').
  • finished: Name of a function to be executed after the batch has completed. This should be used to perform any result massaging that may be needed, and possibly save data in $_SESSION for display after final page redirection.
  • file: Path to the file containing the definitions of the 'operations' and 'finished' functions, for instance if they don't reside in the main .module file. The path should be relative to base_path(), and thus should be built using drupal_get_path().
  • css: Array of paths to CSS files to be used on the progress page.
  • url_options: options passed to url() when constructing redirect URLs for the batch.

Related topics

47 calls to batch_set()
accessibility_tests_list_submit in sites/all/modules/ulmus/accessibility/
Form submit callback for importing tests.
batch_test_chained_form_submit_1 in modules/simpletest/tests/batch_test.module
Submit handler #1 for the chained form.
batch_test_chained_form_submit_2 in modules/simpletest/tests/batch_test.module
Submit handler #2 for the chained form.
batch_test_chained_form_submit_4 in modules/simpletest/tests/batch_test.module
Submit handler #4 for the chained form.
batch_test_large_percentage in modules/simpletest/tests/batch_test.module
Menu callback: fire a batch process without a form submission.

... See full list


includes/, line 4417
Functions for form and batch generation and processing.


function batch_set($batch_definition) {
  if ($batch_definition) {
    $batch = &batch_get();

    // Initialize the batch if needed.
    if (empty($batch)) {
      $batch = array(
        'sets' => array(),
        'has_form_submits' => FALSE,

    // Base and default properties for the batch set.
    // Use get_t() to allow batches during installation.
    $t = get_t();
    $init = array(
      'sandbox' => array(),
      'results' => array(),
      'success' => FALSE,
      'start' => 0,
      'elapsed' => 0,
    $defaults = array(
      'title' => $t('Processing'),
      'init_message' => $t('Initializing.'),
      'progress_message' => $t('Completed @current of @total.'),
      'error_message' => $t('An error has occurred.'),
      'css' => array(),
    $batch_set = $init + $batch_definition + $defaults;

    // Tweak init_message to avoid the bottom of the page flickering down after
    // init phase.
    $batch_set['init_message'] .= '<br/>&nbsp;';

    // The non-concurrent workflow of batch execution allows us to save
    // numberOfItems() queries by handling our own counter.
    $batch_set['total'] = count($batch_set['operations']);
    $batch_set['count'] = $batch_set['total'];

    // Add the set to the batch.
    if (empty($batch['id'])) {
      // The batch is not running yet. Simply add the new set.
      $batch['sets'][] = $batch_set;
    else {
      // The set is being added while the batch is running. Insert the new set
      // right after the current one to ensure execution order, and store its
      // operations in a queue.
      $index = $batch['current_set'] + 1;
      $slice1 = array_slice($batch['sets'], 0, $index);
      $slice2 = array_slice($batch['sets'], $index);
      $batch['sets'] = array_merge($slice1, array($batch_set), $slice2);
      _batch_populate_queue($batch, $index);