batch_set($batch_definition)Opens a new batch.
Operations are added as new batch sets. Batch sets are used to ensure clean code independence, ensuring that several batches submitted by different parts of the code (core / contrib modules) can be processed correctly while not interfering or having to cope with each other. Each batch set gets to specify his own UI messages, operates on its own set of operations and results, and triggers its own 'finished' callback. Batch sets are processed sequentially, with the progress bar starting fresh for every new set.
$batch An array defining the batch. The following keys can be used -- only 'operations' is required, and batch_init() provides default values for the messages.
<?php
array(
array('my_function_1', array($arg1)),
array('my_function_2', array($arg2_1, $arg2_2)),
)
?>includes/form.inc, line 3239
<?php
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 at install time.
$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/> ';
// 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);
}
}
}
?>