Dbarratt has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/372188 )
Change subject: WIP: Determine if LocalSettings.php exists and database is empty ...................................................................... WIP: Determine if LocalSettings.php exists and database is empty Determines if database is empty and then prompts installation. Installation determines if database is empty and skips steps that would invoke modification to LocalSettings.php. Bug: T172555 Change-Id: Id1f32dd3b995a43ebb2c63bb9788cc43947a162b --- M includes/installer/WebInstallerComplete.php M includes/installer/WebInstallerDBSettings.php M includes/installer/WebInstallerExistingWiki.php M includes/libs/rdbms/database/Database.php 4 files changed, 48 insertions(+), 1 deletion(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core refs/changes/88/372188/1 diff --git a/includes/installer/WebInstallerComplete.php b/includes/installer/WebInstallerComplete.php index 456058e..355610b 100644 --- a/includes/installer/WebInstallerComplete.php +++ b/includes/installer/WebInstallerComplete.php @@ -22,6 +22,14 @@ class WebInstallerComplete extends WebInstallerPage { public function execute() { + if ( $this->getVar( '_EmptyDatabase' ) ) { + $this->parent->request->response()->header( + 'Location: ' . $this->getVar( 'wgScriptPath' ) . '/index.php', + true, + 302 + ); + } + // Pop up a dialog box, to make it difficult for the user to forget // to download the file $lsUrl = $this->getVar( 'wgServer' ) . $this->parent->getUrl( [ 'localsettings' => 1 ] ); diff --git a/includes/installer/WebInstallerDBSettings.php b/includes/installer/WebInstallerDBSettings.php index f214663..36bb4ef 100644 --- a/includes/installer/WebInstallerDBSettings.php +++ b/includes/installer/WebInstallerDBSettings.php @@ -27,6 +27,10 @@ public function execute() { $installer = $this->parent->getDBInstaller( $this->getVar( 'wgDBtype' ) ); + if ( $this->getVar( '_EmptyDatabase' ) ) { + return 'skip'; + } + $r = $this->parent->request; if ( $r->wasPosted() ) { $status = $installer->submitSettingsForm(); diff --git a/includes/installer/WebInstallerExistingWiki.php b/includes/installer/WebInstallerExistingWiki.php index df68be8..a3e1a6c 100644 --- a/includes/installer/WebInstallerExistingWiki.php +++ b/includes/installer/WebInstallerExistingWiki.php @@ -31,13 +31,25 @@ return 'skip'; } + // Deteremine if database is empty. IF it is, this is not an upgrade. + $status = $this->handleExistingUpgrade( $vars ); + if ( $status->isOK() ) { + global $wgDBname; + $db = $this->parent->getDBInstaller()->db; + $db->selectDB( $wgDBname ); + $result = $db->query( 'SHOW TABLES' ); + if ( $result->numRows() === 0 ) { + $this->setVar( '_EmptyDatabase', true ); + return 'skip'; + } + } + // Check if the upgrade key supplied to the user has appeared in LocalSettings.php if ( $vars['wgUpgradeKey'] !== false && $this->getVar( '_UpgradeKeySupplied' ) && $this->getVar( 'wgUpgradeKey' ) === $vars['wgUpgradeKey'] ) { // It's there, so the user is authorized - $status = $this->handleExistingUpgrade( $vars ); if ( $status->isOK() ) { return 'skip'; } else { diff --git a/includes/libs/rdbms/database/Database.php b/includes/libs/rdbms/database/Database.php index b8b44e6..5ea6ccb 100644 --- a/includes/libs/rdbms/database/Database.php +++ b/includes/libs/rdbms/database/Database.php @@ -1115,6 +1115,7 @@ $this->mTrxPreCommitCallbacks = []; // T67263 $this->mSessionTempTables = []; $this->mNamedLocksHeld = []; + try { // Handle callbacks in mTrxEndCallbacks $this->runOnTransactionIdleCallbacks( self::TRIGGER_ROLLBACK ); @@ -1142,6 +1143,28 @@ ] ) ); $this->queryLogger->debug( "SQL ERROR: " . $error . "\n" ); + + // Table Does not exist. Before throwing an error, ensure that there is at + // least a single table otherwise MediaWiki hasn't been installed. + if ( $sql !== 'SHOW TABLES' ) { + $result = $this->query( 'SHOW TABLES' ); + if ( $result->numRows() === 0 ) { + global $wgVersion; + $templateParser = new \TemplateParser(); + + echo $templateParser->processTemplate( + 'NoLocalSettings', + [ + 'wgVersion' => ( isset( $wgVersion ) ? $wgVersion : 'VERSION' ), + 'ext' => 'php', + 'localSettingsExists' => false, + 'installerStarted' => true + ] + ); + exit; + } + } + throw new DBQueryError( $this, $error, $errno, $sql, $fname ); } } -- To view, visit https://gerrit.wikimedia.org/r/372188 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Id1f32dd3b995a43ebb2c63bb9788cc43947a162b Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/core Gerrit-Branch: master Gerrit-Owner: Dbarratt <dbarr...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits