r71430 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r71429‎ | r71430 | r71431 >
Date:10:37, 22 August 2010
Author:ialex
Status:resolved (Comments)
Tags:
Comment:
* 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
Modified paths:
  • /trunk/phase3/includes/installer/DatabaseInstaller.php (modified) (history)
  • /trunk/phase3/includes/installer/Installer.i18n.php (modified) (history)
  • /trunk/phase3/includes/installer/MysqlInstaller.php (modified) (history)
  • /trunk/phase3/includes/installer/OracleInstaller.php (modified) (history)
  • /trunk/phase3/includes/installer/PostgresInstaller.php (modified) (history)
  • /trunk/phase3/includes/installer/SqliteInstaller.php (modified) (history)
  • /trunk/phase3/includes/installer/WebInstallerPage.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/installer/Installer.i18n.php
@@ -301,6 +301,8 @@
302302
303303 '''MyISAM''' may be faster in single-user or read-only installations.
304304 MyISAM databases tend to get corrupted more often than InnoDB databases.",
 305+ 'config-mysql-egine-mismatch' => "'''Warning:''' you requested the $1 storage engine, but the existing database uses the $2 engine.
 306+This upgrade script can't convert it, so it will remain $2.",
305307 'config-mysql-charset' => 'Database character set:',
306308 'config-mysql-binary' => 'Binary',
307309 'config-mysql-utf8' => 'UTF-8',
@@ -308,6 +310,8 @@
309311 This is more efficient than MySQL's UTF-8 mode, and allows you to use the full range of Unicode characters.
310312
311313 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].",
 314+ 'config-mysql-charset-mismatch' => "'''Warning:''' you requested the $1 schema, but the existing database has the $2 schema.
 315+ This upgrade script can't convert it, so it will remain $2.",
312316 'config-site-name' => 'Name of wiki:',
313317 'config-site-name-help' => "This will appear in the title bar of the browser and in various other places.",
314318 'config-site-name-blank' => 'Enter a site name.',
Index: trunk/phase3/includes/installer/SqliteInstaller.php
@@ -210,5 +210,4 @@
211211 "# SQLite-specific settings
212212 \$wgSQLiteDataDir = \"{$dir}\";";
213213 }
214 -
215214 }
\ No newline at end of file
Index: trunk/phase3/includes/installer/DatabaseInstaller.php
@@ -123,11 +123,10 @@
124124
125125 /**
126126 * Perform database upgrades
127 - * @todo make abstract
 127+ *
 128+ * @return Boolean
128129 */
129 - /*abstract*/ function doUpgrade() {
130 - return false;
131 - }
 130+ public abstract function doUpgrade();
132131
133132 /**
134133 * Allow DB installers a chance to make last-minute changes before installation
@@ -139,6 +138,13 @@
140139 }
141140
142141 /**
 142+ * Allow DB installers a chance to make checks before upgrade.
 143+ */
 144+ public function preUpgrade() {
 145+
 146+ }
 147+
 148+ /**
143149 * Get an array of MW configuration globals that will be configured by this class.
144150 */
145151 public function getGlobalNames() {
Index: trunk/phase3/includes/installer/MysqlInstaller.php
@@ -130,13 +130,14 @@
131131 return $status;
132132 }
133133
134 - public function doUpgrade() {
 134+ public function preUpgrade() {
135135 $status = $this->getConnection();
136136 if ( !$status->isOK() ) {
137137 $this->parent->showStatusError( $status );
138138 return;
139139 }
140140 $conn = $status->value;
 141+ $conn->selectDB( $this->getVar( 'wgDBname' ) );
141142
142143 # Determine existing default character set
143144 if ( $conn->tableExists( "revision" ) ) {
@@ -164,12 +165,56 @@
165166 $existingEngine = $row->Type;
166167 }
167168 }
 169+ } else {
 170+ $existingSchema = false;
 171+ $existingEngine = false;
168172 }
169 -
170 - // TODO
 173+
 174+ if ( $existingSchema && $existingSchema != $this->getVar( '_MysqlCharset' ) ) {
 175+ $this->parent->showMessage( 'config-mysql-charset-mismatch', $this->getVar( '_MysqlCharset' ), $existingSchema );
 176+ $this->setVar( '_MysqlCharset', $existingSchema );
 177+ }
 178+ if ( $existingEngine && $existingEngine != $this->getVar( '_MysqlEngine' ) ) {
 179+ $this->parent->showMessage( 'config-mysql-egine-mismatch', $this->getVar( '_MysqlEngine' ), $existingEngine );
 180+ $this->setVar( '_MysqlEngine', $existingEngine );
 181+ }
171182 }
172183
173184 /**
 185+ * @todo FIXME: this code is just pure crap for compatibility between
 186+ * old and new code.
 187+ */
 188+ public function doUpgrade() {
 189+ global $wgDatabase, $wgDBuser, $wgDBpassword;
 190+
 191+ # Some maintenance scripts like wfGetDB()
 192+ LBFactory::enableBackend();
 193+ # For do_all_updates()
 194+ $wgDatabase = $this->db;
 195+ # Normal user and password are selected after this step, so for now
 196+ # just copy these two
 197+ $wgDBuser = $this->getVar( '_InstallUser' );
 198+ $wgDBpassword = $this->getVar( '_InstallPassword' );
 199+
 200+ $ret = true;
 201+
 202+ ob_start( array( __CLASS__, 'outputHandler' ) );
 203+ try {
 204+ do_all_updates( false, true );
 205+ } catch ( MWException $e ) {
 206+ echo "\nAn error occured:\n";
 207+ echo $e->getText();
 208+ $ret = false;
 209+ }
 210+ ob_end_flush();
 211+ return $ret;
 212+ }
 213+
 214+ public static function outputHandler( $string ) {
 215+ return htmlspecialchars( $string );
 216+ }
 217+
 218+ /**
174219 * Get a list of storage engines that are available and supported
175220 */
176221 public function getEngines() {
Index: trunk/phase3/includes/installer/OracleInstaller.php
@@ -115,5 +115,9 @@
116116 "# Oracle specific settings
117117 \$wgDBprefix = \"{$prefix}\";";
118118 }
119 -
 119+
 120+ public function doUpgrade() {
 121+ // TODO
 122+ return false;
 123+ }
120124 }
\ No newline at end of file
Index: trunk/phase3/includes/installer/PostgresInstaller.php
@@ -149,4 +149,9 @@
150150 \$wgDBmwschema = \"{$schema}\";
151151 \$wgDBts2schema = \"{$ts2}\";";
152152 }
 153+
 154+ public function doUpgrade() {
 155+ // TODO
 156+ return false;
 157+ }
153158 }
Index: trunk/phase3/includes/installer/WebInstallerPage.php
@@ -293,6 +293,7 @@
294294 }
295295
296296 if ( $this->parent->request->wasPosted() ) {
 297+ $installer->preUpgrade();
297298 $this->addHTML(
298299 '<div id="config-spinner" style="display:none;"><img src="../skins/common/images/ajax-loader.gif" /></div>' .
299300 '<script>jQuery( "#config-spinner" )[0].style.display = "block";</script>' .

Follow-up revisions

RevisionCommit summaryAuthorDate
r72553Per ^demon's comment on r71430: moved doUpgrade() to DatabaseInstaller (did n...ialex20:57, 7 September 2010

Comments

#Comment by 😂 (talk | contribs)   13:08, 7 September 2010

Since we've got preUpgrade() for things like last-minute schema checks, couldn't we move doUpgrade() up to DatabaseInstaller()? It's sufficiently generic I believe.

Status & tagging log