Make CliInstaller control the processing logic of the error
[lhc/web/wiklou.git] / includes / installer / CliInstaller.php
index 7267ddd..99d594d 100644 (file)
@@ -21,6 +21,7 @@
  * @ingroup Deployment
  */
 
+use MediaWiki\Installer\InstallException;
 use MediaWiki\MediaWikiServices;
 
 /**
@@ -51,6 +52,7 @@ class CliInstaller extends Installer {
         * @param string $siteName
         * @param string|null $admin
         * @param array $options
+        * @throws InstallException
         */
        function __construct( $siteName, $admin = null, array $options = [] ) {
                global $wgContLang;
@@ -114,7 +116,7 @@ class CliInstaller extends Installer {
                        $status = $this->validateExtensions(
                                'extension', 'extensions', $options['extensions'] );
                        if ( !$status->isOK() ) {
-                               $this->showStatusMessage( $status );
+                               throw new InstallException( $status );
                        }
                        $this->setVar( '_Extensions', $status->value );
                } elseif ( isset( $options['with-extensions'] ) ) {
@@ -125,7 +127,7 @@ class CliInstaller extends Installer {
                if ( isset( $options['skins'] ) ) {
                        $status = $this->validateExtensions( 'skin', 'skins', $options['skins'] );
                        if ( !$status->isOK() ) {
-                               $this->showStatusMessage( $status );
+                               throw new InstallException( $status );
                        }
                        $skins = $status->value;
                } else {
@@ -165,17 +167,34 @@ class CliInstaller extends Installer {
         * Main entry point.
         */
        public function execute() {
+               // If APC is available, use that as the MainCacheType, instead of nothing.
+               // This is hacky and should be consolidated with WebInstallerOptions.
+               // This is here instead of in __construct(), because it should run run after
+               // doEnvironmentChecks(), which populates '_Caches'.
+               if ( count( $this->getVar( '_Caches' ) ) ) {
+                       // We detected a CACHE_ACCEL implementation, use it.
+                       $this->setVar( '_MainCacheType', 'accel' );
+               }
+
                $vars = Installer::getExistingLocalSettings();
                if ( $vars ) {
-                       $this->showStatusMessage(
-                               Status::newFatal( "config-localsettings-cli-upgrade" )
-                       );
+                       $status = Status::newFatal( "config-localsettings-cli-upgrade" );
+                       $this->showStatusMessage( $status );
+                       return $status;
                }
 
-               $this->performInstallation(
+               $result = $this->performInstallation(
                        [ $this, 'startStage' ],
                        [ $this, 'endStage' ]
                );
+               // PerformInstallation bails on a fatal, so make sure the last item
+               // completed before giving 'next.' Likewise, only provide back on failure
+               $lastStepStatus = end( $result );
+               if ( $lastStepStatus->isOk() ) {
+                       return Status::newGood();
+               } else {
+                       return $lastStepStatus;
+               }
        }
 
        /**
@@ -200,24 +219,23 @@ class CliInstaller extends Installer {
                $this->showMessage( 'config-install-step-done' );
        }
 
-       public function showMessage( $msg /*, ... */ ) {
-               echo $this->getMessageText( func_get_args() ) . "\n";
+       public function showMessage( $msg, ...$params ) {
+               echo $this->getMessageText( $msg, $params ) . "\n";
                flush();
        }
 
-       public function showError( $msg /*, ... */ ) {
-               echo "***{$this->getMessageText( func_get_args() )}***\n";
+       public function showError( $msg, ...$params ) {
+               echo "***{$this->getMessageText( $msg, $params )}***\n";
                flush();
        }
 
        /**
+        * @param string $msg
         * @param array $params
         *
         * @return string
         */
-       protected function getMessageText( $params ) {
-               $msg = array_shift( $params );
-
+       protected function getMessageText( $msg, $params ) {
                $text = wfMessage( $msg, $params )->parse();
 
                $text = preg_replace( '/<a href="(.*?)".*?>(.*?)<\/a>/', '$2 &lt;$1&gt;', $text );
@@ -240,11 +258,6 @@ class CliInstaller extends Installer {
                                $this->showMessage( ...$w );
                        }
                }
-
-               if ( !$status->isOK() ) {
-                       echo "\n";
-                       exit( 1 );
-               }
        }
 
        public function envCheckPath() {