batch_process
- 6
batch_process($redirect = NULL, $url = NULL)
- 7
batch_process($redirect = NULL, $url = 'batch', $redirect_callback = 'drupal_goto')
Processes the batch.
Unless the batch has been marked with 'progressive' = FALSE, the function
issues a drupal_goto and thus ends page execution.
This function is not needed in form submit handlers; Form API takes care
of batches that were set during form submission.
Parameters
$redirect
(optional) Path to redirect to when the batch has finished processing.
$url
(optional - should only be used for separate scripts like update.php)
URL of the batch processing page.
Related topics
- Batch operations
- Functions allowing forms processing to be spread out over several page
requests, thus ensuring that the processing does not get interrupted
because of a PHP timeout, while allowing the user to receive feedback
on the progress of the ongoing operations.
- Form generation
- Functions to enable the processing and display of HTML forms.
Code
drupal/includes/form.inc, line 2500
<?php
function batch_process($redirect = NULL, $url = NULL) {
$batch =& batch_get();
if (isset($batch)) {
$url = isset($url) ? $url : 'batch';
$process_info = array(
'current_set' => 0,
'progressive' => TRUE,
'url' => isset($url) ? $url : 'batch',
'source_page' => $_GET['q'],
'redirect' => $redirect,
);
$batch += $process_info;
if ($batch['progressive']) {
if (isset($_REQUEST['destination'])) {
$batch['destination'] = $_REQUEST['destination'];
unset($_REQUEST['destination']);
}
elseif (isset($_REQUEST['edit']['destination'])) {
$batch['destination'] = $_REQUEST['edit']['destination'];
unset($_REQUEST['edit']['destination']);
}
db_query("INSERT INTO {batch} (token, timestamp) VALUES ('', %d)", time());
$batch['id'] = db_last_insert_id('batch', 'bid');
$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')))));
db_query("UPDATE {batch} SET token = '%s', batch = '%s' WHERE bid = %d", drupal_get_token($batch['id']), serialize($batch), $batch['id']);
drupal_goto($batch['url'], 'op=start&id='. $batch['id']);
}
else {
require_once './includes/batch.inc';
_batch_process();
}
}
}
?>