From a283a3b7b88cc8b5ebcb148612fc358bcc098874 Mon Sep 17 00:00:00 2001
From: Dries Buytaert <dries@buytaert.net>
Date: Wed, 25 Feb 2004 22:20:09 +0000
Subject: [PATCH] - Patch by Gerhard: move the updates to database/updates.inc
 so packaging   systems can by-pass update.php.

---
 database/updates.inc                      | 774 ++++++++++++++++++++++
 modules/poll.module                       |   8 +-
 modules/poll/poll.module                  |   8 +-
 themes/xtemplate/pushbutton/xtemplate.css |  50 +-
 update.php                                | 696 +------------------
 5 files changed, 818 insertions(+), 718 deletions(-)
 create mode 100644 database/updates.inc

diff --git a/database/updates.inc b/database/updates.inc
new file mode 100644
index 000000000000..fe9389eece4f
--- /dev/null
+++ b/database/updates.inc
@@ -0,0 +1,774 @@
+<?php
+/* $Id$ */
+
+// Define the various updates in an array("date : comment" => "function");
+$sql_updates = array(
+  "2002-06-22: first update since Drupal 4.0.0 release" => "update_32",
+  "2002-07-07" => "update_33",
+  "2002-07-31" => "update_34",
+  "2002-08-10" => "update_35",
+  "2002-08-16" => "update_36",
+  "2002-08-19" => "update_37",
+  "2002-08-26" => "update_38",
+  "2002-09-15" => "update_39",
+  "2002-09-17" => "update_40",
+  "2002-10-13" => "update_41",
+  "2002-10-17" => "update_42",
+  "2002-10-26" => "update_43",
+  "2002-11-08" => "update_44",
+  "2002-11-20" => "update_45",
+  "2002-12-10: first update since Drupal 4.1.0 release" => "update_46",
+  "2002-12-29" => "update_47",
+  "2003-01-03" => "update_48",
+  "2003-01-05" => "update_49",
+  "2003-01-15" => "update_50",
+  "2003-04-19" => "update_51",
+  "2003-04-20" => "update_52",
+  "2003-05-18" => "update_53",
+  "2003-05-24" => "update_54",
+  "2003-05-31" => "update_55",
+  "2003-06-04" => "update_56",
+  "2003-06-08" => "update_57",
+  "2003-06-08: first update since Drupal 4.2.0 release" => "update_58",
+  "2003-08-05" => "update_59",
+  "2003-08-15" => "update_60",
+  "2003-08-20" => "update_61",
+  "2003-08-27" => "update_62",
+  "2003-09-09" => "update_63",
+  "2003-09-10" => "update_64",
+  "2003-09-29" => "update_65",
+  "2003-09-30" => "update_66",
+  "2003-10-11" => "update_67",
+  "2003-10-20" => "update_68",
+  "2003-10-22" => "update_69",
+  "2003-10-27" => "update_70",
+  "2003-11-17: first update since Drupal 4.3.0 release" => "update_71",
+  "2003-11-27" => "update_72",
+  "2003-12-03" => "update_73",
+  "2003-12-06" => "update_74",
+  "2004-01-06" => "update_75",
+  "2004-01-11" => "update_76",
+  "2004-01-13" => "update_77",
+  "2004-02-03" => "update_78",
+  "2004-02-21" => "update_79"
+);
+
+function update_32() {
+  $ret = array();
+  $ret[] = update_sql("ALTER TABLE users ADD index (sid(4))");
+  $ret[] = update_sql("ALTER TABLE users ADD index (timestamp)");
+  $ret[] = update_sql("ALTER TABLE users ADD UNIQUE KEY name (name)");
+  return $ret;
+}
+
+function update_33() {
+  $ret = array();
+  $result = db_query("SELECT * FROM variable WHERE value NOT LIKE 's:%;'");
+  // NOTE: the "WHERE"-part of the query above avoids variables to get serialized twice.
+  while ($variable = db_fetch_object($result)) {
+    variable_set($variable->name, $variable->value);
+  }
+  return $ret;
+}
+
+function update_34() {
+  $ret = array();
+  $ret[] = update_sql("ALTER TABLE feed MODIFY refresh int(10) NOT NULL default '0'");
+  $ret[] = update_sql("ALTER TABLE feed MODIFY timestamp int (10) NOT NULL default '0'");
+  $ret[] = update_sql("ALTER TABLE users CHANGE session session TEXT");
+  return $ret;
+}
+
+function update_35() {
+  $ret = array();
+  $ret[] = update_sql("ALTER TABLE poll_choices ADD INDEX (nid)");
+  return $ret;
+}
+
+function update_36() {
+  $ret = array();
+  $ret[] = update_sql("ALTER TABLE rating CHANGE old previous int(6) NOT NULL default '0'");
+  $ret[] = update_sql("ALTER TABLE rating CHANGE new current int(6) NOT NULL default '0'");
+  return $ret;
+}
+
+function update_37() {
+  $ret = array();
+
+  $ret[] = update_sql("DROP TABLE IF EXISTS sequences");
+
+  $ret[] = update_sql("CREATE TABLE sequences (
+    name VARCHAR(255) NOT NULL PRIMARY KEY,
+    id INT UNSIGNED NOT NULL
+  ) TYPE=MyISAM");
+
+  if ($max = db_result(db_query("SELECT MAX(nid) FROM node"))) {
+    $ret[] = update_sql("REPLACE INTO sequences VALUES ('node', $max)");
+  }
+
+  if ($max = db_result(db_query("SELECT MAX(cid) FROM comments"))) {
+    $ret[] = update_sql("REPLACE INTO sequences VALUES ('comments', $max)");
+  }
+  // NOTE: move the comments bit down as soon as we switched to use the new comment module!
+
+  if ($max = db_result(db_query("SELECT MAX(tid) FROM term_data"))) {
+    $ret[] = update_sql("REPLACE INTO sequences VALUES ('term_data', $max)");
+  }
+  return $ret;
+}
+
+function update_38() {
+  $ret = array();
+  $ret[] = update_sql("ALTER TABLE watchdog CHANGE message message text NOT NULL default ''");
+  return $ret;
+}
+
+function update_39() {
+  $ret = array();
+  $ret[] = update_sql("DROP TABLE moderate");
+
+  $ret[] = update_sql("ALTER TABLE comments ADD score MEDIUMINT NOT NULL");
+  $ret[] = update_sql("ALTER TABLE comments ADD status TINYINT UNSIGNED NOT NULL");
+  $ret[] = update_sql("ALTER TABLE comments ADD users MEDIUMTEXT");
+
+  $ret[] = update_sql("CREATE TABLE moderation_votes (
+    mid INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
+    vote VARCHAR(255),
+    weight TINYINT NOT NULL
+  )");
+
+  $ret[] = update_sql("CREATE TABLE moderation_roles (
+    rid INT UNSIGNED NOT NULL,
+    mid INT UNSIGNED NOT NULL,
+    value TINYINT NOT NULL
+  )");
+
+  $ret[] = update_sql("ALTER TABLE moderation_roles ADD INDEX (rid)");
+  $ret[] = update_sql("ALTER TABLE moderation_roles ADD INDEX (mid)");
+
+  $ret[] = update_sql("CREATE TABLE moderation_filters (
+    fid INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
+    filter VARCHAR(255) NOT NULL,
+    minimum SMALLINT NOT NULL
+  )");
+
+  $ret[] = update_sql("DELETE FROM moderation_votes");
+  $ret[] = update_sql("INSERT INTO moderation_votes VALUES (1, '+1', 0)");
+  $ret[] = update_sql("INSERT INTO moderation_votes VALUES (2, '-1', 1)");
+
+  $ret[] = update_sql("DELETE FROM moderation_roles");
+  $ret[] = update_sql("INSERT INTO moderation_roles VALUES (2, 1, 1)");
+  $ret[] = update_sql("INSERT INTO moderation_roles VALUES (2, 2, -1)");
+
+  $ret[] = update_sql("CREATE TABLE forum (
+    nid int unsigned not null primary key,
+    icon varchar(255) not null,
+    shadow int unsigned not null
+  )");
+  return $ret;
+}
+
+function update_40() {
+  $ret = array();
+  if ($max = db_result(db_query("SELECT MAX(cid) FROM comments"))) {
+    $ret[] = update_sql("REPLACE INTO sequences VALUES ('comments', $max)");
+  }
+  return $ret;
+}
+
+function update_41() {
+  $ret = array();
+  $ret[] = update_sql("CREATE TABLE statistics (
+    nid int(11) NOT NULL,
+    totalcount bigint UNSIGNED DEFAULT '0' NOT NULL,
+    daycount mediumint UNSIGNED DEFAULT '0' NOT NULL,
+    timestamp int(11) UNSIGNED DEFAULT '0' NOT NULL,
+    PRIMARY KEY (nid),
+    INDEX (totalcount),
+    INDEX (daycount),
+    INDEX (timestamp)
+  )");
+
+  $ret[] = update_sql("CREATE TABLE accesslog (
+    nid int(11) UNSIGNED DEFAULT '0',
+    url varchar(255),
+    hostname varchar(128),
+    uid int(10) UNSIGNED DEFAULT '0',
+    timestamp int(11) UNSIGNED NOT NULL
+  )");
+  return $ret;
+}
+
+function update_42() {
+  $ret = array();
+  $ret[] = update_sql("DROP TABLE modules");
+  $ret[] = update_sql("DROP TABLE layout");
+  $ret[] = update_sql("DROP TABLE referrer");
+  return $ret;
+}
+
+function update_43() {
+  $ret = array();
+  $ret[] = update_sql("ALTER TABLE blocks DROP remove");
+  $ret[] = update_sql("ALTER TABLE blocks DROP name");
+  $ret[] = update_sql("UPDATE boxes SET type = 0 WHERE type = 1");
+  $ret[] = update_sql("UPDATE boxes SET type = 1 WHERE type = 2");
+  return $ret;
+}
+
+function update_44() {
+  $ret = array();
+  $ret[] = update_sql("UPDATE system SET filename = CONCAT('modules/', filename) WHERE type = 'module'");
+  return $ret;
+}
+
+function update_45() {
+  $ret = array();
+  $ret[] = update_sql("ALTER TABLE page ADD description varchar(128) NOT NULL default ''");
+  return $ret;
+}
+
+function update_46() {
+  $ret = array();
+  if ($GLOBALS["db_type"] == "pgsql") {
+    $ret[] = update_sql("ALTER TABLE cache ADD created integer");
+  }
+  else {
+    $ret[] = update_sql("ALTER TABLE cache ADD created int(11) NOT NULL default '0'");
+  }
+  return $ret;
+}
+
+function update_47() {
+  $ret = array();
+  if ($max = db_result(db_query("SELECT MAX(vid) FROM vocabulary"))) {
+    $ret[] = update_sql("REPLACE INTO sequences VALUES ('vocabulary', $max)");
+  }
+  return $ret;
+}
+
+function update_48() {
+  $ret = array();
+  $ret[] = update_sql("ALTER TABLE watchdog ADD link varchar(255) DEFAULT '' NULL");
+  return $ret;
+}
+
+function update_49() {
+  $ret = array();
+  /*
+  ** Make sure the admin module is added to the system table or the
+  ** admin menus won't show up.
+  */
+
+  $ret[] = update_sql("DELETE FROM system WHERE name = 'admin';");
+  $ret[] = update_sql("INSERT INTO system VALUES ('modules/admin.module','admin','module','',1)");
+  return $ret;
+}
+
+function update_50() {
+  $ret = array();
+  $ret[] = update_sql("ALTER TABLE forum ADD tid INT UNSIGNED NOT NULL");
+  $result = db_queryd("SELECT n.nid, t.tid FROM node n, term_node t WHERE n.nid = t.nid AND type = 'forum'");
+  while ($node = db_fetch_object($result)) {
+    db_queryd("UPDATE forum SET tid = %d WHERE nid = %d", $node->tid, $node->nid);
+  }
+  $ret[] = update_sql("ALTER TABLE forum ADD INDEX (tid)");
+  return $ret;
+}
+
+function update_51() {
+  $ret = array();
+  $ret[] = update_sql("ALTER TABLE blocks CHANGE delta delta varchar(32) NOT NULL default '0'");
+  return $ret;
+}
+
+function update_52() {
+  $ret = array();
+  $ret[] = update_sql("UPDATE sequences SET name = 'comments_cid' WHERE name = 'comments';");
+  $ret[] = update_sql("UPDATE sequences SET name = 'node_nid' WHERE name = 'node';");
+
+  $ret[] = update_sql("DELETE FROM sequences WHERE name = 'import'");
+  $ret[] = update_sql("DELETE FROM sequences WHERE name = 'bundle_bid'");  // in case we would run this entry twice
+  $ret[] = update_sql("DELETE FROM sequences WHERE name = 'feed_fid'");    // in case we would run this entry twice
+
+  $bundles = db_result(db_query("SELECT MAX(bid) FROM bundle;"));
+  $ret[] = update_sql("INSERT INTO sequences (name, id) VALUES ('bundle_bid', '$bundles')");
+
+  $feeds = db_result(db_query("SELECT MAX(fid) FROM feed;"));
+  $ret[] = update_sql("INSERT INTO sequences (name, id) VALUES ('feed_fid', '$feeds')");
+
+  $ret[] = update_sql("UPDATE sequences SET name = 'vocabulary_vid' WHERE name = 'vocabulary';");
+
+  $ret[] = update_sql("UPDATE sequences SET name = 'term_data_tid' WHERE name = 'term_data'");
+  return $ret;
+}
+
+function update_53() {
+  $ret = array();
+  $ret[] = update_sql("CREATE INDEX book_parent ON book(parent);");
+  return $ret;
+}
+
+function update_54() {
+  $ret = array();
+  $ret[] = update_sql("ALTER TABLE locales CHANGE string string BLOB DEFAULT '' NOT NULL");
+  return $ret;
+}
+
+function update_55() {
+  $ret = array();
+  $ret[] = update_sql("ALTER TABLE site ADD checked INT(11) NOT NULL;");
+  $ret[] = update_sql("ALTER TABLE site CHANGE timestamp changed INT(11) NOT NULL;");
+  return $ret;
+}
+
+function update_56() {
+  $ret = array();
+  $ret[] = update_sql("ALTER TABLE vocabulary CHANGE types nodes TEXT DEFAULT '' NOT NULL");
+  return $ret;
+}
+
+function update_57() {
+  $ret = array();
+  $ret[] = update_sql("DELETE FROM variable WHERE name = 'site_charset'");
+  return $ret;
+}
+
+function update_58() {
+  $ret = array();
+  if ($GLOBALS["db_type"] == "pgsql") {
+    $ret[] = update_sql("ALTER TABLE {node} ADD path varchar(250) NULL");
+    $ret[] = update_sql("ALTER TABLE {node} ALTER COLUMN path SET DEFAULT ''");
+  }
+  else {
+    $ret[] = update_sql("ALTER TABLE {node} ADD path varchar(250) NULL default ''");
+  }
+  return $ret;
+}
+
+function update_59() {
+  $ret = array();
+  if ($GLOBALS["db_type"] == "pgsql") {
+    $ret[] = update_sql("ALTER TABLE {comments} ADD thread VARCHAR(255)");
+    $ret[] = update_sql("ALTER TABLE {comments} ALTER COLUMN thread SET NOT NULL");
+  }
+  else {
+    $ret[] = update_sql("ALTER TABLE {comments} ADD thread VARCHAR(255) NOT NULL");
+  }
+
+  $result = db_query("SELECT DISTINCT(nid) FROM {comments} WHERE thread = ''");
+
+  while ($node = db_fetch_object($result)) {
+    $result2 = db_query("SELECT cid, pid FROM {comments} where nid = '%d' ORDER BY timestamp", $node->nid);
+    $comments = array();
+    while ($comment = db_fetch_object($result2)) {
+      $comments[$comment->cid] = $comment;
+    }
+
+    $structure = array();
+    $structure = _update_thread_structure($comments, 0, -1, $structure);
+
+    foreach ($structure as $cid => $thread) {
+      $new_parts = array();
+      foreach(explode(".", $thread) as $part) {
+        if ($part > 9) {
+          $start = substr($part, 0, strlen($part) - 1);
+          $end = substr($part, -1, 1);
+
+          $new_parts[] = str_repeat("9", $start).$end;
+        }
+        else {
+          $new_parts[] = $part;
+        }
+      }
+      $thread = implode(".", $new_parts);
+
+      db_query("UPDATE {comments} SET thread = '%s' WHERE cid = '%d'", $thread."/", $comments[$cid]->cid);
+    }
+  }
+  return $ret;
+}
+
+function _update_thread_structure($comments, $pid, $depth, $structure) {
+  $ret = array();
+  $depth++;
+
+  foreach ($comments as $key => $comment) {
+    if ($comment->pid == $pid) {
+      if ($structure[$comment->pid]) {
+        $structure[$comment->cid] = $structure[$comment->pid]."."._update_next_thread($structure, $structure[$comment->pid]);
+      }
+      else {
+        $structure[$comment->cid] = _update_next_thread($structure, "");
+      }
+
+      $structure = _update_thread_structure($comments, $comment->cid, $depth, $structure);
+    }
+  }
+
+  return $structure;
+  return $ret;
+}
+
+function update_60() {
+  $ret = array();
+  $ret[] = update_sql("ALTER TABLE {forum} DROP icon");
+  return $ret;
+}
+
+function update_61() {
+  $ret = array();
+  if ($GLOBALS["db_type"] == "pgsql") {
+    $ret[] = update_sql("CREATE TABLE {sessions} (
+      uid integer NOT NULL,
+      sid varchar(32) NOT NULL default '',
+      hostname varchar(128) NOT NULL default '',
+      timestamp integer NOT NULL default '0',
+      session text,
+      PRIMARY KEY (sid)
+     );");
+
+    $ret[] = update_sql("ALTER TABLE {users} DROP session;");
+    $ret[] = update_sql("ALTER TABLE {users} DROP hostname;");
+    $ret[] = update_sql("ALTER TABLE {users} DROP sid;");
+
+  }
+  else {
+    $ret[] = update_sql("CREATE TABLE IF NOT EXISTS {sessions} (
+      uid int(10) unsigned NOT NULL,
+      sid varchar(32) NOT NULL default '',
+      hostname varchar(128) NOT NULL default '',
+      timestamp int(11) NOT NULL default '0',
+      session text,
+      KEY uid (uid),
+      KEY sid (sid(4)),
+      KEY timestamp (timestamp)
+    )");
+
+    $ret[] = update_sql("ALTER TABLE {users} DROP session;");
+    $ret[] = update_sql("ALTER TABLE {users} DROP hostname;");
+    $ret[] = update_sql("ALTER TABLE {users} DROP sid;");
+  }
+  return $ret;
+}
+
+function update_62() {
+  $ret = array();
+  if ($GLOBALS["db_type"] == "pgsql") {
+    $ret[] = update_sql("CREATE INDEX accesslog_timestamp ON {accesslog} (timestamp)");
+
+    $ret[] = update_sql("DROP INDEX node_type_idx");
+    $ret[] = update_sql("DROP INDEX node_title_idx");
+    $ret[] = update_sql("DROP INDEX node_promote_idx");
+
+    $ret[] = update_sql("CREATE INDEX node_type ON {node} (type)");
+    $ret[] = update_sql("CREATE INDEX node_title_type ON {node} (title,type)");
+    $ret[] = update_sql("CREATE INDEX node_moderate ON {node} (moderate)");
+    $ret[] = update_sql("CREATE INDEX node_path ON {node} (path)");
+    $ret[] = update_sql("CREATE INDEX node_promote_status ON {node} (promote, status)");
+
+  }
+  else {
+    $ret[] = update_sql("ALTER TABLE {accesslog} ADD INDEX accesslog_timestamp (timestamp)");
+
+    $ret[] = update_sql("ALTER TABLE {node} DROP INDEX type");
+    $ret[] = update_sql("ALTER TABLE {node} DROP INDEX title");
+    $ret[] = update_sql("ALTER TABLE {node} DROP INDEX promote");
+
+    $ret[] = update_sql("ALTER TABLE {node} ADD INDEX node_type (type(4))");
+    $ret[] = update_sql("ALTER TABLE {node} ADD INDEX node_title_type (title,type(4))");
+    $ret[] = update_sql("ALTER TABLE {node} ADD INDEX node_moderate (moderate)");
+    $ret[] = update_sql("ALTER TABLE {node} ADD INDEX node_path (path(5))");
+    $ret[] = update_sql("ALTER TABLE {node} ADD INDEX node_promote_status (promote, status)");
+  }
+  return $ret;
+}
+
+function _update_next_thread($structure, $parent) {
+  $ret = array();
+  do {
+    $val++;
+    if ($parent) {
+      $thread = "$parent.$val";
+    }
+    else {
+      $thread = $val;
+    }
+
+  } while (array_search($thread, $structure));
+
+  return $val;
+  return $ret;
+}
+
+function update_63() {
+  $ret = array();
+  if ($GLOBALS["db_type"] == "pgsql") {
+    $ret[] = update_sql("INSERT INTO {users} (uid, name, mail, timestamp) VALUES ('0', '', '', '". time() ."')");
+  }
+  else {
+    $ret[] = update_sql("ALTER TABLE {users} CHANGE uid uid int(10) unsigned NOT NULL default '0'");
+    $ret[] = update_sql("INSERT INTO {users} (uid, name, mail, timestamp) VALUES ('0', '', '', '". time() ."')");
+    $users = db_result(db_query("SELECT MAX(uid) FROM {users};"));
+    $ret[] = update_sql("INSERT INTO {sequences} (name, id) VALUES ('users_uid', '$users')");
+  }
+  return $ret;
+}
+
+function update_64() {
+  $ret = array();
+  $ret[] = update_sql("UPDATE {users} SET rid = 1 WHERE uid = 0");
+  return $ret;
+}
+
+function update_65() {
+  $ret = array();
+  // PostgreSQL-only update.
+  if ($GLOBALS["db_type"] == "pgsql") {
+    $ret[] = update_sql("CREATE FUNCTION \"rand\"() RETURNS float AS '
+      BEGIN
+        RETURN random();
+      END;' LANGUAGE 'plpgsql'");
+  }
+  return $ret;
+}
+
+function update_66() {
+  $ret = array();
+  if ($GLOBALS["db_type"] == "pgsql") {
+    $ret[] = update_sql("CREATE TABLE {path} (
+      pid serial,
+      src varchar(128) NOT NULL default '',
+      dst varchar(128) NOT NULL default '',
+      PRIMARY KEY  (pid)
+    )");
+    $ret[] = update_sql("CREATE INDEX path_src_idx ON {path}(src)");
+    $ret[] = update_sql("CREATE INDEX path_dst_idx ON {path}(dst)");
+    $result = db_query("SELECT nid, path FROM {node} WHERE path != ''");
+    while ($node = db_fetch_object($result)) {
+      $ret[] = update_sql("INSERT INTO {path} (src, dst) VALUES ('node/view/$node->nid', '". check_query($node->path) ."')");
+    }
+  }
+  else {
+    $ret[] = update_sql("CREATE TABLE {path} (
+      pid int(10) unsigned NOT NULL auto_increment,
+      src varchar(128) NOT NULL default '',
+      dst varchar(128) NOT NULL default '',
+      PRIMARY KEY  (pid),
+      UNIQUE KEY src (src),
+      UNIQUE KEY dst (dst)
+    )");
+    // Migrate the existing paths:
+    $result = db_query("SELECT nid, path FROM {node} WHERE path != ''");
+    while ($node = db_fetch_object($result)) {
+      $ret[] = update_sql("INSERT INTO {path} (src, dst) VALUES ('node/view/$node->nid', '". check_query($node->path) ."')");
+    }
+
+    $ret[] = update_sql("ALTER TABLE {node} DROP path");
+  }
+  return $ret;
+}
+
+function update_67() {
+  $ret = array();
+  if ($GLOBALS["db_type"] == "pgsql") {
+    // Taking no action.  PostgreSQL is not always capable of dropping columns.
+  }
+  else {
+    $ret[] = update_sql("ALTER TABLE {users} DROP homepage");
+  }
+  return $ret;
+}
+
+function update_68() {
+  $ret = array();
+  if ($GLOBALS["db_type"] == "pgsql") {
+    // Unneccesary. The PostgreSQL port was already using a sequence.
+  }
+  else {
+    $max = db_result(db_query("SELECT MAX(aid) FROM {access};"));
+    $ret[] = update_sql("INSERT INTO {sequences} (name, id) VALUES ('access_aid', '$max')");
+    $ret[] = update_sql("ALTER TABLE {access} CHANGE aid aid tinyint(10) NOT NULL ");
+  }
+  return $ret;
+}
+
+function update_69() {
+  $ret = array();
+  if ($GLOBALS["db_type"] == "pgsql") {
+    /* Rename the statistics table to node_counter */
+    $ret[] = update_sql("ALTER TABLE {statistics} RENAME TO {node_counter}");
+    $ret[] = update_sql("DROP INDEX  {statistics}_totalcount_idx");
+    $ret[] = update_sql("DROP INDEX  {statistics}_daycount_idx");
+    $ret[] = update_sql("DROP INDEX  {statistics}_timestamp_idx");
+    $ret[] = update_sql("CREATE INDEX {node_counter}_totalcount_idx ON {node_counter}(totalcount)");
+    $ret[] = update_sql("CREATE INDEX {node_counter}_daycount_idx ON {node_counter}(daycount)");
+    $ret[] = update_sql("CREATE INDEX {node_counter}_timestamp_idx ON {node_counter}(timestamp)");
+
+    /* Rename the path table to url_alias */
+    $ret[] = update_sql("ALTER TABLE {path} RENAME TO {url_alias}");
+    $ret[] = update_sql("ALTER TABLE {path}_pid_seq RENAME TO {url_alias}_pid_seq");
+  }
+  else {
+    $ret[] = update_sql("ALTER TABLE {statistics} RENAME TO {node_counter}");
+    $ret[] = update_sql("ALTER TABLE {path} RENAME TO {url_alias}");
+    $ret[] = update_sql("UPDATE {sequences} SET name = '{url_alias}_pid' WHERE name = '{path}_pid'");
+  }
+
+  $ret[] = update_sql("UPDATE {users} SET name = '' WHERE uid = 0;");
+  return $ret;
+}
+
+function update_70() {
+  $ret = array();
+  $ret[] = update_sql("ALTER TABLE {variable} CHANGE name name varchar(48) NOT NULL");
+  return $ret;
+}
+
+function update_71() {
+  $ret = array();
+  if ($GLOBALS["db_type"] == "pgsql") {
+    $ret[] = update_sql("ALTER TABLE {system} ADD bootstrap integer");
+  }
+  else {
+    $ret[] = update_sql("ALTER TABLE {system} ADD bootstrap int(2)");
+  }
+  return $ret;
+}
+
+function update_72() {
+  $ret = array();
+  if ($GLOBALS["db_type"] == "pgsql") {
+    $ret[] = update_sql("ALTER TABLE {blocks} ADD throttle smallint");
+    $ret[] = update_sql("ALTER TABLE {blocks} ALTER COLUMN throttle SET DEFAULT '0'");
+    $ret[] = update_sql("UPDATE {blocks} SET throttle = 0");
+    $ret[] = update_sql("ALTER TABLE {blocks} ALTER COLUMN throttle SET NOT NULL");
+  }
+  else {
+    $ret[] = update_sql("ALTER TABLE {blocks} ADD throttle tinyint(1) NOT NULL DEFAULT '0'");
+  }
+  return $ret;
+}
+
+function update_73() {
+  $ret = array();
+  /* MySQL only update */
+  if ($GLOBALS["db_type"] == "mysql") {
+    $ret[] = update_sql("ALTER TABLE {book} CHANGE log log longtext");
+    $ret[] = update_sql("ALTER TABLE {boxes} CHANGE body body longtext");
+    $ret[] = update_sql("ALTER TABLE {cache} CHANGE data data longtext");
+    $ret[] = update_sql("ALTER TABLE {comments} CHANGE comment comment longtext");
+    $ret[] = update_sql("ALTER TABLE {comments} CHANGE users users longtext");
+    $ret[] = update_sql("ALTER TABLE {directory} CHANGE slogan slogan longtext");
+    $ret[] = update_sql("ALTER TABLE {directory} CHANGE mission mission longtext");
+    $ret[] = update_sql("ALTER TABLE {feed} CHANGE description description longtext");
+    $ret[] = update_sql("ALTER TABLE {item} CHANGE description description longtext");
+    $ret[] = update_sql("ALTER TABLE {node} CHANGE users users longtext");
+    $ret[] = update_sql("ALTER TABLE {node} CHANGE teaser teaser longtext");
+    $ret[] = update_sql("ALTER TABLE {node} CHANGE body body longtext");
+    $ret[] = update_sql("ALTER TABLE {node} CHANGE revisions revisions longtext");
+    $ret[] = update_sql("ALTER TABLE {permission} CHANGE perm perm longtext");
+    $ret[] = update_sql("ALTER TABLE {poll} CHANGE voters voters longtext");
+    $ret[] = update_sql("ALTER TABLE {sessions} CHANGE session session longtext");
+    $ret[] = update_sql("ALTER TABLE {term_data} CHANGE description description longtext");
+    $ret[] = update_sql("ALTER TABLE {users} CHANGE data data longtext");
+    $ret[] = update_sql("ALTER TABLE {variable} CHANGE value value longtext");
+    $ret[] = update_sql("ALTER TABLE {vocabulary} CHANGE description description longtext");
+    $ret[] = update_sql("ALTER TABLE {vocabulary} CHANGE nodes nodes longtext");
+    $ret[] = update_sql("ALTER TABLE {watchdog} CHANGE message message longtext");
+  }
+  return $ret;
+}
+
+function update_74() {
+  $ret = array();
+  if ($GLOBALS["db_type"] == "pgsql") {
+    $ret[] = update_sql("ALTER TABLE {system} ADD throttle smallint");
+    $ret[] = update_sql("ALTER TABLE {system} ALTER COLUMN throttle SET DEFAULT '0'");
+    $ret[] = update_sql("UPDATE {system} SET throttle = 0");
+    $ret[] = update_sql("ALTER TABLE {system} ALTER COLUMN throttle SET NOT NULL");
+  }
+  else {
+    $ret[] = update_sql("ALTER TABLE {system} ADD throttle tinyint(1) NOT NULL DEFAULT '0'");
+  }
+  return $ret;
+}
+
+function update_75() {
+  $ret = array();
+  if ($GLOBALS["db_type"] == "pgsql") {
+    $ret[] = update_sql("ALTER TABLE {feed} ADD etag text");
+    $ret[] = update_sql("ALTER TABLE {feed} ALTER COLUMN etag SET DEFAULT ''");
+    $ret[] = update_sql("ALTER TABLE {feed} ALTER COLUMN etag SET NOT NULL");
+
+    $ret[] = update_sql("ALTER TABLE {feed} ADD modified integer");
+    $ret[] = update_sql("ALTER TABLE {feed} ALTER COLUMN modified SET DEFAULT '0'");
+    $ret[] = update_sql("UPDATE {feed} SET modified = 0");
+    $ret[] = update_sql("ALTER TABLE {feed} ALTER COLUMN modified SET NOT NULL");
+
+    $ret[] = update_sql("ALTER TABLE {feed} RENAME timestamp TO checked");
+
+    $ret[] = update_sql("UPDATE {blocks} SET module = 'aggregator' WHERE module = 'import'");
+    $ret[] = update_sql("UPDATE {system} SET filename = 'modules/aggregator.module', name = 'aggregator' WHERE filename = 'modules/import.module'");
+  }
+  else {
+    $ret[] = update_sql("ALTER TABLE {feed} ADD etag varchar(255) NOT NULL DEFAULT ''");
+    $ret[] = update_sql("ALTER TABLE {feed} ADD modified int(10) NOT NULL DEFAULT 0");
+    $ret[] = update_sql("ALTER TABLE {feed} CHANGE timestamp checked int(10) NOT NULL DEFAULT 0");
+    $ret[] = update_sql("UPDATE {blocks} SET module = 'aggregator' WHERE module = 'import'");
+    $ret[] = update_sql("UPDATE {system} SET filename = 'modules/aggregator.module', name = 'aggregator' WHERE filename = 'modules/import.module'");
+  }
+  return $ret;
+}
+
+function update_76() {
+  $ret = array();
+  if ($GLOBALS["db_type"] == "pgsql") {
+    $ret[] = update_sql("ALTER TABLE {feed} ADD image text");
+  } else {
+    $ret[] = update_sql("ALTER TABLE {feed} ADD image longtext");
+  }
+  return $ret;
+}
+
+function update_77() {
+  $ret = array();
+  $ret[] = update_sql("ALTER TABLE {cache} ADD headers text");
+  return $ret;
+}
+
+function update_78() {
+  $ret = array();
+  if ($GLOBALS["db_type"] == "mysql") {
+    $ret[] = update_sql("CREATE TABLE {filters} (
+      module varchar(64) NOT NULL default '',
+      weight tinyint(2) DEFAULT '0' NOT NULL,
+      KEY weight (weight)
+    )");
+  }
+  else {
+    /* Needs PGSQL/MSSQL equivalent */
+  }
+  return $ret;
+}
+
+function update_79() {
+  $ret = array();
+  // Works for both mysql and postgresql
+  $ret[] = update_sql("ALTER TABLE {node} DROP attributes");
+  $ret[] = update_sql("ALTER TABLE {comments} DROP link");
+  return $ret;
+}
+
+function update_sql($sql) {
+  $edit = $_POST["edit"];
+  $result = db_query($sql);
+  if ($result) {
+    return array('1', nl2br(htmlentities($sql)) ." ", "<div style=\"color: green;\">OK</div>\n");
+  }
+  else {
+    return array('0', nl2br(htmlentities($sql)) ." ", "<div style=\"color: red;\">FAILED</div>\n");
+  }
+}
+
+?>
diff --git a/modules/poll.module b/modules/poll.module
index cbc95c404e85..faf4fc3b3639 100644
--- a/modules/poll.module
+++ b/modules/poll.module
@@ -118,7 +118,7 @@ function poll_form(&$node, &$error) {
   $output .= '<div class="poll-form">';
 
   // Poll choices
-  $opts = drupal_map_assoc(range(2, $node->choices * 2 + 5)); 
+  $opts = drupal_map_assoc(range(2, $node->choices * 2 + 5));
   for ($a = 0; $a < $node->choices; $a++) {
     $group1 .= form_textfield(t('Choice %n', array('%n' => ($a + 1))), "choice][$a][chtext", $node->choice[$a]['chtext'], 50, 127, $error["choice][$a][chtext"]);
     if ($admin) {
@@ -129,7 +129,7 @@ function poll_form(&$node, &$error) {
   $group1 .= form_checkbox(t('Need more choices'), 'morechoices', 1, 0, t("If the amount of boxes above isn't enough, check this box and click the Preview button below to add some more."));
   $output .= form_group(t('Choices'), $group1);
 
-  
+
   // Poll attributes
   $_duration = array_merge(array(0 => t('Unlimited')), drupal_map_assoc(array(86400, 172800, 345600, 604800, 1209600, 2419200, 4838400, 9676800, 31536000), "format_interval"));
   $_active = array(0 => t('Closed'), 1 => t('Active'));
@@ -138,8 +138,8 @@ function poll_form(&$node, &$error) {
     $group2 .= form_radios(t('Poll status'), 'active', isset($node->active) ? $node->active : 1, $_active, t('When a poll is closed, visitors can no longer vote for it.'));
   }
   $group2 .= form_select(t('Poll duration'), 'runtime', $node->runtime ? $node->runtime : 0, $_duration, t('After this period, the poll will be closed automatically.'));
-  
-  $output .= form_group(t('Settings'), $group2); 
+
+  $output .= form_group(t('Settings'), $group2);
   $output .= '</div>';
 
   return $output;
diff --git a/modules/poll/poll.module b/modules/poll/poll.module
index cbc95c404e85..faf4fc3b3639 100644
--- a/modules/poll/poll.module
+++ b/modules/poll/poll.module
@@ -118,7 +118,7 @@ function poll_form(&$node, &$error) {
   $output .= '<div class="poll-form">';
 
   // Poll choices
-  $opts = drupal_map_assoc(range(2, $node->choices * 2 + 5)); 
+  $opts = drupal_map_assoc(range(2, $node->choices * 2 + 5));
   for ($a = 0; $a < $node->choices; $a++) {
     $group1 .= form_textfield(t('Choice %n', array('%n' => ($a + 1))), "choice][$a][chtext", $node->choice[$a]['chtext'], 50, 127, $error["choice][$a][chtext"]);
     if ($admin) {
@@ -129,7 +129,7 @@ function poll_form(&$node, &$error) {
   $group1 .= form_checkbox(t('Need more choices'), 'morechoices', 1, 0, t("If the amount of boxes above isn't enough, check this box and click the Preview button below to add some more."));
   $output .= form_group(t('Choices'), $group1);
 
-  
+
   // Poll attributes
   $_duration = array_merge(array(0 => t('Unlimited')), drupal_map_assoc(array(86400, 172800, 345600, 604800, 1209600, 2419200, 4838400, 9676800, 31536000), "format_interval"));
   $_active = array(0 => t('Closed'), 1 => t('Active'));
@@ -138,8 +138,8 @@ function poll_form(&$node, &$error) {
     $group2 .= form_radios(t('Poll status'), 'active', isset($node->active) ? $node->active : 1, $_active, t('When a poll is closed, visitors can no longer vote for it.'));
   }
   $group2 .= form_select(t('Poll duration'), 'runtime', $node->runtime ? $node->runtime : 0, $_duration, t('After this period, the poll will be closed automatically.'));
-  
-  $output .= form_group(t('Settings'), $group2); 
+
+  $output .= form_group(t('Settings'), $group2);
   $output .= '</div>';
 
   return $output;
diff --git a/themes/xtemplate/pushbutton/xtemplate.css b/themes/xtemplate/pushbutton/xtemplate.css
index bcbb6beb2203..154b6d7c4489 100644
--- a/themes/xtemplate/pushbutton/xtemplate.css
+++ b/themes/xtemplate/pushbutton/xtemplate.css
@@ -5,16 +5,16 @@
 */
 body  {
   color: #000;
-  background-color: #fff; 
-  margin: 0; 
+  background-color: #fff;
+  margin: 0;
   padding: 0;
 }
-body, p, td, li, ul, ol  { 
-  font-family: Verdana, Helvetica, Arial, sans-serif; 
+body, p, td, li, ul, ol  {
+  font-family: Verdana, Helvetica, Arial, sans-serif;
 }
-h1, h2, h3, h4, h5, h6 { 
-  font-family: "Trebuchet MS", Geneva, Arial, Helvetica, SunSans-Regular, Verdana, sans-serif; 
-  color: #369; 
+h1, h2, h3, h4, h5, h6 {
+  font-family: "Trebuchet MS", Geneva, Arial, Helvetica, SunSans-Regular, Verdana, sans-serif;
+  color: #369;
 }
 img {
   display: block;
@@ -89,8 +89,8 @@ pre {
 /*
 ** Page layout blocks / IDs
 */
-table#primary-links-table  { 
-  background-color: #e0edfb; 
+table#primary-links-table  {
+  background-color: #e0edfb;
 }
 table#primary-links-table tr {
   background: transparent url(header-a.jpg) left bottom repeat;
@@ -105,33 +105,33 @@ td#home a:hover img {
   width: 144px;
   height: 63px;
 }
-#primary-links   { 
+#primary-links   {
   background: transparent url(header-b.jpg) left top no-repeat;
   font-size: 0.85em;
 }
-#primary-links h1, #primary-links h2, #primary-links h3 { 
+#primary-links h1, #primary-links h2, #primary-links h3 {
   font-size: 1.7em;
 }
-#primary-links a  { 
-  color: #369; 
+#primary-links a  {
+  color: #369;
 }
 #primary-links a:hover {
   color: #000;
 }
-table#secondary-links-table   { 
-  background-color: #369; 
-  border-top: 3px solid #69c; 
+table#secondary-links-table   {
+  background-color: #369;
+  border-top: 3px solid #69c;
   border-bottom: 3px solid #69c;
   font-size: 0.85em;
 }
-td#secondary-links { 
+td#secondary-links {
   color: #e4e9eb;
 }
-#secondary-links a  { 
+#secondary-links a  {
   color: #e4e9eb;
 }
-#secondary-links a:hover { 
-  color: #fff; 
+#secondary-links a:hover {
+  color: #fff;
   text-decoration: underline;
 }
 #content {
@@ -161,11 +161,11 @@ td#secondary-links {
 #mission {
   background-color: #fff;
   color: #696969;
-  border-top: 2px solid #dcdcdc; 
+  border-top: 2px solid #dcdcdc;
   border-bottom: 2px solid #dcdcdc;
   padding: 10px 10px 10px 10px;
   margin: 20px 35px 0px 35px;
-  font-family: "Trebuchet MS", Geneva, Arial, Helvetica, SunSans-Regular, Verdana, sans-serif; 
+  font-family: "Trebuchet MS", Geneva, Arial, Helvetica, SunSans-Regular, Verdana, sans-serif;
   font-size: 1.1em;
   font-weight: normal;
 }
@@ -221,7 +221,7 @@ td#secondary-links {
   color: #aaa;
 }
 table#footer-links {
-  border-top: 3px solid #6699cc; 
+  border-top: 3px solid #6699cc;
   border-bottom: 3px solid #6699cc;
   background-color: #369;
   color: #e4e9eb;
@@ -280,7 +280,7 @@ table#footer-links {
 .box h2 {
   font-size: 9px;
 }
-.block .title h3 { 
+.block .title h3 {
   border-bottom: 2px solid #6699cc;
   color: #369;
   font-size: 18px;
@@ -289,7 +289,7 @@ table#footer-links {
   margin-bottom: .25em;
   background: transparent url(icon-block.gif) left center no-repeat;
 }
-.block .content { 
+.block .content {
   padding: 5px 5px 5px 5px;
 }
 .block {
diff --git a/update.php b/update.php
index 9e984c945ee1..b92e011d7d3a 100644
--- a/update.php
+++ b/update.php
@@ -19,692 +19,18 @@
   set_time_limit(180);
 }
 
-// Define the various updates in an array("date : comment" => "function");
-$mysql_updates = array(
-  "2002-06-22: first update since Drupal 4.0.0 release" => "update_32",
-  "2002-07-07" => "update_33",
-  "2002-07-31" => "update_34",
-  "2002-08-10" => "update_35",
-  "2002-08-16" => "update_36",
-  "2002-08-19" => "update_37",
-  "2002-08-26" => "update_38",
-  "2002-09-15" => "update_39",
-  "2002-09-17" => "update_40",
-  "2002-10-13" => "update_41",
-  "2002-10-17" => "update_42",
-  "2002-10-26" => "update_43",
-  "2002-11-08" => "update_44",
-  "2002-11-20" => "update_45",
-  "2002-12-10: first update since Drupal 4.1.0 release" => "update_46",
-  "2002-12-29" => "update_47",
-  "2003-01-03" => "update_48",
-  "2003-01-05" => "update_49",
-  "2003-01-15" => "update_50",
-  "2003-04-19" => "update_51",
-  "2003-04-20" => "update_52",
-  "2003-05-18" => "update_53",
-  "2003-05-24" => "update_54",
-  "2003-05-31" => "update_55",
-  "2003-06-04" => "update_56",
-  "2003-06-08" => "update_57",
-  "2003-06-08: first update since Drupal 4.2.0 release" => "update_58",
-  "2003-08-05" => "update_59",
-  "2003-08-15" => "update_60",
-  "2003-08-20" => "update_61",
-  "2003-08-27" => "update_62",
-  "2003-09-09" => "update_63",
-  "2003-09-10" => "update_64",
-  "2003-09-29" => "update_65",
-  "2003-09-30" => "update_66",
-  "2003-10-11" => "update_67",
-  "2003-10-20" => "update_68",
-  "2003-10-22" => "update_69",
-  "2003-10-27" => "update_70",
-  "2003-11-17: first update since Drupal 4.3.0 release" => "update_71",
-  "2003-11-27" => "update_72",
-  "2003-12-03" => "update_73",
-  "2003-12-06" => "update_74",
-  "2004-01-06" => "update_75",
-  "2004-01-11" => "update_76",
-  "2004-01-13" => "update_77",
-  "2004-02-03" => "update_78",
-  "2004-02-21" => "update_79"
-);
-
-function update_32() {
-  update_sql("ALTER TABLE users ADD index (sid(4))");
-  update_sql("ALTER TABLE users ADD index (timestamp)");
-  update_sql("ALTER TABLE users ADD UNIQUE KEY name (name)");
-}
-
-function update_33() {
-  $result = db_query("SELECT * FROM variable WHERE value NOT LIKE 's:%;'");
-  // NOTE: the "WHERE"-part of the query above avoids variables to get serialized twice.
-  while ($variable = db_fetch_object($result)) {
-    variable_set($variable->name, $variable->value);
-  }
-}
-
-function update_34() {
-  update_sql("ALTER TABLE feed MODIFY refresh int(10) NOT NULL default '0'");
-  update_sql("ALTER TABLE feed MODIFY timestamp int (10) NOT NULL default '0'");
-  update_sql("ALTER TABLE users CHANGE session session TEXT");
-}
-
-function update_35() {
-  update_sql("ALTER TABLE poll_choices ADD INDEX (nid)");
-}
-
-function update_36() {
-  update_sql("ALTER TABLE rating CHANGE old previous int(6) NOT NULL default '0'");
-  update_sql("ALTER TABLE rating CHANGE new current int(6) NOT NULL default '0'");
-}
-
-function update_37() {
-
-  update_sql("DROP TABLE IF EXISTS sequences");
-
-  update_sql("CREATE TABLE sequences (
-    name VARCHAR(255) NOT NULL PRIMARY KEY,
-    id INT UNSIGNED NOT NULL
-  ) TYPE=MyISAM");
-
-  if ($max = db_result(db_query("SELECT MAX(nid) FROM node"))) {
-    update_sql("REPLACE INTO sequences VALUES ('node', $max)");
-  }
-
-  if ($max = db_result(db_query("SELECT MAX(cid) FROM comments"))) {
-    update_sql("REPLACE INTO sequences VALUES ('comments', $max)");
-  }
-  // NOTE: move the comments bit down as soon as we switched to use the new comment module!
-
-  if ($max = db_result(db_query("SELECT MAX(tid) FROM term_data"))) {
-    update_sql("REPLACE INTO sequences VALUES ('term_data', $max)");
-  }
-}
-
-function update_38() {
-  update_sql("ALTER TABLE watchdog CHANGE message message text NOT NULL default ''");
-}
-
-function update_39() {
-  update_sql("DROP TABLE moderate");
-
-  update_sql("ALTER TABLE comments ADD score MEDIUMINT NOT NULL");
-  update_sql("ALTER TABLE comments ADD status TINYINT UNSIGNED NOT NULL");
-  update_sql("ALTER TABLE comments ADD users MEDIUMTEXT");
-
-  update_sql("CREATE TABLE moderation_votes (
-    mid INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
-    vote VARCHAR(255),
-    weight TINYINT NOT NULL
-  )");
-
-  update_sql("CREATE TABLE moderation_roles (
-    rid INT UNSIGNED NOT NULL,
-    mid INT UNSIGNED NOT NULL,
-    value TINYINT NOT NULL
-  )");
-
-  update_sql("ALTER TABLE moderation_roles ADD INDEX (rid)");
-  update_sql("ALTER TABLE moderation_roles ADD INDEX (mid)");
-
-  update_sql("CREATE TABLE moderation_filters (
-    fid INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
-    filter VARCHAR(255) NOT NULL,
-    minimum SMALLINT NOT NULL
-  )");
-
-  update_sql("DELETE FROM moderation_votes");
-  update_sql("INSERT INTO moderation_votes VALUES (1, '+1', 0)");
-  update_sql("INSERT INTO moderation_votes VALUES (2, '-1', 1)");
-
-  update_sql("DELETE FROM moderation_roles");
-  update_sql("INSERT INTO moderation_roles VALUES (2, 1, 1)");
-  update_sql("INSERT INTO moderation_roles VALUES (2, 2, -1)");
-
-  update_sql("CREATE TABLE forum (
-    nid int unsigned not null primary key,
-    icon varchar(255) not null,
-    shadow int unsigned not null
-  )");
-}
-
-function update_40() {
-  if ($max = db_result(db_query("SELECT MAX(cid) FROM comments"))) {
-    update_sql("REPLACE INTO sequences VALUES ('comments', $max)");
-  }
-}
-
-function update_41() {
-  update_sql("CREATE TABLE statistics (
-    nid int(11) NOT NULL,
-    totalcount bigint UNSIGNED DEFAULT '0' NOT NULL,
-    daycount mediumint UNSIGNED DEFAULT '0' NOT NULL,
-    timestamp int(11) UNSIGNED DEFAULT '0' NOT NULL,
-    PRIMARY KEY (nid),
-    INDEX (totalcount),
-    INDEX (daycount),
-    INDEX (timestamp)
-  )");
-
-  update_sql("CREATE TABLE accesslog (
-    nid int(11) UNSIGNED DEFAULT '0',
-    url varchar(255),
-    hostname varchar(128),
-    uid int(10) UNSIGNED DEFAULT '0',
-    timestamp int(11) UNSIGNED NOT NULL
-  )");
-}
-
-function update_42() {
-  update_sql("DROP TABLE modules");
-  update_sql("DROP TABLE layout");
-  update_sql("DROP TABLE referrer");
-}
-
-function update_43() {
-  update_sql("ALTER TABLE blocks DROP remove");
-  update_sql("ALTER TABLE blocks DROP name");
-  update_sql("UPDATE boxes SET type = 0 WHERE type = 1");
-  update_sql("UPDATE boxes SET type = 1 WHERE type = 2");
-}
-
-function update_44() {
-  update_sql("UPDATE system SET filename = CONCAT('modules/', filename) WHERE type = 'module'");
-}
-
-function update_45() {
-  update_sql("ALTER TABLE page ADD description varchar(128) NOT NULL default ''");
-}
-
-function update_46() {
-  if ($GLOBALS["db_type"] == "pgsql") {
-    update_sql("ALTER TABLE cache ADD created integer");
-  }
-  else {
-    update_sql("ALTER TABLE cache ADD created int(11) NOT NULL default '0'");
-  }
-}
-
-function update_47() {
-  if ($max = db_result(db_query("SELECT MAX(vid) FROM vocabulary"))) {
-    update_sql("REPLACE INTO sequences VALUES ('vocabulary', $max)");
-  }
-}
-
-function update_48() {
-  update_sql("ALTER TABLE watchdog ADD link varchar(255) DEFAULT '' NULL");
-}
-
-function update_49() {
-  /*
-  ** Make sure the admin module is added to the system table or the
-  ** admin menus won't show up.
-  */
-
-  update_sql("DELETE FROM system WHERE name = 'admin';");
-  update_sql("INSERT INTO system VALUES ('modules/admin.module','admin','module','',1)");
-}
-
-function update_50() {
-  update_sql("ALTER TABLE forum ADD tid INT UNSIGNED NOT NULL");
-  $result = db_queryd("SELECT n.nid, t.tid FROM node n, term_node t WHERE n.nid = t.nid AND type = 'forum'");
-  while ($node = db_fetch_object($result)) {
-    db_queryd("UPDATE forum SET tid = %d WHERE nid = %d", $node->tid, $node->nid);
-  }
-  update_sql("ALTER TABLE forum ADD INDEX (tid)");
-}
-
-function update_51() {
-  update_sql("ALTER TABLE blocks CHANGE delta delta varchar(32) NOT NULL default '0'");
-}
-
-function update_52() {
-  update_sql("UPDATE sequences SET name = 'comments_cid' WHERE name = 'comments';");
-  update_sql("UPDATE sequences SET name = 'node_nid' WHERE name = 'node';");
-
-  update_sql("DELETE FROM sequences WHERE name = 'import'");
-  update_sql("DELETE FROM sequences WHERE name = 'bundle_bid'");  // in case we would run this entry twice
-  update_sql("DELETE FROM sequences WHERE name = 'feed_fid'");    // in case we would run this entry twice
-
-  $bundles = db_result(db_query("SELECT MAX(bid) FROM bundle;"));
-  update_sql("INSERT INTO sequences (name, id) VALUES ('bundle_bid', '$bundles')");
-
-  $feeds = db_result(db_query("SELECT MAX(fid) FROM feed;"));
-  update_sql("INSERT INTO sequences (name, id) VALUES ('feed_fid', '$feeds')");
-
-  update_sql("UPDATE sequences SET name = 'vocabulary_vid' WHERE name = 'vocabulary';");
-
-  update_sql("UPDATE sequences SET name = 'term_data_tid' WHERE name = 'term_data'");
-}
-
-function update_53() {
-  update_sql("CREATE INDEX book_parent ON book(parent);");
-}
-
-function update_54() {
-  update_sql("ALTER TABLE locales CHANGE string string BLOB DEFAULT '' NOT NULL");
-}
-
-function update_55() {
-  update_sql("ALTER TABLE site ADD checked INT(11) NOT NULL;");
-  update_sql("ALTER TABLE site CHANGE timestamp changed INT(11) NOT NULL;");
-}
-
-function update_56() {
-  update_sql("ALTER TABLE vocabulary CHANGE types nodes TEXT DEFAULT '' NOT NULL");
-}
-
-function update_57() {
-  update_sql("DELETE FROM variable WHERE name = 'site_charset'");
-}
-
-function update_58() {
-  if ($GLOBALS["db_type"] == "pgsql") {
-    update_sql("ALTER TABLE {node} ADD path varchar(250) NULL");
-    update_sql("ALTER TABLE {node} ALTER COLUMN path SET DEFAULT ''");
-  }
-  else {
-    update_sql("ALTER TABLE {node} ADD path varchar(250) NULL default ''");
-  }
-}
-
-function update_59() {
-  if ($GLOBALS["db_type"] == "pgsql") {
-    update_sql("ALTER TABLE {comments} ADD thread VARCHAR(255)");
-    update_sql("ALTER TABLE {comments} ALTER COLUMN thread SET NOT NULL");
-  }
-  else {
-    update_sql("ALTER TABLE {comments} ADD thread VARCHAR(255) NOT NULL");
-  }
-
-  $result = db_query("SELECT DISTINCT(nid) FROM {comments} WHERE thread = ''");
-
-  while ($node = db_fetch_object($result)) {
-    $result2 = db_query("SELECT cid, pid FROM {comments} where nid = '%d' ORDER BY timestamp", $node->nid);
-    $comments = array();
-    while ($comment = db_fetch_object($result2)) {
-      $comments[$comment->cid] = $comment;
-    }
-
-    $structure = array();
-    $structure = _update_thread_structure($comments, 0, -1, $structure);
-
-    foreach ($structure as $cid => $thread) {
-      $new_parts = array();
-      foreach(explode(".", $thread) as $part) {
-        if ($part > 9) {
-          $start = substr($part, 0, strlen($part) - 1);
-          $end = substr($part, -1, 1);
-
-          $new_parts[] = str_repeat("9", $start).$end;
-        }
-        else {
-          $new_parts[] = $part;
-        }
-      }
-      $thread = implode(".", $new_parts);
-
-      db_query("UPDATE {comments} SET thread = '%s' WHERE cid = '%d'", $thread."/", $comments[$cid]->cid);
-    }
-  }
-}
-
-function _update_thread_structure($comments, $pid, $depth, $structure) {
-  $depth++;
-
-  foreach ($comments as $key => $comment) {
-    if ($comment->pid == $pid) {
-      if ($structure[$comment->pid]) {
-        $structure[$comment->cid] = $structure[$comment->pid]."."._update_next_thread($structure, $structure[$comment->pid]);
-      }
-      else {
-        $structure[$comment->cid] = _update_next_thread($structure, "");
-      }
-
-      $structure = _update_thread_structure($comments, $comment->cid, $depth, $structure);
-    }
-  }
-
-  return $structure;
-}
-
-function update_60() {
-  update_sql("ALTER TABLE {forum} DROP icon");
-}
-
-function update_61() {
-  if ($GLOBALS["db_type"] == "pgsql") {
-    update_sql("CREATE TABLE {sessions} (
-      uid integer NOT NULL,
-      sid varchar(32) NOT NULL default '',
-      hostname varchar(128) NOT NULL default '',
-      timestamp integer NOT NULL default '0',
-      session text,
-      PRIMARY KEY (sid)
-     );");
-
-    update_sql("ALTER TABLE {users} DROP session;");
-    update_sql("ALTER TABLE {users} DROP hostname;");
-    update_sql("ALTER TABLE {users} DROP sid;");
-
-  }
-  else {
-    update_sql("CREATE TABLE IF NOT EXISTS {sessions} (
-      uid int(10) unsigned NOT NULL,
-      sid varchar(32) NOT NULL default '',
-      hostname varchar(128) NOT NULL default '',
-      timestamp int(11) NOT NULL default '0',
-      session text,
-      KEY uid (uid),
-      KEY sid (sid(4)),
-      KEY timestamp (timestamp)
-    )");
-
-    update_sql("ALTER TABLE {users} DROP session;");
-    update_sql("ALTER TABLE {users} DROP hostname;");
-    update_sql("ALTER TABLE {users} DROP sid;");
-  }
-}
-
-function update_62() {
-  if ($GLOBALS["db_type"] == "pgsql") {
-    update_sql("CREATE INDEX accesslog_timestamp ON {accesslog} (timestamp)");
-
-    update_sql("DROP INDEX node_type_idx");
-    update_sql("DROP INDEX node_title_idx");
-    update_sql("DROP INDEX node_promote_idx");
-
-    update_sql("CREATE INDEX node_type ON {node} (type)");
-    update_sql("CREATE INDEX node_title_type ON {node} (title,type)");
-    update_sql("CREATE INDEX node_moderate ON {node} (moderate)");
-    update_sql("CREATE INDEX node_path ON {node} (path)");
-    update_sql("CREATE INDEX node_promote_status ON {node} (promote, status)");
-
-  }
-  else {
-    update_sql("ALTER TABLE {accesslog} ADD INDEX accesslog_timestamp (timestamp)");
-
-    update_sql("ALTER TABLE {node} DROP INDEX type");
-    update_sql("ALTER TABLE {node} DROP INDEX title");
-    update_sql("ALTER TABLE {node} DROP INDEX promote");
-
-    update_sql("ALTER TABLE {node} ADD INDEX node_type (type(4))");
-    update_sql("ALTER TABLE {node} ADD INDEX node_title_type (title,type(4))");
-    update_sql("ALTER TABLE {node} ADD INDEX node_moderate (moderate)");
-    update_sql("ALTER TABLE {node} ADD INDEX node_path (path(5))");
-    update_sql("ALTER TABLE {node} ADD INDEX node_promote_status (promote, status)");
-  }
-}
-
-function _update_next_thread($structure, $parent) {
-  do {
-    $val++;
-    if ($parent) {
-      $thread = "$parent.$val";
-    }
-    else {
-      $thread = $val;
-    }
-
-  } while (array_search($thread, $structure));
-
-  return $val;
-}
-
-function update_63() {
-  if ($GLOBALS["db_type"] == "pgsql") {
-    update_sql("INSERT INTO {users} (uid, name, mail, timestamp) VALUES ('0', '', '', '". time() ."')");
-  }
-  else {
-    update_sql("ALTER TABLE {users} CHANGE uid uid int(10) unsigned NOT NULL default '0'");
-    update_sql("INSERT INTO {users} (uid, name, mail, timestamp) VALUES ('0', '', '', '". time() ."')");
-    $users = db_result(db_query("SELECT MAX(uid) FROM {users};"));
-    update_sql("INSERT INTO {sequences} (name, id) VALUES ('users_uid', '$users')");
-  }
-}
-
-function update_64() {
-  update_sql("UPDATE {users} SET rid = 1 WHERE uid = 0");
-}
-
-function update_65() {
-  // PostgreSQL-only update.
-  if ($GLOBALS["db_type"] == "pgsql") {
-    update_sql("CREATE FUNCTION \"rand\"() RETURNS float AS '
-      BEGIN
-        RETURN random();
-      END;' LANGUAGE 'plpgsql'");
-  }
-}
-
-function update_66() {
-  if ($GLOBALS["db_type"] == "pgsql") {
-    update_sql("CREATE TABLE {path} (
-      pid serial,
-      src varchar(128) NOT NULL default '',
-      dst varchar(128) NOT NULL default '',
-      PRIMARY KEY  (pid)
-    )");
-    update_sql("CREATE INDEX path_src_idx ON {path}(src)");
-    update_sql("CREATE INDEX path_dst_idx ON {path}(dst)");
-    $result = db_query("SELECT nid, path FROM {node} WHERE path != ''");
-    while ($node = db_fetch_object($result)) {
-      update_sql("INSERT INTO {path} (src, dst) VALUES ('node/view/$node->nid', '". check_query($node->path) ."')");
-    }
-  }
-  else {
-    update_sql("CREATE TABLE {path} (
-      pid int(10) unsigned NOT NULL auto_increment,
-      src varchar(128) NOT NULL default '',
-      dst varchar(128) NOT NULL default '',
-      PRIMARY KEY  (pid),
-      UNIQUE KEY src (src),
-      UNIQUE KEY dst (dst)
-    )");
-    // Migrate the existing paths:
-    $result = db_query("SELECT nid, path FROM {node} WHERE path != ''");
-    while ($node = db_fetch_object($result)) {
-      update_sql("INSERT INTO {path} (src, dst) VALUES ('node/view/$node->nid', '". check_query($node->path) ."')");
-    }
-
-    update_sql("ALTER TABLE {node} DROP path");
-  }
-}
-
-function update_67() {
-  if ($GLOBALS["db_type"] == "pgsql") {
-    // Taking no action.  PostgreSQL is not always capable of dropping columns.
-  }
-  else {
-    update_sql("ALTER TABLE {users} DROP homepage");
-  }
-}
-
-function update_68() {
-  if ($GLOBALS["db_type"] == "pgsql") {
-    // Unneccesary. The PostgreSQL port was already using a sequence.
-  }
-  else {
-    $max = db_result(db_query("SELECT MAX(aid) FROM {access};"));
-    update_sql("INSERT INTO {sequences} (name, id) VALUES ('access_aid', '$max')");
-    update_sql("ALTER TABLE {access} CHANGE aid aid tinyint(10) NOT NULL ");
-  }
-}
-
-function update_69() {
-  if ($GLOBALS["db_type"] == "pgsql") {
-    /* Rename the statistics table to node_counter */
-    update_sql("ALTER TABLE {statistics} RENAME TO {node_counter}");
-    update_sql("DROP INDEX  {statistics}_totalcount_idx");
-    update_sql("DROP INDEX  {statistics}_daycount_idx");
-    update_sql("DROP INDEX  {statistics}_timestamp_idx");
-    update_sql("CREATE INDEX {node_counter}_totalcount_idx ON {node_counter}(totalcount)");
-    update_sql("CREATE INDEX {node_counter}_daycount_idx ON {node_counter}(daycount)");
-    update_sql("CREATE INDEX {node_counter}_timestamp_idx ON {node_counter}(timestamp)");
-
-    /* Rename the path table to url_alias */
-    update_sql("ALTER TABLE {path} RENAME TO {url_alias}");
-    update_sql("ALTER TABLE {path}_pid_seq RENAME TO {url_alias}_pid_seq");
-  }
-  else {
-    update_sql("ALTER TABLE {statistics} RENAME TO {node_counter}");
-    update_sql("ALTER TABLE {path} RENAME TO {url_alias}");
-    update_sql("UPDATE {sequences} SET name = '{url_alias}_pid' WHERE name = '{path}_pid'");
-  }
-
-  update_sql("UPDATE {users} SET name = '' WHERE uid = 0;");
-}
-
-function update_70() {
-  update_sql("ALTER TABLE {variable} CHANGE name name varchar(48) NOT NULL");
-}
-
-function update_71() {
-  if ($GLOBALS["db_type"] == "pgsql") {
-    update_sql("ALTER TABLE {system} ADD bootstrap integer");
-  }
-  else {
-    update_sql("ALTER TABLE {system} ADD bootstrap int(2)");
-  }
-}
-
-function update_72() {
-  if ($GLOBALS["db_type"] == "pgsql") {
-    update_sql("ALTER TABLE {blocks} ADD throttle smallint");
-    update_sql("ALTER TABLE {blocks} ALTER COLUMN throttle SET DEFAULT '0'");
-    update_sql("UPDATE {blocks} SET throttle = 0");
-    update_sql("ALTER TABLE {blocks} ALTER COLUMN throttle SET NOT NULL");
-  }
-  else {
-    update_sql("ALTER TABLE {blocks} ADD throttle tinyint(1) NOT NULL DEFAULT '0'");
-  }
-}
-
-function update_73() {
-  /* MySQL only update */
-  if ($GLOBALS["db_type"] == "mysql") {
-    update_sql("ALTER TABLE {book} CHANGE log log longtext");
-    update_sql("ALTER TABLE {boxes} CHANGE body body longtext");
-    update_sql("ALTER TABLE {cache} CHANGE data data longtext");
-    update_sql("ALTER TABLE {comments} CHANGE comment comment longtext");
-    update_sql("ALTER TABLE {comments} CHANGE users users longtext");
-    update_sql("ALTER TABLE {directory} CHANGE slogan slogan longtext");
-    update_sql("ALTER TABLE {directory} CHANGE mission mission longtext");
-    update_sql("ALTER TABLE {feed} CHANGE description description longtext");
-    update_sql("ALTER TABLE {item} CHANGE description description longtext");
-    update_sql("ALTER TABLE {node} CHANGE users users longtext");
-    update_sql("ALTER TABLE {node} CHANGE teaser teaser longtext");
-    update_sql("ALTER TABLE {node} CHANGE body body longtext");
-    update_sql("ALTER TABLE {node} CHANGE revisions revisions longtext");
-    update_sql("ALTER TABLE {permission} CHANGE perm perm longtext");
-    update_sql("ALTER TABLE {poll} CHANGE voters voters longtext");
-    update_sql("ALTER TABLE {sessions} CHANGE session session longtext");
-    update_sql("ALTER TABLE {term_data} CHANGE description description longtext");
-    update_sql("ALTER TABLE {users} CHANGE data data longtext");
-    update_sql("ALTER TABLE {variable} CHANGE value value longtext");
-    update_sql("ALTER TABLE {vocabulary} CHANGE description description longtext");
-    update_sql("ALTER TABLE {vocabulary} CHANGE nodes nodes longtext");
-    update_sql("ALTER TABLE {watchdog} CHANGE message message longtext");
-  }
-}
-
-function update_74() {
-  if ($GLOBALS["db_type"] == "pgsql") {
-    update_sql("ALTER TABLE {system} ADD throttle smallint");
-    update_sql("ALTER TABLE {system} ALTER COLUMN throttle SET DEFAULT '0'");
-    update_sql("UPDATE {system} SET throttle = 0");
-    update_sql("ALTER TABLE {system} ALTER COLUMN throttle SET NOT NULL");
-  }
-  else {
-    update_sql("ALTER TABLE {system} ADD throttle tinyint(1) NOT NULL DEFAULT '0'");
-  }
-}
-
-function update_75() {
-  if ($GLOBALS["db_type"] == "pgsql") {
-    update_sql("ALTER TABLE {feed} ADD etag text");
-    update_sql("ALTER TABLE {feed} ALTER COLUMN etag SET DEFAULT ''");
-    update_sql("ALTER TABLE {feed} ALTER COLUMN etag SET NOT NULL");
-
-    update_sql("ALTER TABLE {feed} ADD modified integer");
-    update_sql("ALTER TABLE {feed} ALTER COLUMN modified SET DEFAULT '0'");
-    update_sql("UPDATE {feed} SET modified = 0");
-    update_sql("ALTER TABLE {feed} ALTER COLUMN modified SET NOT NULL");
-
-    update_sql("ALTER TABLE {feed} RENAME timestamp TO checked");
-    update_sql("UPDATE {blocks} SET module = 'aggregator' WHERE module = 'import'");
-    update_sql("UPDATE {system} SET filename = 'modules/aggregator.module', name = 'aggregator' WHERE filename = 'modules/import.module'");
-  }
-  else {
-    update_sql("ALTER TABLE {feed} ADD etag varchar(255) NOT NULL DEFAULT ''");
-    update_sql("ALTER TABLE {feed} ADD modified int(10) NOT NULL DEFAULT 0");
-    update_sql("ALTER TABLE {feed} CHANGE timestamp checked int(10) NOT NULL DEFAULT 0");
-    update_sql("UPDATE {blocks} SET module = 'aggregator' WHERE module = 'import'");
-    update_sql("UPDATE {system} SET filename = 'modules/aggregator.module', name = 'aggregator' WHERE filename = 'modules/import.module'");
-  }
-}
-
-function update_76() {
-  if ($GLOBALS["db_type"] == "pgsql") {
-    update_sql("ALTER TABLE {feed} ADD image text");
-  } else {
-    update_sql("ALTER TABLE {feed} ADD image longtext");
-  }
-}
-
-function update_77() {
-  update_sql("ALTER TABLE {cache} ADD headers text");
-}
-
-function update_78() {
-  if ($GLOBALS["db_type"] == "mysql") {
-    update_sql("CREATE TABLE {filters} (
-      module varchar(64) NOT NULL default '',
-      weight tinyint(2) DEFAULT '0' NOT NULL,
-      KEY weight (weight)
-    )");
-  }
-  else {
-    update_sql("CREATE TABLE {filters} (
-      module varchar(64) NOT NULL default '',
-      weight smallint DEFAULT '0' NOT NULL,
-      PRIMARY KEY (weight)
-    )");
-  }
-}
-
-function update_79() {
-  // Works for both mysql and postgresql
-  update_sql("ALTER TABLE {node} DROP attributes");
-  update_sql("ALTER TABLE {comments} DROP link");
-}
-
-/*
-** System functions
-*/
-
-function update_sql($sql) {
-  $edit = $_POST["edit"];
-  print nl2br(htmlentities($sql)) ." ";
-  $result = db_query($sql);
-  if ($result) {
-    print "<div style=\"color: green;\">OK</div>\n";
-    return 1;
-  }
-  else {
-    print "<div style=\"color: red;\">FAILED</div>\n";
-    return 0;
-  }
-}
+include_once "database/updates.inc";
 
 function update_data($start) {
-  global $mysql_updates;
-  $mysql_updates = array_slice($mysql_updates, ($start-- ? $start : 0));
-  foreach ($mysql_updates as $date => $func) {
+  global $sql_updates;
+  $sql_updates = array_slice($sql_updates, ($start-- ? $start : 0));
+  foreach ($sql_updates as $date => $func) {
     print "<strong>$date</strong><br />\n<pre>\n";
-    $func();
+    $ret = $func();
+    foreach ($ret as $return) {
+      print $return[1];
+      print $return[2];
+    }
     variable_set("update_start", $date);
     print "</pre>\n";
   }
@@ -729,7 +55,7 @@ function update_page_footer() {
 }
 
 function update_page() {
-  global $user, $mysql_updates;
+  global $user, $sql_updates;
 
   $edit = $_POST["edit"];
 
@@ -755,7 +81,7 @@ function update_page() {
       $start = variable_get("update_start", 0);
       $dates[] = "All";
       $i = 1;
-      foreach ($mysql_updates as $date => $sql) {
+      foreach ($sql_updates as $date => $sql) {
         $dates[$i++] = $date;
         if ($date == $start) {
           $selected = $i;
-- 
GitLab