'MediaWiki\\Diff\\WordAccumulator' => __DIR__ . '/includes/diff/WordAccumulator.php',
'MediaWiki\\HeaderCallback' => __DIR__ . '/includes/HeaderCallback.php',
'MediaWiki\\Http\\HttpRequestFactory' => __DIR__ . '/includes/http/HttpRequestFactory.php',
+ 'MediaWiki\\Installer\\InstallException' => __DIR__ . '/includes/installer/InstallException.php',
'MediaWiki\\Interwiki\\ClassicInterwikiLookup' => __DIR__ . '/includes/interwiki/ClassicInterwikiLookup.php',
'MediaWiki\\Interwiki\\InterwikiLookup' => __DIR__ . '/includes/interwiki/InterwikiLookup.php',
'MediaWiki\\Interwiki\\InterwikiLookupAdapter' => __DIR__ . '/includes/interwiki/InterwikiLookupAdapter.php',
* @ingroup Deployment
*/
+use MediaWiki\Installer\InstallException;
use MediaWiki\MediaWikiServices;
/**
* @param string $siteName
* @param string|null $admin
* @param array $options
+ * @throws InstallException
*/
function __construct( $siteName, $admin = null, array $options = [] ) {
global $wgContLang;
$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'] ) ) {
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 {
$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;
+ }
}
/**
$this->showMessage( ...$w );
}
}
-
- if ( !$status->isOK() ) {
- echo "\n";
- exit( 1 );
- }
}
public function envCheckPath() {
--- /dev/null
+<?php
+/**
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ */
+
+namespace MediaWiki\Installer;
+
+use Throwable;
+
+/**
+ * Exception thrown if an error occur which installation
+ * @ingroup Exception
+ */
+class InstallException extends \MWException {
+ /**
+ * @var \Status State when an exception occurs
+ */
+ private $status;
+
+ /**
+ * InstallException constructor.
+ * @param \Status $status State when an exception occurs
+ * @param string $message The Exception message to throw
+ * @param int $code The Exception code
+ * @param Throwable|null $previous The previous throwable used for the exception chaining
+ */
+ public function __construct( \Status $status, $message = '', $code = 0,
+ Throwable $previous = null ) {
+ parent::__construct( $message, $code, $previous );
+ $this->status = $status;
+ }
+
+ public function getStatus() : \Status {
+ return $this->status;
+ }
+}
*/
protected function envCheckDB() {
global $wgLang;
+ /** @var string|null $dbType The user-specified database type */
+ $dbType = $this->getVar( 'wgDBtype' );
$allNames = [];
$databases = $this->getCompiledDBs();
$databases = array_flip( $databases );
+ $ok = true;
foreach ( array_keys( $databases ) as $db ) {
$installer = $this->getDBInstaller( $db );
$status = $installer->checkPrerequisites();
if ( !$status->isGood() ) {
+ if ( !$this instanceof WebInstaller && $db === $dbType ) {
+ // Strictly check the key database type instead of just outputting message
+ // Note: No perform this check run from the web installer, since this method always called by
+ // the welcome page under web installation, so $dbType will always be 'mysql'
+ $ok = false;
+ }
$this->showStatusMessage( $status );
- }
- if ( !$status->isOK() ) {
unset( $databases[$db] );
}
}
$databases = array_flip( $databases );
if ( !$databases ) {
$this->showError( 'config-no-db', $wgLang->commaList( $allNames ), count( $allNames ) );
-
- // @todo FIXME: This only works for the web installer!
return false;
}
-
- return true;
+ return $ok;
}
/**
* @param callable $startCB A callback array for the beginning of each step
* @param callable $endCB A callback array for the end of each step
*
- * @return array Array of Status objects
+ * @return Status[] Array of Status objects
*/
public function performInstallation( $startCB, $endCB ) {
$installResults = [];
$this->setPassOption();
}
- $installer = InstallerOverrides::getCliInstaller( $siteName, $adminName, $this->mOptions );
+ try {
+ $installer = InstallerOverrides::getCliInstaller( $siteName, $adminName, $this->mOptions );
+ } catch ( \MediaWiki\Installer\InstallException $e ) {
+ $this->output( $e->getStatus()->getMessage()->parse() . "\n" );
+ return false;
+ }
$status = $installer->doEnvironmentChecks();
if ( $status->isGood() ) {
} else {
$installer->showStatusMessage( $status );
- return;
+ return false;
}
if ( !$envChecksOnly ) {
- $installer->execute();
+ $status = $installer->execute();
+ if ( !$status->isGood() ) {
+ return false;
+ }
$installer->writeConfigurationFile( $this->getOption( 'confpath', $IP ) );
+ $installer->showMessage(
+ 'config-install-success',
+ $installer->getVar( 'wgServer' ),
+ $installer->getVar( 'wgScriptPath' )
+ );
}
- $installer->showMessage(
- 'config-install-success',
- $installer->getVar( 'wgServer' ),
- $installer->getVar( 'wgScriptPath' )
- );
+ return true;
}
private function setDbPassOption() {