r69142 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r69141‎ | r69142 | r69143 >
Date:13:52, 7 July 2010
Author:demon
Status:ok (Comments)
Tags:
Comment:
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
Modified paths:
  • /trunk/phase3/includes/installer/Installer.php (modified) (history)
  • /trunk/phase3/includes/installer/InstallerDBType.php (modified) (history)
  • /trunk/phase3/includes/installer/MysqlInstaller.php (modified) (history)
  • /trunk/phase3/includes/installer/OracleInstaller.php (modified) (history)
  • /trunk/phase3/includes/installer/PostgresInstaller.php (modified) (history)
  • /trunk/phase3/includes/installer/SqliteInstaller.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/installer/Installer.php
@@ -235,7 +235,7 @@
236236 }
237237 foreach ( $this->dbTypes as $type ) {
238238 $installer = $this->getDBInstaller( $type );
239 - if ( !$installer ) {
 239+ if ( !$installer->isCompiled() ) {
240240 continue;
241241 }
242242 $defaults = $installer->getGlobalDefaults();
@@ -282,11 +282,7 @@
283283
284284 if ( !isset( $this->dbInstallers[$type] ) ) {
285285 $class = ucfirst( $type ). 'Installer';
286 - if ( call_user_func( array( $class, 'isCompiled' ) ) ) {
287 - $this->dbInstallers[$type] = new $class( $this );
288 - } else {
289 - $this->dbInstallers[$type] = false;
290 - }
 286+ $this->dbInstallers[$type] = new $class( $this );
291287 }
292288 return $this->dbInstallers[$type];
293289 }
@@ -867,6 +863,7 @@
868864 */
869865 public function performInstallation( $startCB, $endCB ) {
870866 $installResults = array();
 867+ $installer = $this->getDBInstaller();
871868 foreach( $this->getInstallSteps() as $stepObj ) {
872869 $step = is_array( $stepObj ) ? $stepObj['name'] : $stepObj;
873870 call_user_func_array( $startCB, array( $step ) );
@@ -880,7 +877,7 @@
881878 } else {
882879 # Boring implicitly named callback
883880 $func = 'install' . ucfirst( $step );
884 - $status = $this->{$func}();
 881+ $status = $this->{$func}( $installer );
885882 }
886883 call_user_func_array( $endCB, array( $step, $status ) );
887884 $installResults[$step] = $status;
@@ -903,10 +900,9 @@
904901 return Status::newGood();
905902 }
906903
907 - public function installDatabase() {
908 - $type = $this->getVar( 'wgDBtype' );
909 - $installer = $this->getDBInstaller( $type );
 904+ public function installDatabase( &$installer ) {
910905 if(!$installer) {
 906+ $type = $this->getVar( 'wgDBtype' );
911907 $status = Status::newFatal( "config-no-db", $type );
912908 } else {
913909 $status = $installer->setupDatabase();
@@ -914,8 +910,7 @@
915911 return $status;
916912 }
917913
918 - public function installTables() {
919 - $installer = $this->getDBInstaller();
 914+ public function installTables( &$installer ) {
920915 $status = $installer->createTables();
921916 if( $status->isOK() ) {
922917 LBFactory::enableBackend();
@@ -923,8 +918,7 @@
924919 return $status;
925920 }
926921
927 - public function installInterwiki() {
928 - $installer = $this->getDBInstaller();
 922+ public function installInterwiki( &$installer ) {
929923 return $installer->populateInterwikiTable();
930924 }
931925
Index: trunk/phase3/includes/installer/SqliteInstaller.php
@@ -10,7 +10,7 @@
1111 return 'sqlite';
1212 }
1313
14 - static function isCompiled() {
 14+ public function isCompiled() {
1515 return self::checkExtension( 'pdo_sqlite' );
1616 }
1717
Index: trunk/phase3/includes/installer/MysqlInstaller.php
@@ -34,22 +34,9 @@
3535
3636 function __construct( $parent ) {
3737 parent::__construct( $parent );
38 -
39 - if ( $this->parent->getVar( 'wgDBtype' ) !== $this->getName() ) {
40 - return;
41 - }
42 -
43 - # Add our user callback to installSteps, right before the tables are created.
44 - $callback = array(
45 - array(
46 - 'name' => 'user',
47 - 'callback' => array( &$this, 'setupUser' ),
48 - )
49 - );
50 - $this->parent->addInstallStepFollowing( "tables", $callback );
5138 }
5239
53 - static function isCompiled() {
 40+ public function isCompiled() {
5441 return self::checkExtension( 'mysql' );
5542 }
5643
@@ -379,6 +366,17 @@
380367 return Status::newGood();
381368 }
382369
 370+ public function preInstall() {
 371+ # Add our user callback to installSteps, right before the tables are created.
 372+ $callback = array(
 373+ array(
 374+ 'name' => 'user',
 375+ 'callback' => array( &$this, 'setupUser' ),
 376+ )
 377+ );
 378+ $this->parent->addInstallStepFollowing( "tables", $callback );
 379+ }
 380+
383381 function setupDatabase() {
384382 $status = $this->getConnection();
385383 if ( !$status->isOK() ) {
Index: trunk/phase3/includes/installer/OracleInstaller.php
@@ -19,7 +19,7 @@
2020 return 'oracle';
2121 }
2222
23 - static function isCompiled() {
 23+ public function isCompiled() {
2424 return self::checkExtension( 'oci8' );
2525 }
2626
Index: trunk/phase3/includes/installer/PostgresInstaller.php
@@ -25,7 +25,7 @@
2626 return 'postgres';
2727 }
2828
29 - static function isCompiled() {
 29+ public function isCompiled() {
3030 return self::checkExtension( 'pgsql' );
3131 }
3232
Index: trunk/phase3/includes/installer/InstallerDBType.php
@@ -24,7 +24,7 @@
2525 /**
2626 * @return true if the client library is compiled in
2727 */
28 - abstract static function isCompiled();
 28+ abstract public function isCompiled();
2929
3030 /**
3131 * Get an array of MW configuration globals that will be configured by this class.
@@ -78,6 +78,13 @@
7979 abstract function getConnection();
8080
8181 /**
 82+ * Allow DB installers a chance to make last-minute changes before installation
 83+ * occurs. This happens before setupDatabase() or createTables() is called, but
 84+ * long after the constructor. Helpful for things like modifying setup steps :)
 85+ */
 86+ public function preInstall() {}
 87+
 88+ /**
8289 * Create the database and return a Status object indicating success or
8390 * failure.
8491 *
@@ -126,7 +133,7 @@
127134 * Convenience function
128135 * Check if a named extension is present
129136 */
130 - static function checkExtension( $name ) {
 137+ protected static function checkExtension( $name ) {
131138 wfSuppressWarnings();
132139 $compiled = wfDl( $name );
133140 wfRestoreWarnings();

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r69128* Add Status::getWarningsArray() to complement Status::getErrorsArray()...mah02:53, 7 July 2010

Comments

#Comment by Tim Starling (talk | contribs)   00:35, 25 January 2011

What's with the call-by-reference? For example

+				'callback' => array( &$this, 'setupUser' ),

This was required in PHP 4, and it's still present in some old code because we can't change it without breaking backwards compatibility. It shouldn't be done in new code unless you want the function you call to be able to change what object instance $this (or whatever) points to in the caller. In most cases, this ability is undesirable, so you should pass a handle.

I am fixing it.

Status & tagging log