? includes/.install.core.inc.swp
? includes/.install.inc.swp
? includes/.update.inc.swp
? includes/database/pgsql/.install.inc.swp
? sites/all/modules
? sites/all/themes
? sites/default/files
? sites/default/settings.php
? sites/default/settings.php-mysql
? sites/default/settings.php-pgsql
Index: update.php
===================================================================
RCS file: /cvs/drupal/drupal/update.php,v
retrieving revision 1.327
diff -u -p -r1.327 update.php
--- update.php	28 Dec 2010 18:31:16 -0000	1.327
+++ update.php	30 Dec 2010 11:01:24 -0000
@@ -309,6 +309,7 @@ function update_extra_requirements($requ
 function update_check_requirements() {
   // Check requirements of all loaded modules.
   $requirements = module_invoke_all('requirements', 'update');
+  $requirements += update_database_requirements();
   $requirements += update_extra_requirements();
   $severity = drupal_requirements_severity($requirements);
 
Index: includes/install.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/install.inc,v
retrieving revision 1.151
diff -u -p -r1.151 install.inc
--- includes/install.inc	28 Dec 2010 18:17:27 -0000	1.151
+++ includes/install.inc	30 Dec 2010 11:01:31 -0000
@@ -406,6 +406,7 @@ abstract class DatabaseTasks {
           throw new DatabaseTaskException(st("Failed to run all tasks against the database server. The task %task wasn't found.", array('%task' => $task['function'])));
         }
       }
+      $this->runDriverUpdates();
     }
     // Check for failed results and compile message
     $message = '';
@@ -421,6 +422,107 @@ abstract class DatabaseTasks {
   }
 
   /**
+   * Run the driver updates that have not been run before.
+   */
+  private function runDriverUpdates() {
+    // First create the metadata table if necessary
+    $this->initializeDriverMetadata();
+    $old_schema_version = $this->getDriverMetadata('version');
+    if ($old_schema_version === NULL) {
+      $old_schema_version = -1;
+    }
+    $available_updates = $this->getAvailableUpdates();
+    $current_schema_version = $old_schema_version;
+    foreach ($available_updates as $schema => $function) {
+      if ($schema > $old_schema_version) {
+        $result = $this->$function();
+        if ($result === FALSE) {
+          // If the function returns FALSE, don't process any further updates.
+          break;
+        }
+        $current_schema_version = $schema;
+      }
+    }
+    if ($current_schema_version != $old_schema_version) {
+      $this->setDriverMetadata('version', $current_schema_version);
+    }
+  }
+
+  /**
+   * Initialize the driver metadata storage.
+   *
+   * This function needs to be idempotent (running it multiple times
+   * yields the same result as running it once).
+   */
+  protected function initializeDriverMetadata() {
+    if (! db_table_exists('_db_metadata')) {
+      $metaschema = array(
+        'description' => 'This table contains metadata for the database driver',
+        'fields' => array(
+          'name' => array(
+            'description' => 'Metadata property name',
+            'type' => 'varchar',
+            'length' => 255,
+          ),
+          'data' => array(
+            'description' => 'The serialized metadata property value',
+            'type' => 'blob',
+            'serialize' => TRUE,
+          ),
+        ),
+        'primary key' => array('name'),
+      );
+      db_create_table('_db_metadata', $metaschema);
+    }
+  }
+
+  /**
+   * Return metadata stored for the database driver.
+   */
+  protected function getDriverMetadata($name) {
+    $data = db_query("SELECT data FROM {_db_metadata} WHERE name = :name", array(':name' => $name))->fetchField();
+    if (! $data) {
+      return NULL;
+    }
+    return unserialize($data);
+  }
+
+  protected function setDriverMetadata($name, $data) {
+    db_merge('_db_metadata')
+      ->key(array(
+        'name' => $name,
+      ))
+      ->fields(array(
+        'data' => serialize($data)
+      ))
+      ->execute();
+  }
+
+  /**
+   * Returns the available driver updates
+   *
+   * @return
+   *   An array of the available update functions. The array is keyed by the
+   *   update number.
+   */
+  private function getAvailableUpdates() {
+    $updates = array();
+    $methods = get_class_methods($this);
+    $regexp = '/^updateDriver(?P<version>\d+)$/';
+    // Narrow this down to functions ending with an integer, since all
+    // updateDriverN() functions end this way.
+    foreach (preg_grep('/\d+$/', $methods) as $method) {
+      // If this function is a driver update function, add it to the list of
+      // driver updates.
+      if (preg_match($regexp, $method, $matches)) {
+        $updates[$matches['version']] = $method;
+      }
+    }
+    ksort($updates);
+    return $updates;
+  }
+
+  /**
    * Check if we can connect to the database.
    */
   protected function connect() {
Index: includes/update.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/update.inc,v
retrieving revision 1.85
diff -u -p -r1.85 update.inc
--- includes/update.inc	29 Dec 2010 03:46:39 -0000	1.85
+++ includes/update.inc	30 Dec 2010 11:01:37 -0000
@@ -156,19 +156,7 @@ function update_prepare_d7_bootstrap() {
       ),
     );
 
-    // Make sure that the database environment is properly set up.
-    try {
-      db_run_tasks(db_driver());
-    }
-    catch (DatabaseTaskException $e) {
-      $requirements['database tasks'] = array(
-        'title' => 'Database environment',
-        'value' => 'There is a problem with your database environment',
-        'severity' => REQUIREMENT_ERROR,
-        'description' => $e->getMessage(),
-      );
-    }
-
+    $requirements += update_database_requirements();
     update_extra_requirements($requirements);
 
     // Allow a D6 session to work, since the upgrade has not been performed yet.
@@ -304,6 +292,24 @@ function update_prepare_d7_bootstrap() {
     $GLOBALS['conf']['date_default_timezone'] = 'UTC';
   }
 }
+/**
+ * Make sure that the database environment is properly set up.
+ */
+function update_database_requirements() {
+  $requirements = array();
+  try {
+    db_run_tasks(db_driver());
+  }
+  catch (DatabaseTaskException $e) {
+    $requirements['database tasks'] = array(
+      'title' => 'Database environment',
+      'value' => 'An error occured while updating the database driver.',
+      'severity' => REQUIREMENT_ERROR,
+      'description' => $e->getMessage(),
+    );
+  }
+  return $requirements;
+}
 
 /**
  * A helper function that modules can use to assist with the transformation
Index: includes/database/pgsql/install.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/database/pgsql/install.inc,v
retrieving revision 1.14
diff -u -p -r1.14 install.inc
--- includes/database/pgsql/install.inc	21 Dec 2010 21:20:04 -0000	1.14
+++ includes/database/pgsql/install.inc	30 Dec 2010 11:01:38 -0000
@@ -25,10 +25,6 @@ class DatabaseTasks_pgsql extends Databa
       'function' => 'checkBinaryOutput',
       'arguments' => array(),
     );
-    $this->tasks[] = array(
-      'function' => 'initializeDatabase',
-      'arguments' => array(),
-    );
   }
 
   public function name() {
@@ -137,7 +133,7 @@ class DatabaseTasks_pgsql extends Databa
   /**
    * Make PostgreSQL Drupal friendly.
    */
-  function initializeDatabase() {
+  public function updateDriver7001() {
     // We create some functions using global names instead of prefixing them
     // like we do with table names. This is so that we don't double up if more
     // than one instance of Drupal is running on a single database. We therefore
@@ -192,6 +188,7 @@ class DatabaseTasks_pgsql extends Databa
     }
     catch (Exception $e) {
       $this->fail(st('Drupal could not be correctly setup with the existing database. Revise any errors.'));
+      return FALSE;
     }
   }
 }
