From f08c6b1df948262b0d5d863ce881ab02ca0c875f Mon Sep 17 00:00:00 2001 From: Chad Horohoe Date: Sun, 15 Aug 2010 18:55:08 +0000 Subject: [PATCH] Initial refactoring for Postgres; DatabaseUpdater subclass is now passed to LoadExtensionSchemaUpdates --- docs/hooks.txt | 4 ++-- includes/AutoLoader.php | 1 + includes/installer/CoreInstaller.php | 2 +- includes/installer/DatabaseUpdater.php | 16 ++++++++-------- includes/installer/Installer.php | 8 ++++---- includes/installer/PostgresUpdater.php | 23 +++++++++++++++++++++++ maintenance/updaters.inc | 10 +++++----- 7 files changed, 44 insertions(+), 20 deletions(-) create mode 100644 includes/installer/PostgresUpdater.php diff --git a/docs/hooks.txt b/docs/hooks.txt index 9a297de631..b0ae26ff2d 100644 --- a/docs/hooks.txt +++ b/docs/hooks.txt @@ -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 diff --git a/includes/AutoLoader.php b/includes/AutoLoader.php index cc06c99c41..d864253dcb 100644 --- a/includes/AutoLoader.php +++ b/includes/AutoLoader.php @@ -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', diff --git a/includes/installer/CoreInstaller.php b/includes/installer/CoreInstaller.php index c3c8e36560..f44f602c27 100644 --- a/includes/installer/CoreInstaller.php +++ b/includes/installer/CoreInstaller.php @@ -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() ) { diff --git a/includes/installer/DatabaseUpdater.php b/includes/installer/DatabaseUpdater.php index a85be1299f..7f4c75215d 100644 --- a/includes/installer/DatabaseUpdater.php +++ b/includes/installer/DatabaseUpdater.php @@ -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" ); diff --git a/includes/installer/Installer.php b/includes/installer/Installer.php index 6f63ecc040..e401f57dda 100644 --- a/includes/installer/Installer.php +++ b/includes/installer/Installer.php @@ -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 index 0000000000..c7dd166181 --- /dev/null +++ b/includes/installer/PostgresUpdater.php @@ -0,0 +1,23 @@ +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 ); -- 2.20.1