From 47296df668c0e384b59822d0e6e9fc108aa0c99c Mon Sep 17 00:00:00 2001 From: Alexandre Emsenhuber Date: Sun, 22 Aug 2010 10:37:27 +0000 Subject: [PATCH] * Make the MySQL updater work in the new installer * DatabaseInstaller::doUpgrade() is now abstract TODO: MysqlUpdater::doUpgrade() is horrible, please someone fix it once it could be --- includes/installer/DatabaseInstaller.php | 14 +++++-- includes/installer/Installer.i18n.php | 4 ++ includes/installer/MysqlInstaller.php | 51 ++++++++++++++++++++++-- includes/installer/OracleInstaller.php | 6 ++- includes/installer/PostgresInstaller.php | 5 +++ includes/installer/SqliteInstaller.php | 1 - includes/installer/WebInstallerPage.php | 1 + 7 files changed, 73 insertions(+), 9 deletions(-) diff --git a/includes/installer/DatabaseInstaller.php b/includes/installer/DatabaseInstaller.php index c7e27198f6..d9241e529b 100644 --- a/includes/installer/DatabaseInstaller.php +++ b/includes/installer/DatabaseInstaller.php @@ -123,11 +123,10 @@ abstract class DatabaseInstaller { /** * Perform database upgrades - * @todo make abstract + * + * @return Boolean */ - /*abstract*/ function doUpgrade() { - return false; - } + public abstract function doUpgrade(); /** * Allow DB installers a chance to make last-minute changes before installation @@ -138,6 +137,13 @@ abstract class DatabaseInstaller { } + /** + * Allow DB installers a chance to make checks before upgrade. + */ + public function preUpgrade() { + + } + /** * Get an array of MW configuration globals that will be configured by this class. */ diff --git a/includes/installer/Installer.i18n.php b/includes/installer/Installer.i18n.php index 9a54c1ad5b..f1af514375 100644 --- a/includes/installer/Installer.i18n.php +++ b/includes/installer/Installer.i18n.php @@ -301,6 +301,8 @@ The account you specify here must already exist.', '''MyISAM''' may be faster in single-user or read-only installations. MyISAM databases tend to get corrupted more often than InnoDB databases.", + 'config-mysql-egine-mismatch' => "'''Warning:''' you requested the $1 storage engine, but the existing database uses the $2 engine. +This upgrade script can't convert it, so it will remain $2.", 'config-mysql-charset' => 'Database character set:', 'config-mysql-binary' => 'Binary', 'config-mysql-utf8' => 'UTF-8', @@ -308,6 +310,8 @@ MyISAM databases tend to get corrupted more often than InnoDB databases.", This is more efficient than MySQL's UTF-8 mode, and allows you to use the full range of Unicode characters. In '''UTF-8 mode''', MySQL will know what character set your data is in, and can present and convert it appropriately, but it will not let you store characters above the [http://en.wikipedia.org/wiki/Mapping_of_Unicode_character_planes Basic Multilingual Plane].", + 'config-mysql-charset-mismatch' => "'''Warning:''' you requested the $1 schema, but the existing database has the $2 schema. + This upgrade script can't convert it, so it will remain $2.", 'config-site-name' => 'Name of wiki:', 'config-site-name-help' => "This will appear in the title bar of the browser and in various other places.", 'config-site-name-blank' => 'Enter a site name.', diff --git a/includes/installer/MysqlInstaller.php b/includes/installer/MysqlInstaller.php index 44dfa00b02..6a3f2f1a1e 100644 --- a/includes/installer/MysqlInstaller.php +++ b/includes/installer/MysqlInstaller.php @@ -130,13 +130,14 @@ class MysqlInstaller extends DatabaseInstaller { return $status; } - public function doUpgrade() { + public function preUpgrade() { $status = $this->getConnection(); if ( !$status->isOK() ) { $this->parent->showStatusError( $status ); return; } $conn = $status->value; + $conn->selectDB( $this->getVar( 'wgDBname' ) ); # Determine existing default character set if ( $conn->tableExists( "revision" ) ) { @@ -164,9 +165,53 @@ class MysqlInstaller extends DatabaseInstaller { $existingEngine = $row->Type; } } + } else { + $existingSchema = false; + $existingEngine = false; } - - // TODO + + if ( $existingSchema && $existingSchema != $this->getVar( '_MysqlCharset' ) ) { + $this->parent->showMessage( 'config-mysql-charset-mismatch', $this->getVar( '_MysqlCharset' ), $existingSchema ); + $this->setVar( '_MysqlCharset', $existingSchema ); + } + if ( $existingEngine && $existingEngine != $this->getVar( '_MysqlEngine' ) ) { + $this->parent->showMessage( 'config-mysql-egine-mismatch', $this->getVar( '_MysqlEngine' ), $existingEngine ); + $this->setVar( '_MysqlEngine', $existingEngine ); + } + } + + /** + * @todo FIXME: this code is just pure crap for compatibility between + * old and new code. + */ + public function doUpgrade() { + global $wgDatabase, $wgDBuser, $wgDBpassword; + + # Some maintenance scripts like wfGetDB() + LBFactory::enableBackend(); + # For do_all_updates() + $wgDatabase = $this->db; + # Normal user and password are selected after this step, so for now + # just copy these two + $wgDBuser = $this->getVar( '_InstallUser' ); + $wgDBpassword = $this->getVar( '_InstallPassword' ); + + $ret = true; + + ob_start( array( __CLASS__, 'outputHandler' ) ); + try { + do_all_updates( false, true ); + } catch ( MWException $e ) { + echo "\nAn error occured:\n"; + echo $e->getText(); + $ret = false; + } + ob_end_flush(); + return $ret; + } + + public static function outputHandler( $string ) { + return htmlspecialchars( $string ); } /** diff --git a/includes/installer/OracleInstaller.php b/includes/installer/OracleInstaller.php index 0abc69f146..f6057f57a5 100644 --- a/includes/installer/OracleInstaller.php +++ b/includes/installer/OracleInstaller.php @@ -115,5 +115,9 @@ class OracleInstaller extends DatabaseInstaller { "# Oracle specific settings \$wgDBprefix = \"{$prefix}\";"; } - + + public function doUpgrade() { + // TODO + return false; + } } \ No newline at end of file diff --git a/includes/installer/PostgresInstaller.php b/includes/installer/PostgresInstaller.php index f2e5c76117..c5af5bbe93 100644 --- a/includes/installer/PostgresInstaller.php +++ b/includes/installer/PostgresInstaller.php @@ -149,4 +149,9 @@ class PostgresInstaller extends DatabaseInstaller { \$wgDBmwschema = \"{$schema}\"; \$wgDBts2schema = \"{$ts2}\";"; } + + public function doUpgrade() { + // TODO + return false; + } } diff --git a/includes/installer/SqliteInstaller.php b/includes/installer/SqliteInstaller.php index 36301c42ee..e4b7526330 100644 --- a/includes/installer/SqliteInstaller.php +++ b/includes/installer/SqliteInstaller.php @@ -210,5 +210,4 @@ class SqliteInstaller extends DatabaseInstaller { "# SQLite-specific settings \$wgSQLiteDataDir = \"{$dir}\";"; } - } \ No newline at end of file diff --git a/includes/installer/WebInstallerPage.php b/includes/installer/WebInstallerPage.php index 1e4e1ea5e7..644ba7d178 100644 --- a/includes/installer/WebInstallerPage.php +++ b/includes/installer/WebInstallerPage.php @@ -293,6 +293,7 @@ class WebInstaller_Upgrade extends WebInstallerPage { } if ( $this->parent->request->wasPosted() ) { + $installer->preUpgrade(); $this->addHTML( '' . '' . -- 2.20.1