r78774 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r78773‎ | r78774 | r78775 >
Date:05:21, 22 December 2010
Author:demon
Status:ok (Comments)
Tags:
Comment:
Rewrite install steps again (cleanup r76390)
* No longer iterating and modifying the same array
* Allows multiple attachments to the same step
* Database -> DatabaseMysql
Modified paths:
  • /trunk/phase3/includes/installer/CoreInstaller.php (modified) (history)
  • /trunk/phase3/includes/installer/MysqlInstaller.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/installer/CoreInstaller.php
@@ -89,6 +89,13 @@
9090 );
9191
9292 /**
 93+ * The actual list of installation steps. This will be initialized by getInstallSteps()
 94+ *
 95+ * @var array
 96+ */
 97+ private $installSteps = array();
 98+
 99+ /**
93100 * Extra steps for installation, for things like DatabaseInstallers to modify
94101 *
95102 * @var array
@@ -296,40 +303,66 @@
297304 }
298305
299306 /**
300 - * Get an array of install steps. These could be a plain key like the defaults
301 - * in $installSteps, or could be an array with a name and a specific callback
302 - * There must be a config-install-$step message defined per step, which will
 307+ * Get an array of install steps. Should always be in the format of
 308+ * array(
 309+ * 'name' => 'someuniquename',
 310+ * 'callback' => array( $obj, 'method' ),
 311+ * )
 312+ * There must be a config-install-$name message defined per step, which will
303313 * be shown on install.
304314 *
305315 * @param $installer DatabaseInstaller so we can make callbacks
306316 * @return array
307317 */
308318 protected function getInstallSteps( DatabaseInstaller &$installer ) {
309 - $installSteps = array(
310 - array( 'name' => 'database', 'callback' => array( $installer, 'setupDatabase' ) ),
311 - array( 'name' => 'tables', 'callback' => array( $this, 'installTables' ) ),
312 - array( 'name' => 'interwiki', 'callback' => array( $installer, 'populateInterwikiTable' ) ),
313 - array( 'name' => 'secretkey', 'callback' => array( $this, 'generateSecretKey' ) ),
 319+ $coreInstallSteps = array(
 320+ array( 'name' => 'database', 'callback' => array( $installer, 'setupDatabase' ) ),
 321+ array( 'name' => 'tables', 'callback' => array( $this, 'installTables' ) ),
 322+ array( 'name' => 'interwiki', 'callback' => array( $installer, 'populateInterwikiTable' ) ),
 323+ array( 'name' => 'secretkey', 'callback' => array( $this, 'generateSecretKey' ) ),
314324 array( 'name' => 'upgradekey', 'callback' => array( $this, 'generateUpgradeKey' ) ),
315 - array( 'name' => 'sysop', 'callback' => array( $this, 'createSysop' ) ),
316 - array( 'name' => 'mainpage', 'callback' => array( $this, 'createMainpage' ) ),
 325+ array( 'name' => 'sysop', 'callback' => array( $this, 'createSysop' ) ),
 326+ array( 'name' => 'mainpage', 'callback' => array( $this, 'createMainpage' ) ),
317327 );
318328 if( count( $this->getVar( '_Extensions' ) ) ) {
319 - array_unshift( $installSteps,
 329+ array_unshift( $coreInstallSteps,
320330 array( 'name' => 'extensions', 'callback' => array( $this, 'includeExtensions' ) )
321331 );
322332 }
323 - foreach( $installSteps as $idx => $stepObj ) {
324 - if( isset( $this->extraInstallSteps[ $stepObj['name'] ] ) ) {
325 - $tmp = array_slice( $installSteps, 0, $idx );
326 - $tmp[] = $this->extraInstallSteps[ $stepObj['name'] ];
327 - $installSteps = array_merge( $tmp, array_slice( $installSteps, $idx ) );
 333+ $this->installSteps = $coreInstallSteps;
 334+ foreach( $this->extraInstallSteps as $step ) {
 335+ // Put the step at the beginning
 336+ if( !strval( $step['position' ] ) ) {
 337+ array_unshift( $installSteps, $step['callback'] );
 338+ continue;
 339+ } else {
 340+ // Walk the $coreInstallSteps array to see if we can modify
 341+ // $this->installSteps with a callback that wants to attach after
 342+ // a given step
 343+ array_walk(
 344+ $coreInstallSteps,
 345+ array( $this, 'installStepCallback' ),
 346+ $step
 347+ );
328348 }
329349 }
330 - return $installSteps;
 350+ return $this->installSteps;
331351 }
332352
333353 /**
 354+ * Callback for getInstallSteps() - used for finding if a given $insertableStep
 355+ * should be inserted after the current $coreStep in question
 356+ */
 357+ private function installStepCallback( $coreStep, $key, $insertableStep ) {
 358+ if( $coreStep['name'] == $insertableStep['position'] ) {
 359+ $front = array_slice( $this->installSteps, 0, $key + 1 );
 360+ $front[] = $insertableStep['callback'];
 361+ $back = array_slice( $this->installSteps, $key + 1 );
 362+ $this->installSteps = array_merge( $front, $back );
 363+ }
 364+ }
 365+
 366+ /**
334367 * Actually perform the installation.
335368 *
336369 * @param $startCB A callback array for the beginning of each step
@@ -506,10 +539,12 @@
507540 /**
508541 * Add an installation step following the given step.
509542 *
510 - * @param $findStep String the step to find. Use NULL to put the step at the beginning.
511 - * @param $callback array A valid callback array, with name and callback given
 543+ * @param $callback Array A valid callback array, with name and callback given
 544+ * @param $findStep String the step to find. Omit to put the step at the beginning
512545 */
513 - public function addInstallStepFollowing( $findStep, $callback ) {
514 - $this->extraInstallSteps[$findStep] = $callback;
 546+ public function addInstallStep( $callback, $findStep = '' ) {
 547+ $this->extraInstallSteps[] = array(
 548+ 'position' => $findStep, 'callback' => $callback
 549+ );
515550 }
516551 }
Index: trunk/phase3/includes/installer/MysqlInstaller.php
@@ -366,7 +366,7 @@
367367 if ( !$create ) {
368368 // Test the web account
369369 try {
370 - new Database(
 370+ new DatabaseMysql(
371371 $this->getVar( 'wgDBserver' ),
372372 $this->getVar( 'wgDBuser' ),
373373 $this->getVar( 'wgDBpassword' ),
@@ -399,7 +399,7 @@
400400 'name' => 'user',
401401 'callback' => array( $this, 'setupUser' ),
402402 );
403 - $this->parent->addInstallStepFollowing( "tables", $callback );
 403+ $this->parent->addInstallStep( $callback, 'tables' );
404404 }
405405
406406 public function setupDatabase() {

Follow-up revisions

RevisionCommit summaryAuthorDate
r78925* Fix r78774 for Oracle and Postgres, broke by method rename...demon20:24, 23 December 2010
r79129MFT r78011 r78014 r78015 r78016 r78099 r78117 r78161 r78170 r78172 r78199 r78......platonides19:58, 28 December 2010
r79765Fix docs per comment on r78774demon22:33, 6 January 2011
r80006Fix callback issue noted in r79989 (broken in r78774)....demon13:54, 11 January 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r76390Rewrite install step callbacks to use the array model Ævar said I should use...demon15:58, 9 November 2010

Comments

#Comment by Catrope (talk | contribs)   17:28, 23 December 2010
+	 * @param $callback Array A valid callback array, with name and callback given

This should probably be clarified a little bit to say it's of the form array( 'name' => string, 'callback' => callback ). Upon reading this code for the first time, I thought it was broken because it added callbacks straight into the steps array, but it turns out these "callbacks" were really "callback arrays" of that form. Calling it a "callback array" and referring to it as $callback in the code is also a bit confusing IMO, but clear docs are more important than variable name choices.

#Comment by 😂 (talk | contribs)   17:48, 23 December 2010

Yeah during the course of this I renamed them about 10 times. In the end they all ended up being called callback. Better docs and var names can be added :)

Status & tagging log