From: Chad Horohoe Date: Wed, 7 Jul 2010 13:52:05 +0000 (+0000) Subject: Partial revert r69128: go back to making isCompiled() an instance method rather than... X-Git-Tag: 1.31.0-rc.0~36224 X-Git-Url: http://git.cyclocoop.org/%7B%7B%20url_for%28%27admin_vote_add%27%29%20%7D%7D?a=commitdiff_plain;h=67281454eb7e02f895a8566a47b41478140bb647;p=lhc%2Fweb%2Fwiklou.git Partial revert r69128: go back to making isCompiled() an instance method rather than static. Moved $installSteps tweaking to new preInstall() method rather than piling more hacks into the constructor. Also pass InstallerDBType to install steps, reduce some code duplication --- diff --git a/includes/installer/Installer.php b/includes/installer/Installer.php index 7c44ddbb8e..9ec3c42ba4 100644 --- a/includes/installer/Installer.php +++ b/includes/installer/Installer.php @@ -235,7 +235,7 @@ abstract class Installer { } foreach ( $this->dbTypes as $type ) { $installer = $this->getDBInstaller( $type ); - if ( !$installer ) { + if ( !$installer->isCompiled() ) { continue; } $defaults = $installer->getGlobalDefaults(); @@ -282,11 +282,7 @@ abstract class Installer { if ( !isset( $this->dbInstallers[$type] ) ) { $class = ucfirst( $type ). 'Installer'; - if ( call_user_func( array( $class, 'isCompiled' ) ) ) { - $this->dbInstallers[$type] = new $class( $this ); - } else { - $this->dbInstallers[$type] = false; - } + $this->dbInstallers[$type] = new $class( $this ); } return $this->dbInstallers[$type]; } @@ -867,6 +863,7 @@ abstract class Installer { */ public function performInstallation( $startCB, $endCB ) { $installResults = array(); + $installer = $this->getDBInstaller(); foreach( $this->getInstallSteps() as $stepObj ) { $step = is_array( $stepObj ) ? $stepObj['name'] : $stepObj; call_user_func_array( $startCB, array( $step ) ); @@ -880,7 +877,7 @@ abstract class Installer { } else { # Boring implicitly named callback $func = 'install' . ucfirst( $step ); - $status = $this->{$func}(); + $status = $this->{$func}( $installer ); } call_user_func_array( $endCB, array( $step, $status ) ); $installResults[$step] = $status; @@ -903,10 +900,9 @@ abstract class Installer { return Status::newGood(); } - public function installDatabase() { - $type = $this->getVar( 'wgDBtype' ); - $installer = $this->getDBInstaller( $type ); + public function installDatabase( &$installer ) { if(!$installer) { + $type = $this->getVar( 'wgDBtype' ); $status = Status::newFatal( "config-no-db", $type ); } else { $status = $installer->setupDatabase(); @@ -914,8 +910,7 @@ abstract class Installer { return $status; } - public function installTables() { - $installer = $this->getDBInstaller(); + public function installTables( &$installer ) { $status = $installer->createTables(); if( $status->isOK() ) { LBFactory::enableBackend(); @@ -923,8 +918,7 @@ abstract class Installer { return $status; } - public function installInterwiki() { - $installer = $this->getDBInstaller(); + public function installInterwiki( &$installer ) { return $installer->populateInterwikiTable(); } diff --git a/includes/installer/InstallerDBType.php b/includes/installer/InstallerDBType.php index a37110e795..008161280d 100644 --- a/includes/installer/InstallerDBType.php +++ b/includes/installer/InstallerDBType.php @@ -24,7 +24,7 @@ abstract class InstallerDBType { /** * @return true if the client library is compiled in */ - abstract static function isCompiled(); + abstract public function isCompiled(); /** * Get an array of MW configuration globals that will be configured by this class. @@ -77,6 +77,13 @@ abstract class InstallerDBType { */ abstract function getConnection(); + /** + * Allow DB installers a chance to make last-minute changes before installation + * occurs. This happens before setupDatabase() or createTables() is called, but + * long after the constructor. Helpful for things like modifying setup steps :) + */ + public function preInstall() {} + /** * Create the database and return a Status object indicating success or * failure. @@ -126,7 +133,7 @@ abstract class InstallerDBType { * Convenience function * Check if a named extension is present */ - static function checkExtension( $name ) { + protected static function checkExtension( $name ) { wfSuppressWarnings(); $compiled = wfDl( $name ); wfRestoreWarnings(); diff --git a/includes/installer/MysqlInstaller.php b/includes/installer/MysqlInstaller.php index 348e71624d..e1c67064ba 100644 --- a/includes/installer/MysqlInstaller.php +++ b/includes/installer/MysqlInstaller.php @@ -34,22 +34,9 @@ class MysqlInstaller extends InstallerDBType { function __construct( $parent ) { parent::__construct( $parent ); - - if ( $this->parent->getVar( 'wgDBtype' ) !== $this->getName() ) { - return; - } - - # Add our user callback to installSteps, right before the tables are created. - $callback = array( - array( - 'name' => 'user', - 'callback' => array( &$this, 'setupUser' ), - ) - ); - $this->parent->addInstallStepFollowing( "tables", $callback ); } - static function isCompiled() { + public function isCompiled() { return self::checkExtension( 'mysql' ); } @@ -379,6 +366,17 @@ class MysqlInstaller extends InstallerDBType { return Status::newGood(); } + public function preInstall() { + # Add our user callback to installSteps, right before the tables are created. + $callback = array( + array( + 'name' => 'user', + 'callback' => array( &$this, 'setupUser' ), + ) + ); + $this->parent->addInstallStepFollowing( "tables", $callback ); + } + function setupDatabase() { $status = $this->getConnection(); if ( !$status->isOK() ) { diff --git a/includes/installer/OracleInstaller.php b/includes/installer/OracleInstaller.php index a6cc135765..ba3a5ca4d6 100644 --- a/includes/installer/OracleInstaller.php +++ b/includes/installer/OracleInstaller.php @@ -19,7 +19,7 @@ class OracleInstaller extends InstallerDBType { return 'oracle'; } - static function isCompiled() { + public function isCompiled() { return self::checkExtension( 'oci8' ); } diff --git a/includes/installer/PostgresInstaller.php b/includes/installer/PostgresInstaller.php index 65d4116afc..859e3fb482 100644 --- a/includes/installer/PostgresInstaller.php +++ b/includes/installer/PostgresInstaller.php @@ -25,7 +25,7 @@ class PostgresInstaller extends InstallerDBType { return 'postgres'; } - static function isCompiled() { + public function isCompiled() { return self::checkExtension( 'pgsql' ); } diff --git a/includes/installer/SqliteInstaller.php b/includes/installer/SqliteInstaller.php index 86c5a16e21..9edc7e1fe0 100644 --- a/includes/installer/SqliteInstaller.php +++ b/includes/installer/SqliteInstaller.php @@ -10,7 +10,7 @@ class SqliteInstaller extends InstallerDBType { return 'sqlite'; } - static function isCompiled() { + public function isCompiled() { return self::checkExtension( 'pdo_sqlite' ); }