Skip to content
Snippets Groups Projects
Commit 0e161b66 authored by Dries Buytaert's avatar Dries Buytaert
Browse files

- Patch #555762 by gordon, sun | yched, chx, moshe weitzman, KiamLaLuno,...

- Patch #555762 by gordon, sun | yched, chx, moshe weitzman, KiamLaLuno, lilou: improvements to batch API.
parent 919d94be
No related branches found
No related tags found
No related merge requests found
...@@ -445,7 +445,10 @@ function _batch_finished() { ...@@ -445,7 +445,10 @@ function _batch_finished() {
// If no redirection happened, save the final $form_state value to be // If no redirection happened, save the final $form_state value to be
// retrieved by drupal_get_form() and redirect to the originating page. // retrieved by drupal_get_form() and redirect to the originating page.
$_SESSION['batch_form_state'] = $_batch['form_state']; $_SESSION['batch_form_state'] = $_batch['form_state'];
drupal_goto($_batch['source_page']); $function = $_batch['redirect_callback'];
if (function_exists($function)) {
$function($_batch['source_url'], array('op' => 'finish', 'id' => $_batch['id']));
}
} }
} }
......
...@@ -2895,25 +2895,34 @@ function batch_set($batch_definition) { ...@@ -2895,25 +2895,34 @@ function batch_set($batch_definition) {
* @param $url * @param $url
* (optional - should only be used for separate scripts like update.php) * (optional - should only be used for separate scripts like update.php)
* URL of the batch processing page. * URL of the batch processing page.
* @param $redirect_callback
* (optional) Specify a function to be called to redirect to the progressive
* processing page. By default drupal_goto() will be used to redirect to a
* page which will do the progressive page. Specifying another function will
* allow the progressive processing to be processed differently.
*/ */
function batch_process($redirect = NULL, $url = NULL) { function batch_process($redirect = NULL, $url = 'batch', $redirect_callback = 'drupal_goto') {
$batch =& batch_get(); $batch =& batch_get();
drupal_theme_initialize(); drupal_theme_initialize();
if (isset($batch)) { if (isset($batch)) {
// Add process information // Add process information
$url = isset($url) ? $url : 'batch';
$process_info = array( $process_info = array(
'current_set' => 0, 'current_set' => 0,
'progressive' => TRUE, 'progressive' => TRUE,
'url' => isset($url) ? $url : 'batch', 'url' => $url,
'source_page' => $_GET['q'], 'source_page' => $_GET['q'],
'redirect' => $redirect, 'redirect' => $redirect,
'theme' => $GLOBALS['theme_key'], 'theme' => $GLOBALS['theme_key'],
'redirect_callback' => $redirect_callback,
); );
$batch += $process_info; $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 enviroments.
drupal_alter('batch', $batch);
if ($batch['progressive']) { if ($batch['progressive']) {
// Clear the way for the drupal_goto() redirection to the batch processing // Clear the way for the drupal_goto() redirection to the batch processing
// page, by saving and unsetting the 'destination', if there is any. // page, by saving and unsetting the 'destination', if there is any.
...@@ -2948,7 +2957,10 @@ function batch_process($redirect = NULL, $url = NULL) { ...@@ -2948,7 +2957,10 @@ function batch_process($redirect = NULL, $url = NULL) {
// Set the batch number in the session to guarantee that it will stay alive. // Set the batch number in the session to guarantee that it will stay alive.
$_SESSION['batches'][$batch['id']] = TRUE; $_SESSION['batches'][$batch['id']] = TRUE;
drupal_goto($batch['url'], array('op' => 'start', 'id' => $batch['id'])); $function = $batch['redirect_callback'];
if (function_exists($function)) {
$function($batch['url'], array('op' => 'start', 'id' => $batch['id']));
}
} }
else { else {
// Non-progressive execution: bypass the whole progressbar workflow // Non-progressive execution: bypass the whole progressbar workflow
......
...@@ -361,8 +361,11 @@ class DrupalUpdateException extends Exception { } ...@@ -361,8 +361,11 @@ class DrupalUpdateException extends Exception { }
* scripts like update.php). * scripts like update.php).
* @param $batch * @param $batch
* Optional parameters to pass into the batch API. * Optional parameters to pass into the batch API.
* @param $redirect_callback
* (optional) Specify a function to be called to redirect to the progressive
* processing page.
*/ */
function update_batch($start, $redirect = NULL, $url = NULL, $batch = array()) { function update_batch($start, $redirect = NULL, $url = NULL, $batch = array(), $redirect_callback = 'drupal_goto') {
// During the update, bring the site offline so that schema changes do not // During the update, bring the site offline so that schema changes do not
// affect visiting users. // affect visiting users.
$_SESSION['maintenance_mode'] = variable_get('maintenance_mode', FALSE); $_SESSION['maintenance_mode'] = variable_get('maintenance_mode', FALSE);
...@@ -393,7 +396,7 @@ function update_batch($start, $redirect = NULL, $url = NULL, $batch = array()) { ...@@ -393,7 +396,7 @@ function update_batch($start, $redirect = NULL, $url = NULL, $batch = array()) {
'file' => 'includes/update.inc', 'file' => 'includes/update.inc',
); );
batch_set($batch); batch_set($batch);
batch_process($redirect, $url); batch_process($redirect, $url, $redirect_callback);
} }
/** /**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment