r65860 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r65859‎ | r65860 | r65861 >
Date:16:01, 3 May 2010
Author:avar
Status:ok (Comments)
Tags:
Comment:
Make all Installer::$installSteps methods return Status, not bool

Now instead of saying just "Fail" on the Install page when something
fails, we show a detailed error showing what went wrong.
Modified paths:
  • /branches/new-installer/phase3/includes/installer/Installer.php (modified) (history)
  • /branches/new-installer/phase3/includes/installer/WebInstaller.php (modified) (history)

Diff [purge]

Index: branches/new-installer/phase3/includes/installer/WebInstaller.php
@@ -1570,8 +1570,12 @@
15711571 foreach( $this->parent->getInstallSteps() as $step ) {
15721572 $this->startStage( "config-install-$step" );
15731573 $func = 'install' . ucfirst( $step );
1574 - $success = $this->parent->{$func}();
1575 - $this->endStage( $success );
 1574+ $status = $this->parent->{$func}();
 1575+ $ok = $status->isGood();
 1576+ if ( !$ok ) {
 1577+ $this->parent->showStatusErrorBox( $status );
 1578+ }
 1579+ $this->endStage( $ok );
15761580 }
15771581 $this->addHTML("</ul>");
15781582 $this->endForm();
Index: branches/new-installer/phase3/includes/installer/Installer.php
@@ -828,16 +828,13 @@
829829 foreach( $exts as $e ) {
830830 require( "$path/$e/$e.php" );
831831 }
832 - return true;
 832+ return Status::newGood();
833833 }
834834
835835 public function installDatabase() {
836836 $installer = $this->getDBInstaller( $this->getVar( 'wgDBtype' ) );
837 - $db = $installer->setupDatabase();
838 - if( !$db ) {
839 - return false;
840 - }
841 - return true;
 837+ $status = $installer->setupDatabase();
 838+ return $status;
842839 }
843840
844841 public function installTables() {
@@ -845,10 +842,8 @@
846843 $status = $installer->createTables();
847844 if( $status->isGood() ) {
848845 LBFactory::enableBackend();
849 - return true;
850 - } else {
851 - return false;
852846 }
 847+ return $status;
853848 }
854849
855850 public function installSecretKey() {
@@ -864,7 +859,7 @@
865860 $this->output->addWarningMsg( 'config-insecure-secretkey' );
866861 }
867862 $this->setVar( 'wgSecretKey', $secretKey );
868 - return true;
 863+ return Status::newGood();
869864 }
870865
871866 public function installSysop() {
@@ -872,27 +867,33 @@
873868 $user = User::newFromName( $name );
874869 if ( !$user ) {
875870 // we should've validated this earlier anyway!
876 - $this->output->addWarningMsg( 'config-admin-error-user', $name );
877 - return false;
 871+ return Status::newFatal( 'config-admin-error-user', $name );
878872 }
879873 if ( $user->idForName() == 0 ) {
880874 $user->addToDatabase();
881875 try {
882876 $user->setPassword( $this->getVar( '_AdminPassword' ) );
883877 } catch( PasswordError $pwe ) {
884 - $this->output->addWarningMsg( 'config-admin-error-password', $name, $pwe->getMessage() );
885 - return false;
 878+ return Status::newFatal( 'config-admin-error-password', $name, $pwe->getMessage() );
886879 }
887880 $user->saveSettings();
888881 $user->addGroup( 'sysop' );
889882 $user->addGroup( 'bureaucrat' );
890883 }
891 - return true;
 884+ return Status::newGood();
892885 }
893886
894887 public function installLocalsettings() {
895888 $localSettings = new LocalSettingsGenerator( $this );
896 - return $localSettings->writeLocalSettings();
 889+ $ok = $localSettings->writeLocalSettings();
 890+
 891+ # TODO: Make writeLocalSettings() itself not warn, but instead return
 892+ # a Status object to us to pass along.
 893+ if ( $ok ) {
 894+ return Status::newGood();
 895+ } else {
 896+ return Status::newFatal();
 897+ }
897898 }
898899
899900 /*

Comments

#Comment by Tim Starling (talk | contribs)   03:16, 30 June 2010

You missed an instance of $this->output->addWarningMsg() in Installer::installSecretKey(), see r64348. Note that the Status class has support for non-fatal warning lists.

#Comment by Ævar Arnfjörð Bjarmason (talk | contribs)   21:50, 4 July 2010

Thanks Tim. Marking this as fixed since mah beat me to it and fixed it in r68908.

Status & tagging log