=== modified file 'includes/common.inc'
--- includes/common.inc	2008-11-01 21:21:34 +0000
+++ includes/common.inc	2008-11-03 04:57:12 +0000
@@ -614,9 +614,15 @@ function _drupal_error_handler($error_le
       E_STRICT => 'Strict warning',
       E_RECOVERABLE_ERROR => 'Recoverable fatal error'
     );
-    $backtrace = debug_backtrace();
+    $caller = _drupal_get_last_caller(debug_backtrace());
     // We treat recoverable errors as fatal.
-    _drupal_log_error(isset($types[$error_level]) ? $types[$error_level] : 'Unknown error', $message, $backtrace, $error_level == E_RECOVERABLE_ERROR);
+    _drupal_log_error(array(
+      '%type' => isset($types[$error_level]) ? $types[$error_level] : 'Unknown error',
+      '%message' => $message,
+      '%function' => $caller['function'],
+      '%file' => $caller['file'],
+      '%line' => $caller['line'],
+    ), $error_level == E_RECOVERABLE_ERROR);
   }
 }
 
@@ -631,6 +637,18 @@ function _drupal_error_handler($error_le
  *   The exception object that was thrown.
  */
 function _drupal_exception_handler($exception) {
+  // Log the message to the watchdog and return an error page to the user.
+  _drupal_log_error(_drupal_decode_exception($exception), TRUE);
+}
+
+/**
+ * Decode an exception, especially to retrive the correct caller.
+ *
+ * @param $exception
+ *   The exception object that was thrown.
+ * @return An error in the format expected by _drupal_log_error().
+ */
+function _drupal_decode_exception($exception) {
   $backtrace = $exception->getTrace();
   // Add the line throwing the exception to the backtrace.
   array_unshift($backtrace, array('line' => $exception->getLine(), 'file' => $exception->getFile()));
@@ -642,7 +660,7 @@ function _drupal_exception_handler($exce
     // We skip calls that occurred in one of the classes of the database layer
     // or in one of its global functions.
     $db_functions = array('db_query', 'pager_query', 'db_query_range', 'db_query_temporary', 'update_sql');
-    while (($caller = $backtrace[1]) &&
+    while (!empty($backtrace[1]) && ($caller = $backtrace[1]) &&
          ((isset($caller['class']) && (strpos($caller['class'], 'Query') !== FALSE || strpos($caller['class'], 'Database') !== FALSE)) ||
          in_array($caller['function'], $db_functions))) {
       // We remove that call.
@@ -650,44 +668,54 @@ function _drupal_exception_handler($exce
     }
   }
 
-  // Log the message to the watchdog and return an error page to the user.
-  _drupal_log_error(get_class($exception), $exception->getMessage(), $backtrace, TRUE);
+  $caller = _drupal_get_last_caller($backtrace);
+
+  return array(
+    '%type' => get_class($exception),
+    '%message' => $exception->getMessage(),
+    '%function' => $caller['function'],
+    '%file' => $caller['file'],
+    '%line' => $caller['line'],
+  );
 }
 
 /**
  * Log a PHP error or exception, display an error page in fatal cases.
  *
- * @param $type
- *   The type of the error (Error, Warning, ...).
- * @param $message
- *   The message associated to the error.
- * @param $backtrace
- *   The backtrace of function calls that led to this error.
+ * @param $error
+ *   An array with the following keys: %type, %message, %function, %file, %line.
  * @param $fatal
  *   TRUE if the error is fatal.
  */
-function _drupal_log_error($type, $message, $backtrace, $fatal) {
-  $caller = _drupal_get_last_caller($backtrace);
-
+function _drupal_log_error($error, $fatal) {
   // Initialize a maintenance theme early if the boostrap was not complete.
   // Do it early because drupal_set_message() triggers an init_theme().
   if ($fatal && (drupal_get_bootstrap_phase() != DRUPAL_BOOTSTRAP_FULL)) {
     unset($GLOBALS['theme']);
-    define('MAINTENANCE_MODE', 'error');
+    if (!defined('MAINTENANCE_MODE')) {
+      define('MAINTENANCE_MODE', 'error');
+    }
     drupal_maintenance_theme();
   }
 
   // Force display of error messages in update.php.
   if (variable_get('error_level', 1) == 1 || (defined('MAINTENANCE_MODE') && MAINTENANCE_MODE == 'update')) {
-    drupal_set_message(t('@type: %message in %function (line %line of %file).', array('@type' => $type, '%message' => $message, '%function' => $caller['function'], '%line' => $caller['line'], '%file' => $caller['file'])), 'error');
+    drupal_set_message(t('%type: %message in %function (line %line of %file).', $error), 'error');
   }
 
-  watchdog('php', '%type: %message in %function (line %line of %file).', array('%type' => $type, '%message' => $message, '%function' => $caller['function'], '%file' => $caller['file'], '%line' => $caller['line']), WATCHDOG_ERROR);
+  try {
+    watchdog('php', '%type: %message in %function (line %line of %file).', $error, WATCHDOG_ERROR);
+  }
+  catch (Exception $e) {
+    $new_error = _drupal_decode_exception($e);
+    drupal_set_message(t('%type: %message in %function (line %line of %file).', $new_error), 'error');
+  }
 
   if ($fatal) {
     drupal_set_header($_SERVER['SERVER_PROTOCOL'] . ' Service unavailable');
     drupal_set_title(t('Error'));
-    if (drupal_get_bootstrap_phase() == DRUPAL_BOOTSTRAP_FULL) {
+    
+    if (!defined('MAINTENANCE_MODE') && drupal_get_bootstrap_phase() == DRUPAL_BOOTSTRAP_FULL) {
       print theme('page', t('The website encountered an unexpected error. Please try again later.'), FALSE);
     }
     else {

=== modified file 'includes/database/database.inc'
--- includes/database/database.inc	2008-11-01 21:21:34 +0000
+++ includes/database/database.inc	2008-11-03 04:54:26 +0000
@@ -414,9 +414,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;
@@ -892,11 +890,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
@@ -1016,7 +1012,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;
     }
   }
@@ -1851,7 +1847,7 @@ function db_field_set_no_default(&$ret, 
  *   Fields for the primary key.
  */
 function db_add_primary_key(&$ret, $table, $fields) {
-  return Database::getActiveConnection()->schema()->addPrimaryKey($ret, $table, $field);
+  return Database::getActiveConnection()->schema()->addPrimaryKey($ret, $table, $fields);
 }
 
 /**
@@ -1923,7 +1919,7 @@ function db_add_index(&$ret, $table, $na
  *   The name of the index.
  */
 function db_drop_index(&$ret, $table, $name) {
-  return Database::getActiveConnection()->schema()->addIndex($ret, $table, $name);
+  return Database::getActiveConnection()->schema()->dropIndex($ret, $table, $name);
 }
 
 /**
@@ -2032,8 +2028,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');
   }

=== modified file 'includes/database/pgsql/database.inc'
--- includes/database/pgsql/database.inc	2008-10-31 11:24:04 +0000
+++ includes/database/pgsql/database.inc	2008-11-03 04:30:37 +0000
@@ -61,10 +61,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;

=== added directory 'includes/database/sqlite'
=== modified file 'includes/theme.inc'
--- includes/theme.inc	2008-11-02 14:46:57 +0000
+++ includes/theme.inc	2008-11-03 04:39:33 +0000
@@ -898,7 +898,7 @@ function theme_get_settings($key = NULL)
     'toggle_logo'                   =>  1,
     'toggle_favicon'                =>  1,
     'toggle_name'                   =>  1,
-    'toggle_search'                 =>  1,
+    'toggle_search'                 =>  0,
     'toggle_slogan'                 =>  0,
     'toggle_mission'                =>  1,
     'toggle_node_user_picture'      =>  0,
@@ -919,8 +919,8 @@ function theme_get_settings($key = NULL)
   }
 
   // Only offer search box if search.module is enabled.
-  if (!module_exists('search') || !user_access('search content')) {
-    $settings['toggle_search'] = 0;
+  if (!defined('MAINTENANCE_MODE') && module_exists('search') && user_access('search content')) {
+    $settings['toggle_search'] = 1;
   }
 
   return $settings;

=== modified file 'modules/node/node.module'
--- modules/node/node.module	2008-11-02 10:48:31 +0000
+++ modules/node/node.module	2008-11-03 04:30:37 +0000
@@ -594,8 +594,9 @@ function _node_types_build() {
   while ($type_object = db_fetch_object($type_result)) {
     // Check for node types from disabled modules and mark their types for removal.
     // Types defined by the node module in the database (rather than by a separate
-    // module using hook_node_info) have a base value of 'node_content'.
-    if ($type_object->base != 'node_content' && empty($info_array[$type_object->type])) {
+    // module using hook_node_info) have a base value of 'node_content'. The isset()
+    // check prevents errors on old (pre-Drupal 7) databases.
+    if (isset($type_object->base) && $type_object->base != 'node_content' && empty($info_array[$type_object->type])) {
       $type_object->disabled = TRUE;
     }
     if (!isset($_node_types[$type_object->type]) || $type_object->modified) {

=== modified file 'modules/system/system.install'
--- modules/system/system.install	2008-11-02 17:56:20 +0000
+++ modules/system/system.install	2008-11-03 04:54:37 +0000
@@ -2955,7 +2955,7 @@ function system_update_7006() {
       'type'   => array('type' => 'varchar', 'length' => 9, 'not null' => TRUE, 'default' => ''),
       'filename'   => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''),
       'module'   => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''),
-      'suffix'   => array('type' => 'varchar', 'length' => 69, 'not null' => TRUE, 'default' => ''),
+      'suffix'   => array('type' => 'varchar', 'length' => 68, 'not null' => TRUE, 'default' => ''),
       'weight'   => array('type' => 'int', 'not null' => TRUE, 'default' => 0),
     ),
     'primary key' => array('name', 'type'),
@@ -3071,8 +3071,8 @@ function system_update_7009() {
  */
 function system_update_7010() {
   $ret = array();
-  db_change_field($ret, 'menu_router', 'load_functions', 'load_functions', array('type' => 'text', 'not null' => TRUE, 'default' => ''));
-  db_change_field($ret, 'menu_router', 'to_arg_functions', 'to_arg_functions', array('type' => 'text', 'not null' => TRUE, 'default' => '',));
+  db_change_field($ret, 'menu_router', 'load_functions', 'load_functions', array('type' => 'text', 'not null' => TRUE));
+  db_change_field($ret, 'menu_router', 'to_arg_functions', 'to_arg_functions', array('type' => 'text', 'not null' => TRUE));
 
   return $ret;
 }
@@ -3107,10 +3107,11 @@ function system_update_7012() {
   $ret = array();
   db_drop_unique_key($ret, 'search_dataset', 'sid_type');
   db_add_primary_key($ret, 'search_dataset', array('sid', 'type'));
-  
+
   db_drop_index($ret, 'search_index', 'word');
   db_drop_unique_key($ret, 'search_index', 'word_sid_type');
   db_add_primary_key($ret, 'search_index', array('word', 'sid', 'type'));
+
   return $ret;
 }
 

=== modified file 'update.php'
--- update.php	2008-10-24 18:47:02 +0000
+++ update.php	2008-11-03 04:55:13 +0000
@@ -330,7 +330,7 @@ function update_finished($success, $resu
   $_SESSION['update_results'] = $results;
   $_SESSION['update_success'] = $success;
   $_SESSION['updates_remaining'] = $operations;
-  
+
   // Now that the update is done, we can disable site maintenance if it was
   // previously turned off.
   if (isset($_SESSION['site_offline']) && $_SESSION['site_offline'] == FALSE) {
@@ -574,6 +574,37 @@ 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();
+  spl_autoload_unregister('drupal_autoload_class');
+  spl_autoload_unregister('drupal_autoload_interface');
+  // 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) {
@@ -655,13 +686,10 @@ if (empty($op)) {
   install_goto('update.php?op=info');
 }
 
+update_prepare_d7_bootstrap();
 drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
 drupal_maintenance_theme();
 
-// This must happen *after* drupal_bootstrap(), since it calls
-// variable_(get|set), which only works after a full bootstrap.
-update_create_batch_table();
-
 // 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);

