From b362985de5cf8a5485dfe67ccb56f249b64130b8 Mon Sep 17 00:00:00 2001
From: Dries Buytaert <dries@buytaert.net>
Date: Mon, 26 Dec 2005 17:20:23 +0000
Subject: [PATCH] - Patch #41118 by Goba: various upgrade script fixes.

---
 database/updates.inc | 17 ++++++-----------
 includes/theme.inc   |  1 +
 update.php           | 34 +++++++++++++++++++++++++++++-----
 3 files changed, 36 insertions(+), 16 deletions(-)

diff --git a/database/updates.inc b/database/updates.inc
index 622413cbab23..f977fdbde3b6 100644
--- a/database/updates.inc
+++ b/database/updates.inc
@@ -208,15 +208,10 @@ function system_update_114() {
 
 function system_update_115() {
   $ret = array();
-  if ($GLOBALS['db_type'] == 'mysql') {
-    $ret[] = update_sql("ALTER TABLE {watchdog} ADD severity tinyint(3) unsigned NOT NULL default '0'");
-  }
-  else if ($GLOBALS['db_type'] == 'pgsql') {
-    $ret[] = update_sql('ALTER TABLE {watchdog} ADD severity smallint');
-    $ret[] = update_sql('UPDATE {watchdog} SET severity = 0');
-    $ret[] = update_sql('ALTER TABLE {watchdog} ALTER COLUMN severity SET NOT NULL');
-    $ret[] = update_sql('ALTER TABLE {watchdog} ALTER COLUMN severity SET DEFAULT 0');
-  }
+
+  // This update has been moved to update_fix_watchdog_115 in update.php because it
+  // is needed for the basic functioning of the update script.
+
   return $ret;
 }
 
@@ -387,7 +382,7 @@ function system_update_124() {
   $result = db_query("SELECT c.nid, c.timestamp, c.name, c.uid, COUNT(c.nid) as comment_count FROM {node} n LEFT JOIN {comments} c ON c.nid = n.nid WHERE c.status = 0 GROUP BY c.nid, c.timestamp, c.name, c.uid");
   while ($comment_record = db_fetch_object($result)) {
     $count = db_result(db_query('SELECT COUNT(cid) FROM {comments} WHERE nid = %d AND status = 0', $comment_record->nid));
-    $ret[] = db_query("UPDATE {node_comment_statistics} SET comment_count = %d, last_comment_timestamp = %d, last_comment_name = '%s', last_comment_uid = %d WHERE nid = %d", $count, $comment_record->timestamp, $comment_record->name, $comment_record->uid, $comment_record->nid);
+    db_query("UPDATE {node_comment_statistics} SET comment_count = %d, last_comment_timestamp = %d, last_comment_name = '%s', last_comment_uid = %d WHERE nid = %d", $count, $comment_record->timestamp, $comment_record->name, $comment_record->uid, $comment_record->nid);
   }
 
   return $ret;
@@ -1128,7 +1123,7 @@ function system_update_159() {
   $vid = db_next_id('{node_revisions}_vid');
   while ($node = db_fetch_object($result)) {
     $revisions = unserialize($node->revisions);
-    if (!$revisions && is_array($revisions) && count($revisions) > 0) {
+    if (isset($revisions) && is_array($revisions) && count($revisions) > 0) {
       $revisions_query = array();
       $revisions_args = array();
       $book_query = array();
diff --git a/includes/theme.inc b/includes/theme.inc
index 279015b7118d..9e150e8345aa 100644
--- a/includes/theme.inc
+++ b/includes/theme.inc
@@ -409,6 +409,7 @@ function theme_page($content) {
 function theme_maintenance_page($content) {
   drupal_set_header('Content-Type: text/html; charset=utf-8');
   theme('add_style', 'misc/maintenance.css');
+  drupal_set_html_head('<link rel="shortcut icon" href="misc/favicon.ico" type="image/x-icon" />');
   $output = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n";
   $output .= '<html xmlns="http://www.w3.org/1999/xhtml">';
   $output .= '<head>';
diff --git a/update.php b/update.php
index c29fbdb09603..3ddce89ff8d1 100644
--- a/update.php
+++ b/update.php
@@ -214,6 +214,29 @@ function update_fix_sessions() {
   }
 }
 
+/**
+ * System update 115 changes the watchdog table, which breaks the update
+ * script's ability to use logging. This changes the table appropriately.
+ *
+ * This code, including the 'update_watchdog_115_fixed' variable,  may be removed
+ * when update 115 is removed. It is part of the Drupal 4.5 to 4.7 migration.
+ */
+function update_fix_watchdog_115() {
+  if (drupal_get_installed_schema_version('system') < 115 && !variable_get('update_watchdog_115_fixed', FALSE)) {
+    if ($GLOBALS['db_type'] == 'mysql') {
+      $ret[] = update_sql("ALTER TABLE {watchdog} ADD severity tinyint(3) unsigned NOT NULL default '0'");
+    }
+    else if ($GLOBALS['db_type'] == 'pgsql') {
+      $ret[] = update_sql('ALTER TABLE {watchdog} ADD severity smallint');
+      $ret[] = update_sql('UPDATE {watchdog} SET severity = 0');
+      $ret[] = update_sql('ALTER TABLE {watchdog} ALTER COLUMN severity SET NOT NULL');
+      $ret[] = update_sql('ALTER TABLE {watchdog} ALTER COLUMN severity SET DEFAULT 0');
+    }
+
+    variable_set('update_watchdog_115_fixed', TRUE);
+  }
+}
+
 /**
  * System update 142 changes the watchdog table, which breaks the update
  * script's ability to use logging. This changes the table appropriately.
@@ -280,8 +303,8 @@ function update_data($module, $number) {
 }
 
 function update_selection_page() {
-  $output = '<p>'. t('The version of Drupal you are updating from has been automatically detected. You can select a different version, but you should not need to.') .'</p>';
-  $output .= '<p>'. t('Click Update to start the update process.') .'</p>';
+  $output = '<p>The version of Drupal you are updating from has been automatically detected. You can select a different version, but you should not need to.</p>';
+  $output .= '<p>Click Update to start the update process.</p>';
 
   $form = array();
   $form['start'] = array(
@@ -299,7 +322,7 @@ function update_selection_page() {
 
       $form['start'][$module] = array(
         '#type' => 'select',
-        '#title' => t('%name module', array('%name' => $module)),
+        '#title' => $module . ' module',
         '#default_value' => array_search(drupal_get_installed_schema_version($module), $updates) + 1,
         '#options' => $updates,
       );
@@ -313,7 +336,7 @@ function update_selection_page() {
   );
   $form['submit'] = array(
     '#type' => 'submit',
-    '#value' => t('Update')
+    '#value' => 'Update'
   );
 
   drupal_set_title('Drupal database update');
@@ -496,8 +519,9 @@ function update_access_denied_page() {
   include_once './includes/install.inc';
 
   update_fix_schema_version();
-  update_fix_sessions();
+  update_fix_watchdog_115();
   update_fix_watchdog();
+  update_fix_sessions();
 
   $op = isset($_REQUEST['op']) ? $_REQUEST['op'] : '';
   switch ($op) {
-- 
GitLab