From cb49e19e9ed2e90a4ece7a5479a4f6e3d342925f Mon Sep 17 00:00:00 2001 From: Gerhard Killesreiter Date: Tue, 28 Mar 2006 09:29:23 +0000 Subject: #54003, Watchdog not logging update errors, patch by Steven --- includes/common.inc | 3 ++- includes/theme.inc | 11 ++++++++--- misc/progress.js | 2 +- misc/update.js | 12 +++++++++--- update.php | 36 ++++++++++++++++++++++++++---------- 5 files changed, 46 insertions(+), 18 deletions(-) diff --git a/includes/common.inc b/includes/common.inc index 196fbab6f..e3e65528f 100644 --- a/includes/common.inc +++ b/includes/common.inc @@ -452,7 +452,8 @@ function error_handler($errno, $message, $filename, $line) { $types = array(1 => 'error', 2 => 'warning', 4 => 'parse error', 8 => 'notice', 16 => 'core error', 32 => 'core warning', 64 => 'compile error', 128 => 'compile warning', 256 => 'user error', 512 => 'user warning', 1024 => 'user notice', 2048 => 'strict warning'); $entry = $types[$errno] .': '. $message .' in '. $filename .' on line '. $line .'.'; - if (variable_get('error_level', 1) == 1) { + // Note: force display of error messages in update.php + if (variable_get('error_level', 1) == 1 || strstr($_SERVER['PHP_SELF'], 'update.php')) { drupal_set_message($entry, 'error'); } diff --git a/includes/theme.inc b/includes/theme.inc index c0e4f3b0c..ec085d946 100644 --- a/includes/theme.inc +++ b/includes/theme.inc @@ -425,10 +425,11 @@ function theme_page($content) { return $output; } -function theme_maintenance_page($content) { +function theme_maintenance_page($content, $messages = TRUE, $partial = FALSE) { drupal_set_header('Content-Type: text/html; charset=utf-8'); theme('add_style', 'misc/maintenance.css'); drupal_set_html_head(''); + $output = "\n"; $output .= ''; $output .= ''; @@ -439,13 +440,17 @@ function theme_maintenance_page($content) { $output .= ''; $output .= '

' . drupal_get_title() . '

'; - $output .= theme('status_messages'); + if ($messages) { + $output .= theme('status_messages'); + } $output .= "\n\n"; $output .= $content; $output .= "\n\n"; - $output .= ''; + if (!$partial) { + $output .= ''; + } return $output; } diff --git a/misc/progress.js b/misc/progress.js index cc029e5b5..b519f066b 100644 --- a/misc/progress.js +++ b/misc/progress.js @@ -107,7 +107,7 @@ progressBar.prototype.receivePing = function (string, xmlhttp, pb) { progressBar.prototype.displayError = function (string) { var error = document.createElement('div'); error.className = 'error'; - error.appendChild(document.createTextNode(string)); + error.innerHTML = string; this.element.style.display = 'none'; this.element.parentNode.insertBefore(error, this.element); diff --git a/misc/update.js b/misc/update.js index 1dbfdb10e..9177296a1 100644 --- a/misc/update.js +++ b/misc/update.js @@ -7,15 +7,21 @@ if (isJsEnabled()) { } if ($('progress')) { - updateCallback = function (progress, status, pb) { + // Success: redirect to the summary. + var updateCallback = function (progress, status, pb) { if (progress == 100) { pb.stopMonitoring(); window.location = window.location.href.split('op=')[0] +'op=finished'; } } - errorCallback = function (pb) { - window.location = window.location.href.split('op=')[0] +'op=error'; + // Failure: point out error message and provide link to the summary. + var errorCallback = function (pb) { + var div = document.createElement('p'); + div.className = 'error'; + div.innerHTML = 'An unrecoverable error has occured. You can find the error message below. It is advised to copy it to the clipboard for reference. Please continue to the update summary'; + $('progress').insertBefore(div, $('progress').firstChild); + $('wait').style.display = 'none'; } var progress = new progressBar('updateprogress', updateCallback, HTTPPost, errorCallback); diff --git a/update.php b/update.php index 973ed1c8d..403d4b716 100644 --- a/update.php +++ b/update.php @@ -383,12 +383,13 @@ function update_update_page() { } function update_progress_page() { - drupal_add_js('misc/progress.js'); - drupal_add_js('misc/update.js'); + // Prevent browser from using cached drupal.js or update.js + drupal_add_js('misc/progress.js', TRUE); + drupal_add_js('misc/update.js', TRUE); drupal_set_title('Updating'); $output = '
'; - $output .= '

Please wait while your site is being updated.

'; + $output .= '

Please wait while your site is being updated.

'; return $output; } @@ -434,6 +435,8 @@ function update_do_update_page() { return ''; } + // 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)); } @@ -442,11 +445,15 @@ function update_do_update_page() { * Perform updates for the non-JS version and return the status page. */ function update_progress_page_nojs() { + drupal_set_title('Updating'); + $new_op = 'do_update_nojs'; if ($_SERVER['REQUEST_METHOD'] == 'GET') { - // Store a fallback redirect in case of a fatal PHP error + // Error handling: if PHP dies, it will output whatever is in the output + // buffer, followed by the error message. ob_start(); - print ''; + $fallback = '

An unrecoverable error has occured. You can find the error message below. It is advised to copy it to the clipboard for reference. Please continue to the update summary.

'; + print theme('maintenance_page', $fallback, FALSE, TRUE); list($percentage, $message) = update_do_updates(); if ($percentage == 100) { @@ -463,11 +470,12 @@ function update_progress_page_nojs() { } drupal_set_html_head(''); - drupal_set_title('Updating'); $output = theme('progress_bar', $percentage, $message); $output .= '

Updating your site will take a few seconds.

'; - return $output; + // Note: do not output drupal_set_message()s until the summary page. + print theme('maintenance_page', $output, FALSE); + return NULL; } function update_finished_page($success) { @@ -476,15 +484,17 @@ function update_finished_page($success) { $links[] = 'main page'; $links[] = 'administration pages'; + // Report end result if ($success) { $output = '

Updates were attempted. If you see no failures below, you may proceed happily to the administration pages. Otherwise, you may need to update your database manually. All errors have been logged.

'; } else { - $output = '

The update process did not complete. All errors have been logged. You may need to check the watchdog table manually.'; + $update = reset($_SESSION['update_remaining']); + $output = '

The update process was aborted prematurely while running update #'. $update['version'] .' in '. $update['module'] .'.module. All other errors have been logged. You may need to check the watchdog database table manually.

'; } if ($GLOBALS['access_check'] == FALSE) { - $output .= "

Reminder: don't forget to set the \$access_check value at the top of update.php back to TRUE."; + $output .= "

Reminder: don't forget to set the \$access_check value at the top of update.php back to TRUE.

"; } $output .= theme('item_list', $links); @@ -638,17 +648,23 @@ function update_convert_table_utf8($table) { } // Some unavoidable errors happen because the database is not yet up-to-date. -// We suppress them to avoid confusion. All errors are still logged. +// Our custom error handler is not yet installed, so we just surpress them. ini_set('display_errors', FALSE); include_once './includes/bootstrap.inc'; update_fix_system_table(); update_fix_access_table(); + drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL); drupal_maintenance_theme(); +// Turn error reporting back on. From now on, only fatal errors (which are +// not passed through the error handler) will cause a message to be printed. +ini_set('display_errors', TRUE); + // Access check: if (($access_check == FALSE) || ($user->uid == 1)) { + include_once './includes/install.inc'; update_fix_schema_version(); -- cgit v1.2.3