From: Chad Horohoe Date: Wed, 22 Dec 2010 05:21:22 +0000 (+0000) Subject: Rewrite install steps again (cleanup r76390) X-Git-Tag: 1.31.0-rc.0~33201 X-Git-Url: http://git.cyclocoop.org/url?a=commitdiff_plain;h=a8dc1fe6a985b5eac06060012a21ef22fbfc1b91;p=lhc%2Fweb%2Fwiklou.git Rewrite install steps again (cleanup r76390) * No longer iterating and modifying the same array * Allows multiple attachments to the same step * Database -> DatabaseMysql --- diff --git a/includes/installer/CoreInstaller.php b/includes/installer/CoreInstaller.php index 10056f5539..e4cd4518c5 100644 --- a/includes/installer/CoreInstaller.php +++ b/includes/installer/CoreInstaller.php @@ -88,6 +88,13 @@ abstract class CoreInstaller extends Installer { '_ExistingDBSettings' => false, ); + /** + * The actual list of installation steps. This will be initialized by getInstallSteps() + * + * @var array + */ + private $installSteps = array(); + /** * Extra steps for installation, for things like DatabaseInstallers to modify * @@ -296,37 +303,63 @@ abstract class CoreInstaller extends Installer { } /** - * Get an array of install steps. These could be a plain key like the defaults - * in $installSteps, or could be an array with a name and a specific callback - * There must be a config-install-$step message defined per step, which will + * Get an array of install steps. Should always be in the format of + * array( + * 'name' => 'someuniquename', + * 'callback' => array( $obj, 'method' ), + * ) + * There must be a config-install-$name message defined per step, which will * be shown on install. * * @param $installer DatabaseInstaller so we can make callbacks * @return array */ protected function getInstallSteps( DatabaseInstaller &$installer ) { - $installSteps = array( - array( 'name' => 'database', 'callback' => array( $installer, 'setupDatabase' ) ), - array( 'name' => 'tables', 'callback' => array( $this, 'installTables' ) ), - array( 'name' => 'interwiki', 'callback' => array( $installer, 'populateInterwikiTable' ) ), - array( 'name' => 'secretkey', 'callback' => array( $this, 'generateSecretKey' ) ), + $coreInstallSteps = array( + array( 'name' => 'database', 'callback' => array( $installer, 'setupDatabase' ) ), + array( 'name' => 'tables', 'callback' => array( $this, 'installTables' ) ), + array( 'name' => 'interwiki', 'callback' => array( $installer, 'populateInterwikiTable' ) ), + array( 'name' => 'secretkey', 'callback' => array( $this, 'generateSecretKey' ) ), array( 'name' => 'upgradekey', 'callback' => array( $this, 'generateUpgradeKey' ) ), - array( 'name' => 'sysop', 'callback' => array( $this, 'createSysop' ) ), - array( 'name' => 'mainpage', 'callback' => array( $this, 'createMainpage' ) ), + array( 'name' => 'sysop', 'callback' => array( $this, 'createSysop' ) ), + array( 'name' => 'mainpage', 'callback' => array( $this, 'createMainpage' ) ), ); if( count( $this->getVar( '_Extensions' ) ) ) { - array_unshift( $installSteps, + array_unshift( $coreInstallSteps, array( 'name' => 'extensions', 'callback' => array( $this, 'includeExtensions' ) ) ); } - foreach( $installSteps as $idx => $stepObj ) { - if( isset( $this->extraInstallSteps[ $stepObj['name'] ] ) ) { - $tmp = array_slice( $installSteps, 0, $idx ); - $tmp[] = $this->extraInstallSteps[ $stepObj['name'] ]; - $installSteps = array_merge( $tmp, array_slice( $installSteps, $idx ) ); + $this->installSteps = $coreInstallSteps; + foreach( $this->extraInstallSteps as $step ) { + // Put the step at the beginning + if( !strval( $step['position' ] ) ) { + array_unshift( $installSteps, $step['callback'] ); + continue; + } else { + // Walk the $coreInstallSteps array to see if we can modify + // $this->installSteps with a callback that wants to attach after + // a given step + array_walk( + $coreInstallSteps, + array( $this, 'installStepCallback' ), + $step + ); } } - return $installSteps; + return $this->installSteps; + } + + /** + * Callback for getInstallSteps() - used for finding if a given $insertableStep + * should be inserted after the current $coreStep in question + */ + private function installStepCallback( $coreStep, $key, $insertableStep ) { + if( $coreStep['name'] == $insertableStep['position'] ) { + $front = array_slice( $this->installSteps, 0, $key + 1 ); + $front[] = $insertableStep['callback']; + $back = array_slice( $this->installSteps, $key + 1 ); + $this->installSteps = array_merge( $front, $back ); + } } /** @@ -506,10 +539,12 @@ abstract class CoreInstaller extends Installer { /** * Add an installation step following the given step. * - * @param $findStep String the step to find. Use NULL to put the step at the beginning. - * @param $callback array A valid callback array, with name and callback given + * @param $callback Array A valid callback array, with name and callback given + * @param $findStep String the step to find. Omit to put the step at the beginning */ - public function addInstallStepFollowing( $findStep, $callback ) { - $this->extraInstallSteps[$findStep] = $callback; + public function addInstallStep( $callback, $findStep = '' ) { + $this->extraInstallSteps[] = array( + 'position' => $findStep, 'callback' => $callback + ); } } diff --git a/includes/installer/MysqlInstaller.php b/includes/installer/MysqlInstaller.php index 91b4ef5d95..5f963a2a75 100644 --- a/includes/installer/MysqlInstaller.php +++ b/includes/installer/MysqlInstaller.php @@ -366,7 +366,7 @@ class MysqlInstaller extends DatabaseInstaller { if ( !$create ) { // Test the web account try { - new Database( + new DatabaseMysql( $this->getVar( 'wgDBserver' ), $this->getVar( 'wgDBuser' ), $this->getVar( 'wgDBpassword' ), @@ -399,7 +399,7 @@ class MysqlInstaller extends DatabaseInstaller { 'name' => 'user', 'callback' => array( $this, 'setupUser' ), ); - $this->parent->addInstallStepFollowing( "tables", $callback ); + $this->parent->addInstallStep( $callback, 'tables' ); } public function setupDatabase() {