### Eclipse Workspace Patch 1.0 #P test_drupal_6 Index: update.php =================================================================== RCS file: /cvs/drupal/drupal/update.php,v retrieving revision 1.216 diff -u -r1.216 update.php --- update.php 13 Apr 2007 08:56:57 -0000 1.216 +++ update.php 16 Apr 2007 14:14:17 -0000 @@ -1,5 +1,5 @@ $module)); } function update_selection_page() { @@ -322,7 +321,7 @@ drupal_set_title('Drupal database update'); // Prevent browser from using cached drupal.js or update.js - drupal_add_js('misc/update.js', 'core', 'header', FALSE, TRUE); + //drupal_add_js('misc/update.js', 'core', 'header', FALSE, TRUE); $output .= drupal_get_form('update_script_selection_form'); update_task_list('select'); @@ -377,7 +376,7 @@ return $form; } -function update_update_page() { +function update_set_batch() { // Set the installed version so updates start at the correct place. foreach ($_POST['start'] as $module => $version) { drupal_set_installed_schema_version($module, $version - 1); @@ -386,146 +385,39 @@ if ($version <= $max_version) { foreach ($updates as $update) { if ($update >= $version) { - $_SESSION['update_remaining'][] = array('module' => $module, 'version' => $update); + $operations[] = array( + 'callback' => 'update_data', + 'arguments' => array($module, $update), + ); } } } } - - // Keep track of total number of updates - if (isset($_SESSION['update_remaining'])) { - $_SESSION['update_total'] = count($_SESSION['update_remaining']); - } - - if ($_POST['has_js']) { - return update_progress_page(); - } - else { - return update_progress_page_nojs(); - } -} - -function update_progress_page() { - // Prevent browser from using cached drupal.js or update.js - drupal_add_js('misc/progress.js', 'core', 'header', FALSE, TRUE); - drupal_add_js('misc/update.js', 'core', 'header', FALSE, TRUE); - - drupal_set_title('Updating'); - update_task_list('run'); - $output = '
'; - $output .= 'Please wait while your site is being updated.
'; - return $output; -} - -/** - * Perform updates for one second or until finished. - * - * @return - * An array indicating the status after doing updates. The first element is - * the overall percentage finished. The second element is a status message. - */ -function update_do_updates() { - while (isset($_SESSION['update_remaining']) && ($update = reset($_SESSION['update_remaining']))) { - $update_finished = update_data($update['module'], $update['version']); - if ($update_finished == 1) { - // Dequeue the completed update. - unset($_SESSION['update_remaining'][key($_SESSION['update_remaining'])]); - $update_finished = 0; // Make sure this step isn't counted double - } - if (timer_read('page') > 1000) { - break; - } - } - - if ($_SESSION['update_total']) { - $percentage = floor(($_SESSION['update_total'] - count($_SESSION['update_remaining']) + $update_finished) / $_SESSION['update_total'] * 100); - } - else { - $percentage = 100; - } - - // When no updates remain, clear the caches in case the data has been updated. - if (!isset($update['module'])) { - cache_clear_all('*', 'cache', TRUE); - cache_clear_all('*', 'cache_page', TRUE); - cache_clear_all('*', 'cache_menu', TRUE); - cache_clear_all('*', 'cache_filter', TRUE); - drupal_clear_css_cache(); - } - - return array($percentage, isset($update['module']) ? 'Updating '. $update['module'] .' module' : 'Updating complete'); -} - -/** - * Perform updates for the JS version and return progress. - */ -function update_do_update_page() { - global $conf; - - // HTTP Post required - if ($_SERVER['REQUEST_METHOD'] != 'POST') { - drupal_set_message('HTTP Post is required.', 'error'); - drupal_set_title('Error'); - return ''; + if ($operations) { + global $base_url; + $batch = array( + 'title' => 'Updating', + 'init_message' => 'Starting updates', + 'error_message' => 'An unrecoverable error has occured. You can find the error message below. It is advised to copy it to the clipboard for reference.', + 'finished' => 'update_finished', + 'operations' => $operations, + ); + batch_open($batch, FALSE, $base_url .'/update.php', $base_url .'/update.php?op=results'); } - - // Error handling: if PHP dies, the output will fail to parse as JSON, and - // the Javascript will tell the user to continue to the op=error page. - list($percentage, $message) = update_do_updates(); - print drupal_to_js(array('status' => TRUE, 'percentage' => $percentage, 'message' => $message)); } -/** - * Perform updates for the non-JS version and return the status page. - */ -function update_progress_page_nojs() { - drupal_set_title('Updating'); - update_task_list('run'); - - $new_op = 'do_update_nojs'; - if ($_SERVER['REQUEST_METHOD'] == 'POST') { - // This is the first page so return some output immediately. - $percentage = 0; - $message = 'Starting updates'; - } - else { - // This is one of the later requests: do some updates 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. So, we put an explanation in the - // buffer to guide the user when an error happens. - ob_start(); - $fallback = 'An unrecoverable error has occurred. You can find the error message below. It is advised to copy it to the clipboard for reference. Please continue to the update summary.
'; - $fallback = theme('maintenance_page', $fallback, 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