Initial refactoring for Postgres; DatabaseUpdater subclass is now passed to LoadExten...
authorChad Horohoe <demon@users.mediawiki.org>
Sun, 15 Aug 2010 18:55:08 +0000 (18:55 +0000)
committerChad Horohoe <demon@users.mediawiki.org>
Sun, 15 Aug 2010 18:55:08 +0000 (18:55 +0000)
docs/hooks.txt
includes/AutoLoader.php
includes/installer/CoreInstaller.php
includes/installer/DatabaseUpdater.php
includes/installer/Installer.php
includes/installer/PostgresUpdater.php [new file with mode: 0644]
maintenance/updaters.inc

index 9a297de..b0ae26f 100644 (file)
@@ -1031,8 +1031,8 @@ completed
 'ListDefinedTags': When trying to find all defined tags.
 &$tags: The list of tags.
 
-'LoadExtensionSchemaUpdates': called by maintenance/updaters.inc when upgrading
-database schema
+'LoadExtensionSchemaUpdates': called during database installation and updates
+&updater: A DatabaseUpdater subclass
 
 'LocalFile::getHistory': called before file history query performed
 $file: the file
index cc06c99..d864253 100644 (file)
@@ -437,6 +437,7 @@ $wgAutoloadLocalClasses = array(
        'MysqlInstaller' => 'includes/installer/MysqlInstaller.php',
        'MysqlUpdater' => 'includes/installer/MysqlUpdater.php',
        'PostgresInstaller' => 'includes/installer/PostgresInstaller.php',
+       'PostgresUpdater' => 'includes/installer/PostgresUpdater.php',
        'SqliteInstaller' => 'includes/installer/SqliteInstaller.php',
        'SqliteUpdater' => 'includes/installer/SqliteUpdater.php',
        'OracleInstaller' => 'includes/installer/OracleInstaller.php',
index c3c8e36..f44f602 100644 (file)
@@ -200,7 +200,7 @@ abstract class CoreInstaller extends Installer {
                        $this->settings[$var] = $GLOBALS[$var];
                }
 
-               foreach ( $this->dbTypes as $type ) {
+               foreach ( self::getDBTypes() as $type ) {
                        $installer = $this->getDBInstaller( $type );
 
                        if ( !$installer->isCompiled() ) {
index a85be12..7f4c752 100644 (file)
@@ -26,17 +26,17 @@ abstract class DatabaseUpdater {
        }
 
        public static function newForDB( $db, $shared ) {
-               switch( $db->getType() ) {
-                       case 'mysql':
-                       case 'sqlite':
-                       case 'oracle':
-                               $class = ucfirst( $db->getType() ) . 'Updater';
-                               return new $class( $db, $shared );
-                       default:
-                               throw new MWException( __METHOD__ . ' called for unsupported $wgDBtype' );
+               $type = $db->getType();
+               if( in_array( $type, Installer::getDBTypes() ) ) {
+                       $class = ucfirst( $type ) . 'Updater';
+                       return new $class( $db, $shared );
+               } else {
+                       throw new MWException( __METHOD__ . ' called for unsupported $wgDBtype' );
                }
        }
 
+       public function getDB() { return $this->db; }
+
        public function doUpdates() {
                global $IP, $wgVersion;
                require_once( "$IP/maintenance/updaters.inc" );
index 6f63ecc..e401f57 100644 (file)
@@ -61,7 +61,7 @@ abstract class Installer {
         *
         * @var array
         */
-       protected $dbTypes = array(
+       protected static $dbTypes = array(
                'mysql',
                'postgres',
                'sqlite',
@@ -118,8 +118,8 @@ abstract class Installer {
        /**
         * Get a list of known DB types.
         */
-       public function getDBTypes() {
-               return $this->dbTypes;
+       public static function getDBTypes() {
+               return self::$dbTypes;
        }
 
        /**
@@ -416,7 +416,7 @@ abstract class Installer {
                $goodNames = array();
                $allNames = array();
 
-               foreach ( $this->dbTypes as $name ) {
+               foreach ( self::getDBTypes() as $name ) {
                        $db = $this->getDBInstaller( $name );
                        $readableName = wfMsg( 'config-type-' . $name );
 
diff --git a/includes/installer/PostgresUpdater.php b/includes/installer/PostgresUpdater.php
new file mode 100644 (file)
index 0000000..c7dd166
--- /dev/null
@@ -0,0 +1,23 @@
+<?php
+
+/**
+ * Class for handling updates to Postgres databases.
+ *
+ * @TODO @FIXME - Postgres should use sequential updates like Mysql, Sqlite
+ * and everybody else. It never got refactored like it should've. For now,
+ * just wrap the old do_postgres_updates() in this class so we can clean up
+ * the higher-level stuff.
+ *
+ * @ingroup Deployment
+ * @since 1.17
+ */
+
+class PostgresUpdater extends Updater {
+       protected function getCoreUpdateList() {
+               return array();
+       }
+
+       public function doUpdates() {
+               do_postgres_updates();
+       }
+}
index ff94e6d..dc61a6b 100644 (file)
@@ -934,16 +934,16 @@ function purge_cache() {
 function do_all_updates( $shared = false, $purge = true ) {
        global $wgSharedDB, $wgSharedTables, $wgDatabase, $wgDBtype;
 
-       wfRunHooks( 'LoadExtensionSchemaUpdates' );
+       $updater = DatabaseUpdater::newForDb( $wgDatabase, $shared );
+
+       wfRunHooks( 'LoadExtensionSchemaUpdates', array( &$updater ) );
+
+       $updater->doUpdates();
 
        if ( $wgDBtype === 'postgres' ) {
-               do_postgres_updates();
                return;
        }
 
-       $up = DatabaseUpdater::newForDb( $wgDatabase, $shared );
-       $up->doUpdates();
-
        wfOut( "Deleting old default messages (this may take a long time!)..." );
        if ( !defined( 'MW_NO_SETUP' ) ) {
                define( 'MW_NO_SETUP', true );