From 9b005901182b766e0de6e682a9117dfecdf38139 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 --- includes/form.inc | 9 +++++++-- includes/update.inc | 7 +++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git includes/form.inc includes/form.inc index ee35a6b..7fdbd63 100644 --- includes/form.inc +++ includes/form.inc @@ -2854,8 +2854,11 @@ 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. */ -function batch_process($redirect = NULL, $url = NULL) { +function batch_process($redirect = NULL, $url = NULL, $redirect_callback = 'drupal_goto') { $batch =& batch_get(); if (isset($batch)) { @@ -2905,7 +2908,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 ($redirect_callback && drupal_function_exists($redirect_callback)) { + call_user_func_array($redirect_callback, array($batch['url'], 'op=start&id=' . $batch['id'])); + } } else { // Non-progressive execution: bypass the whole progressbar workflow diff --git includes/update.inc includes/update.inc index 0b022cd..65582b0 100644 --- includes/update.inc +++ includes/update.inc @@ -423,8 +423,11 @@ function update_do_one($module, $number, &$context) { * 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 = 'drupal_goto') { // During the update, bring the site offline so that schema changes do not // affect visiting users. $_SESSION['site_offline'] = variable_get('site_offline', FALSE); @@ -455,7 +458,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.4.rc0.17.gd9eb0