Index: update.php
===================================================================
RCS file: /cvs/drupal/drupal/update.php,v
retrieving revision 1.263
diff -u -p -r1.263 update.php
--- update.php	12 Oct 2008 04:30:05 -0000	1.263
+++ update.php	15 Oct 2008 05:21:16 -0000
@@ -573,6 +573,35 @@ function update_fix_d6_requirements() {
 }
 
 /**
+ * Users who still have a Drupal 6 database (and are in the process of
+ * updating to Drupal 7) need extra help before a full bootstrap can be
+ * achieved. This function does the necessary preliminary work that allows
+ * the bootstrap to be successful.
+ *
+ * No access check has been performed when this function is called, so no
+ * changes to the database should be made here.
+ */
+function update_prepare_d7_bootstrap() {
+  // Allow the database system to work even though the registry has not
+  // been created yet.
+  drupal_bootstrap(DRUPAL_BOOTSTRAP_DATABASE);
+  include_once DRUPAL_ROOT . '/includes/install.inc';
+  drupal_install_init_database();
+  // The new {blocked_ips} table is used in Drupal 7 to store a list of
+  // banned IP addresses. If this table doesn't exist then we are still
+  // running on a Drupal 6 database, so suppress the unavoidable errors
+  // that occur.
+  try {
+    drupal_bootstrap(DRUPAL_BOOTSTRAP_ACCESS);
+  }
+  catch (Exception $e) {
+    if (db_table_exists('blocked_ips')) {
+      throw $e;
+    }
+  }
+}
+
+/**
  * Add the update task list to the current page.
  */
 function update_task_list($active = NULL) {
@@ -654,6 +683,7 @@ if (empty($op)) {
   install_goto('update.php?op=info');
 }
 
+update_prepare_d7_bootstrap();
 drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
 drupal_maintenance_theme();
 
Index: includes/database/database.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/database/database.inc,v
retrieving revision 1.12
diff -u -p -r1.12 database.inc
--- includes/database/database.inc	8 Oct 2008 11:21:37 -0000	1.12
+++ includes/database/database.inc	15 Oct 2008 05:21:17 -0000
@@ -352,9 +352,7 @@ abstract class DatabaseConnection extend
       }
     }
     catch (PDOException $e) {
-      if (!function_exists('module_implements')) {
-        _db_need_install();
-      }
+      _db_check_install_needed();
       if ($options['throw_exception']) {
         if ($query instanceof DatabaseStatement) {
           $query_string = $stmt->queryString;
@@ -750,11 +748,9 @@ abstract class Database {
   final protected static function parseConnectionInfo() {
     global $databases;
 
-    if (empty($databases)) {
-      _db_need_install();
-    }
-    $databaseInfo = $databases;
+    _db_check_install_needed();
 
+    $databaseInfo = $databases;
     foreach ($databaseInfo as $index => $info) {
       foreach ($databaseInfo[$index] as $target => $value) {
         // If there is no "driver" property, then we assume it's an array of
@@ -861,7 +857,7 @@ abstract class Database {
       // It is extremely rare that an exception will be generated here other
       // than when installing.  We therefore intercept it and try the installer,
       // passing on the exception otherwise.
-      _db_need_install();
+      _db_check_install_needed();
       throw $e;
     }
   }
@@ -1849,8 +1845,14 @@ function db_result(DatabaseStatement $st
   return $statement->fetchField();
 }
 
-function _db_need_install() {
-  if (!function_exists('install_goto')) {
+/**
+ * Redirect the user to the installation script if Drupal has not been
+ * installed yet (i.e., if no $databases array has been defined in the
+ * settings file) and we are not already there. Otherwise, do nothing.
+ */
+function _db_check_install_needed() {
+  global $databases;
+  if (empty($databases) && !function_exists('install_main')) {
     include_once DRUPAL_ROOT . '/includes/install.inc';
     install_goto('install.php');
   }
Index: includes/database/pgsql/database.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/database/pgsql/database.inc,v
retrieving revision 1.3
diff -u -p -r1.3 database.inc
--- includes/database/pgsql/database.inc	15 Sep 2008 20:48:07 -0000	1.3
+++ includes/database/pgsql/database.inc	15 Oct 2008 05:21:17 -0000
@@ -58,10 +58,7 @@ class DatabaseConnection_pgsql extends D
       }
     }
     catch (PDOException $e) {
-      if (!function_exists('module_implements')) {
-        _db_need_install();
-      }
-      //watchdog('database', var_export($e, TRUE) . $e->getMessage(), NULL, WATCHDOG_ERROR);
+      _db_check_install_needed();
       if ($options['throw_exception']) {
         if ($query instanceof DatabaseStatement) {
           $query_string = $stmt->queryString;
