From ebb599f4db60fcba217667b1f8f164a07fe0841c Mon Sep 17 00:00:00 2001 From: Gordon Heydon Date: Fri, 21 Aug 2009 23:55:22 +1000 Subject: [PATCH] Changes to batch API to allow better user of progressive mode in non HTML enviroments. - Add check of function with drupal_function_exists() - Fix up call to use $redirect_callback instead of the hard coded drupal_goto - change default for $redirect-callback to NULL - Change callback to only ass the batch id if it is not NULL or drupal_goto - Add $op to the callback so that it will be called on start and finish. - Remote the _batch_do_shell(). - Fix up some of the docs. - Remove a blank line. - Fix up PHPWTF with TRUE == 'drupal_goto' - Fix up elseif coding standard - Change is_null() to empty() - Remote checks for null in elseif() - make changes to call drupal_goto directly - change call to be the same as drupal_goto() but use the new query array --- includes/batch.inc | 4 +++- includes/form.inc | 12 ++++++++++-- includes/update.inc | 7 +++++-- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git includes/batch.inc includes/batch.inc index 5cdcec0..37baf07 100644 --- includes/batch.inc +++ includes/batch.inc @@ -445,7 +445,9 @@ function _batch_finished() { // If no redirection happened, save the final $form_state value to be // retrieved by drupal_get_form() and redirect to the originating page. $_SESSION['batch_form_state'] = $_batch['form_state']; - drupal_goto($_batch['source_page']); + if (function_exists($_batch['redirect_callback'])) { + $_batch['redirect_callback']($_batch['source_url'], array('op' => 'finish', 'id' => $_batch['id'])); + } } } diff --git includes/form.inc includes/form.inc index d92e2a7..9466b80 100644 --- includes/form.inc +++ includes/form.inc @@ -2931,8 +2931,13 @@ function batch_set($batch_definition) { * @param $url * (optional - should only be used for separate scripts like update.php) * 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 = NULL, $redirect_callback = NULL) { $batch =& batch_get(); drupal_theme_initialize(); @@ -2947,6 +2952,7 @@ function batch_process($redirect = NULL, $url = NULL) { 'source_page' => $_GET['q'], 'redirect' => $redirect, 'theme' => $GLOBALS['theme_key'], + 'redirect_callback' => empty($redirect_callback) ? 'drupal_callback' : $redirect_callback, ); $batch += $process_info; @@ -2984,7 +2990,9 @@ function batch_process($redirect = NULL, $url = NULL) { // Set the batch number in the session to guarantee that it will stay alive. $_SESSION['batches'][$batch['id']] = TRUE; - drupal_goto($batch['url'], 'op=start&id=' . $batch['id']); + if (function_exists($batch['redirect_callback'])) { + $batch['redirect_callback']($batch['url'], array('op' => 'start', 'id' => $batch['id'])); + } } else { // Non-progressive execution: bypass the whole progressbar workflow diff --git includes/update.inc includes/update.inc index 21bf1ae..290da95 100644 --- includes/update.inc +++ includes/update.inc @@ -368,8 +368,11 @@ class DrupalUpdateException extends Exception { } * scripts like update.php). * @param $batch * 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 = NULL) { // During the update, bring the site offline so that schema changes do not // affect visiting users. $_SESSION['maintenance_mode'] = variable_get('maintenance_mode', FALSE); @@ -400,7 +403,7 @@ function update_batch($start, $redirect = NULL, $url = NULL, $batch = array()) { 'file' => 'includes/update.inc', ); batch_set($batch); - batch_process($redirect, $url); + batch_process($redirect, $url, $redirect_callback); } /** -- 1.6.3.3