* Make the MySQL updater work in the new installer
authorAlexandre Emsenhuber <ialex@users.mediawiki.org>
Sun, 22 Aug 2010 10:37:27 +0000 (10:37 +0000)
committerAlexandre Emsenhuber <ialex@users.mediawiki.org>
Sun, 22 Aug 2010 10:37:27 +0000 (10:37 +0000)
* DatabaseInstaller::doUpgrade() is now abstract

TODO: MysqlUpdater::doUpgrade() is horrible, please someone fix it once it could be

includes/installer/DatabaseInstaller.php
includes/installer/Installer.i18n.php
includes/installer/MysqlInstaller.php
includes/installer/OracleInstaller.php
includes/installer/PostgresInstaller.php
includes/installer/SqliteInstaller.php
includes/installer/WebInstallerPage.php

index c7e2719..d9241e5 100644 (file)
@@ -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.
         */
index 9a54c1a..f1af514 100644 (file)
@@ -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.',
index 44dfa00..6a3f2f1 100644 (file)
@@ -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 );
        }
 
        /**
index 0abc69f..f6057f5 100644 (file)
@@ -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
index f2e5c76..c5af5bb 100644 (file)
@@ -149,4 +149,9 @@ class PostgresInstaller extends DatabaseInstaller {
 \$wgDBmwschema       = \"{$schema}\";
 \$wgDBts2schema      = \"{$ts2}\";";
        }
+
+       public function doUpgrade() {
+               // TODO
+               return false;
+       }
 }
index 36301c4..e4b7526 100644 (file)
@@ -210,5 +210,4 @@ class SqliteInstaller extends DatabaseInstaller {
 "# SQLite-specific settings
 \$wgSQLiteDataDir    = \"{$dir}\";";
        }
-       
 }
\ No newline at end of file
index 1e4e1ea..644ba7d 100644 (file)
@@ -293,6 +293,7 @@ class WebInstaller_Upgrade extends WebInstallerPage {
                }
 
                if ( $this->parent->request->wasPosted() ) {
+                       $installer->preUpgrade();
                        $this->addHTML(
                                '<div id="config-spinner" style="display:none;"><img src="../skins/common/images/ajax-loader.gif" /></div>' .
                                '<script>jQuery( "#config-spinner" )[0].style.display = "block";</script>' .