Newer
Older
drupal_theme_initialize();

Angie Byron
committed
if (isset($batch)) {
// Add process information
$process_info = array(
'current_set' => 0,
'progressive' => TRUE,

Dries Buytaert
committed
'url' => $url,

Angie Byron
committed
'url_options' => array(),
'source_url' => $_GET['q'],
'redirect' => $redirect,
'theme' => $GLOBALS['theme_key'],

Dries Buytaert
committed
'redirect_callback' => $redirect_callback,
);
$batch += $process_info;
// The batch is now completely built. Allow other modules to make changes
// to the batch so that it is easier to reuse batch processes in other
// environments.

Dries Buytaert
committed
drupal_alter('batch', $batch);
// Assign an arbitrary id: don't rely on a serial column in the 'batch'
// table, since non-progressive batches skip database storage completely.
$batch['id'] = db_next_id();
// Move operations to a job queue. Non-progressive batches will use a
// memory-based queue.
foreach ($batch['sets'] as $key => $batch_set) {
_batch_populate_queue($batch, $key);
}
// Initiate processing.
if ($batch['progressive']) {
// Now that we have a batch id, we can generate the redirection link in
// the generic error message.
$t = get_t();
$batch['error_message'] = $t('Please continue to <a href="@error_url">the error page</a>', array('@error_url' => url($url, array('query' => array('id' => $batch['id'], 'op' => 'finished')))));

Dries Buytaert
committed
// Clear the way for the drupal_goto() redirection to the batch processing
// page, by saving and unsetting the 'destination', if there is any.
if (isset($_GET['destination'])) {
$batch['destination'] = $_GET['destination'];
unset($_GET['destination']);
}
// Store the batch.
db_insert('batch')

Dries Buytaert
committed
->fields(array(
'bid' => $batch['id'],

Dries Buytaert
committed
'timestamp' => REQUEST_TIME,
'token' => drupal_get_token($batch['id']),
'batch' => serialize($batch),
))
->execute();

Dries Buytaert
committed
// Set the batch number in the session to guarantee that it will stay alive.
$_SESSION['batches'][$batch['id']] = TRUE;
// Redirect for processing.

Dries Buytaert
committed
$function = $batch['redirect_callback'];
if (function_exists($function)) {

Angie Byron
committed
$function($batch['url'], array('query' => array('op' => 'start', 'id' => $batch['id'])));

Dries Buytaert
committed
}
}
else {
// Non-progressive execution: bypass the whole progressbar workflow
// and execute the batch in one pass.

Angie Byron
committed
require_once DRUPAL_ROOT . '/includes/batch.inc';
_batch_process();
}
}
}
/**

Angie Byron
committed
* Retrieves the current batch.
*/
function &batch_get() {

Dries Buytaert
committed
// Not drupal_static(), because Batch API operates at a lower level than most
// use-cases for resetting static variables, and we specifically do not want a
// global drupal_static_reset() resetting the batch information. Functions
// that are part of the Batch API and need to reset the batch information may
// call batch_get() and manipulate the result by reference. Functions that are
// not part of the Batch API can also do this, but shouldn't.
static $batch = array();
return $batch;
}
/**
* Populates a job queue with the operations of a batch set.
*
* Depending on whether the batch is progressive or not, the BatchQueue or
* BatchMemoryQueue handler classes will be used.
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
*
* @param $batch
* The batch array.
* @param $set_id
* The id of the set to process.
* @return
* The name and class of the queue are added by reference to the batch set.
*/
function _batch_populate_queue(&$batch, $set_id) {
$batch_set = &$batch['sets'][$set_id];
if (isset($batch_set['operations'])) {
$batch_set += array(
'queue' => array(
'name' => 'drupal_batch:' . $batch['id'] . ':' . $set_id,
'class' => $batch['progressive'] ? 'BatchQueue' : 'BatchMemoryQueue',
),
);
$queue = _batch_queue($batch_set);
$queue->createQueue();
foreach ($batch_set['operations'] as $operation) {
$queue->createItem($operation);
}
unset($batch_set['operations']);
}
}
/**
* Returns a queue object for a batch set.
*
* @param $batch_set
* The batch set.
* @return
* The queue object.
*/
function _batch_queue($batch_set) {
static $queues;
// The class autoloader is not available when running update.php, so make
// sure the files are manually included.
if (!isset($queues)) {
$queues = array();
require_once DRUPAL_ROOT . '/modules/system/system.queue.inc';
require_once DRUPAL_ROOT . '/includes/batch.queue.inc';
}
if (isset($batch_set['queue'])) {
$name = $batch_set['queue']['name'];
$class = $batch_set['queue']['class'];
if (!isset($queues[$class][$name])) {
$queues[$class][$name] = new $class($name);
}
return $queues[$class][$name];
}
}
/**
* @} End of "defgroup batch".
*/