--- C:\Users\Edward\Webs\drupal\includes\batch.inc	2008-01-15 23:25:58.760000000 -0500
+++ C:\Users\Edward\Webs\drupal\includes\batch.inc.formatted	2008-01-15 23:59:10.387000000 -0500
@@ -1,6 +1,7 @@
 <?php
 // $Id: batch.inc,v 1.14 2007/12/20 11:57:20 goba Exp $
 
+
 /**
  * @file Batch processing API for processes to run in multiple HTTP requests.
  */
@@ -9,8 +10,8 @@
  * State-based dispatcher for the batch processing page.
  */
 function _batch_page() {
-  $batch =& batch_get();
-
+  $batch = &batch_get();
+  
   // Retrieve the current state of batch from db.
   if (isset($_REQUEST['id']) && $data = db_result(db_query("SELECT batch FROM {batch} WHERE bid = %d AND token = '%s'", $_REQUEST['id'], drupal_get_token($_REQUEST['id'])))) {
     $batch = unserialize($data);
@@ -18,32 +19,32 @@
   else {
     return FALSE;
   }
-
+  
   // Register database update for end of processing.
   register_shutdown_function('_batch_shutdown');
-
+  
   $op = isset($_REQUEST['op']) ? $_REQUEST['op'] : '';
   $output = NULL;
   switch ($op) {
     case 'start':
       $output = _batch_start();
       break;
-
+    
     case 'do':
       // JS-version AJAX callback.
       _batch_do();
       break;
-
+    
     case 'do_nojs':
       // Non-JS progress page.
       $output = _batch_progress_page_nojs();
       break;
-
+    
     case 'finished':
       $output = _batch_finished();
       break;
   }
-
+  
   return $output;
 }
 
@@ -68,13 +69,13 @@
  */
 function _batch_progress_page_js() {
   $batch = batch_get();
-
+  
   // The first batch set gets to set the page title
   // and the initialization and error messages.
   $current_set = _batch_current_set();
   drupal_set_title($current_set['title']);
   drupal_add_js('misc/progress.js', 'core', 'header', FALSE, FALSE);
-
+  
   $url = url($batch['url'], array('query' => array('id' => $batch['id'])));
   $js_setting = array(
     'batch' => array(
@@ -85,7 +86,7 @@
   );
   drupal_add_js($js_setting, 'setting');
   drupal_add_js('misc/batch.js', 'core', 'header', FALSE, FALSE);
-
+  
   $output = '<div id="progress"></div>';
   return $output;
 }
@@ -101,10 +102,10 @@
     drupal_set_title(t('Error'));
     return '';
   }
-
+  
   // Perform actual processing.
   list($percentage, $message) = _batch_process();
-
+  
   drupal_json(array('status' => TRUE, 'percentage' => $percentage, 'message' => $message));
 }
 
@@ -112,46 +113,45 @@
  * Batch processing page without JavaScript support.
  */
 function _batch_progress_page_nojs() {
-  $batch =& batch_get();
+  $batch = &batch_get();
   $current_set = _batch_current_set();
-
+  
   drupal_set_title($current_set['title']);
-
+  
   $new_op = 'do_nojs';
-
+  
   if (!isset($batch['running'])) {
     // This is the first page so we return some output immediately.
-    $percentage = 0;
-    $message = $current_set['init_message'];
+    $percentage       = 0;
+    $message          = $current_set['init_message'];
     $batch['running'] = TRUE;
   }
   else {
     // This is one of the later requests: do some processing first.
-
     // Error handling: if PHP dies due to a fatal error (e.g. non-existant
     // function), it will output whatever is in the output buffer,
     // followed by the error message.
     ob_start();
     $fallback = $current_set['error_message'] .'<br/>'. $batch['error_message'];
     $fallback = theme('maintenance_page', $fallback, FALSE, FALSE);
-
+    
     // We strip the end of the page using a marker in the template, so any
     // additional HTML output by PHP shows up inside the page rather than
     // below it. While this causes invalid HTML, the same would be true if
     // we didn't, as content is not allowed to appear after </html> anyway.
     list($fallback) = explode('<!--partial-->', $fallback);
     print $fallback;
-
+    
     // Perform actual processing.
     list($percentage, $message) = _batch_process($batch);
     if ($percentage == 100) {
       $new_op = 'finished';
     }
-
+    
     // PHP did not die : remove the fallback output.
     ob_end_clean();
   }
-
+  
   $url = url($batch['url'], array('query' => array('id' => $batch['id'], 'op' => $new_op)));
   drupal_set_html_head('<meta http-equiv="Refresh" content="0; URL='. $url .'">');
   $output = theme('progress_bar', $percentage, $message);
@@ -163,32 +163,32 @@
  * was not set for progressive execution - e.g forms submitted by drupal_execute).
  */
 function _batch_process() {
-  $batch =& batch_get();
-  $current_set =& _batch_current_set();
+  $batch       = &batch_get();
+  $current_set = &_batch_current_set();
   $set_changed = TRUE;
-
+  
   if ($batch['progressive']) {
     timer_start('batch_processing');
   }
-
+  
   while (!$current_set['success']) {
     // If this is the first time we iterate this batch set in the current
     // request, we check if it requires an additional file for functions
     // definitions.
     if ($set_changed && isset($current_set['file']) && is_file($current_set['file'])) {
-      include_once($current_set['file']);
+      include_once ($current_set['file']);
     }
-
+    
     $finished = 1;
     $task_message = '';
     if ((list($function, $args) = reset($current_set['operations'])) && function_exists($function)) {
       // Build the 'context' array, execute the function call,
       // and retrieve the user message.
-      $batch_context = array('sandbox' => &$current_set['sandbox'], 'results' => &$current_set['results'], 'finished' => &$finished, 'message' => &$task_message);
+      $batch_context = array('sandbox' => & $current_set['sandbox'], 'results' => & $current_set['results'], 'finished' => & $finished, 'message' => & $task_message);
       // Process the current operation.
       call_user_func_array($function, array_merge($args, array(&$batch_context)));
     }
-
+    
     if ($finished == 1) {
       // Make sure this step isn't counted double when computing $current.
       $finished = 0;
@@ -196,7 +196,7 @@
       array_shift($current_set['operations']);
       $current_set['sandbox'] = array();
     }
-
+    
     // If the batch set is completed, browse through the remaining sets,
     // executing 'control sets' (stored form submit handlers) along the way -
     // this might in turn insert new batch sets.
@@ -204,62 +204,59 @@
     $set_changed = FALSE;
     $old_set = $current_set;
     while (empty($current_set['operations']) && ($current_set['success'] = TRUE) && _batch_next_set()) {
-      $current_set =& _batch_current_set();
+      $current_set = &_batch_current_set();
       $set_changed = TRUE;
     }
     // At this point, either $current_set is a 'real' batch set (has operations),
     // or all sets have been completed.
-
     // If we're in progressive mode, stop after 1 second.
     if ($batch['progressive'] && timer_read('batch_processing') > 1000) {
       break;
     }
   }
-
+  
   if ($batch['progressive']) {
     // Gather progress information.
-
     // Reporting 100% progress will cause the whole batch to be considered
     // processed. If processing was paused right after moving to a new set,
     // we have to use the info from the new (unprocessed) one.
     if ($set_changed && isset($current_set['operations'])) {
       // Processing will continue with a fresh batch set.
-      $remaining = count($current_set['operations']);
-      $total = $current_set['total'];
+      $remaining        = count($current_set['operations']);
+      $total            = $current_set['total'];
       $progress_message = $current_set['init_message'];
-      $task_message = '';
+      $task_message     = '';
     }
     else {
-      $remaining = count($old_set['operations']);
-      $total = $old_set['total'];
+      $remaining        = count($old_set['operations']);
+      $total            = $old_set['total'];
       $progress_message = $old_set['progress_message'];
     }
-
+    
     $current    = $total - $remaining + $finished;
     $percentage = $total ? floor($current / $total * 100) : 100;
-    $values = array(
-      '@remaining'  => $remaining,
-      '@total'      => $total,
-      '@current'    => floor($current),
+    $values     = array(
+      '@remaining' => $remaining,
+      '@total' => $total,
+      '@current' => floor($current),
       '@percentage' => $percentage,
-      );
+    );
     $message = strtr($progress_message, $values) .'<br/>';
     $message .= $task_message ? $task_message : '&nbsp';
-
+    
     return array($percentage, $message);
   }
   else {
     // If we're not in progressive mode, the whole batch has been processed by now.
     return _batch_finished();
   }
-
 }
 
 /**
  * Retrieve the batch set being currently processed.
  */
-function &_batch_current_set() {
-  $batch =& batch_get();
+function & _batch_current_set() {
+  $batch = &batch_get();
   return $batch['sets'][$batch['current_set']];
 }
 
@@ -269,10 +266,10 @@
  * additional batch sets).
  */
 function _batch_next_set() {
-  $batch =& batch_get();
+  $batch = &batch_get();
   if (isset($batch['sets'][$batch['current_set'] + 1])) {
     $batch['current_set']++;
-    $current_set =& _batch_current_set();
+    $current_set = &_batch_current_set();
     if (isset($current_set['form_submit']) && ($function = $current_set['form_submit']) && function_exists($function)) {
       // We use our stored copies of $form and $form_state, to account for
       // possible alteration by the submit handlers.
@@ -288,35 +285,35 @@
  * and resolve page redirection.
  */
 function _batch_finished() {
-  $batch =& batch_get();
-
+  $batch = &batch_get();
+  
   // Execute the 'finished' callbacks for each batch set.
   foreach ($batch['sets'] as $key => $batch_set) {
     if (isset($batch_set['finished'])) {
       // Check if the set requires an additional file for functions definitions.
       if (isset($batch_set['file']) && is_file($batch_set['file'])) {
-        include_once($batch_set['file']);
+        include_once ($batch_set['file']);
       }
       if (function_exists($batch_set['finished'])) {
         $batch_set['finished']($batch_set['success'], $batch_set['results'], $batch_set['operations']);
       }
     }
   }
-
+  
   // Cleanup the batch table and unset the global $batch variable.
   if ($batch['progressive']) {
     db_query("DELETE FROM {batch} WHERE bid = %d", $batch['id']);
   }
   $_batch = $batch;
   $batch = NULL;
-
+  
   // Redirect if needed.
   if ($_batch['progressive']) {
     // Put back the 'destination' that was saved in batch_process().
     if (isset($_batch['destination'])) {
       $_REQUEST['destination'] = $_batch['destination'];
     }
-
+    
     // Use $_batch['form_state']['redirect'], or $_batch['redirect'],
     // or $_batch['source_page'].
     if (isset($_batch['form_state']['redirect'])) {
@@ -328,13 +325,13 @@
     else {
       $redirect = $_batch['source_page'];
     }
-
+    
     // Let drupal_redirect_form handle redirection logic.
     $form = isset($batch['form']) ? $batch['form'] : array();
     if (empty($_batch['form_state']['rebuild']) && empty($_batch['form_state']['storage'])) {
       drupal_redirect_form($form, $redirect);
     }
-
+    
     // We get here if $form['#redirect'] was FALSE, or if the form is a
     // multi-step form. We save the final $form_state value to be retrieved
     // by drupal_get_form, and we redirect to the originating page.
@@ -352,3 +349,4 @@
     db_query("UPDATE {batch} SET batch = '%s' WHERE bid = %d", serialize($batch), $batch['id']);
   }
 }
+
