r71140 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r71139‎ | r71140 | r71141 >
Date:18:55, 15 August 2010
Author:demon
Status:ok (Comments)
Tags:
Comment:
Initial refactoring for Postgres; DatabaseUpdater subclass is now passed to LoadExtensionSchemaUpdates
Modified paths:
  • /trunk/phase3/docs/hooks.txt (modified) (history)
  • /trunk/phase3/includes/AutoLoader.php (modified) (history)
  • /trunk/phase3/includes/installer/CoreInstaller.php (modified) (history)
  • /trunk/phase3/includes/installer/DatabaseUpdater.php (modified) (history)
  • /trunk/phase3/includes/installer/Installer.php (modified) (history)
  • /trunk/phase3/includes/installer/PostgresUpdater.php (added) (history)
  • /trunk/phase3/maintenance/updaters.inc (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/updaters.inc
@@ -934,16 +934,16 @@
935935 function do_all_updates( $shared = false, $purge = true ) {
936936 global $wgSharedDB, $wgSharedTables, $wgDatabase, $wgDBtype;
937937
938 - wfRunHooks( 'LoadExtensionSchemaUpdates' );
 938+ $updater = DatabaseUpdater::newForDb( $wgDatabase, $shared );
939939
 940+ wfRunHooks( 'LoadExtensionSchemaUpdates', array( &$updater ) );
 941+
 942+ $updater->doUpdates();
 943+
940944 if ( $wgDBtype === 'postgres' ) {
941 - do_postgres_updates();
942945 return;
943946 }
944947
945 - $up = DatabaseUpdater::newForDb( $wgDatabase, $shared );
946 - $up->doUpdates();
947 -
948948 wfOut( "Deleting old default messages (this may take a long time!)..." );
949949 if ( !defined( 'MW_NO_SETUP' ) ) {
950950 define( 'MW_NO_SETUP', true );
Index: trunk/phase3/docs/hooks.txt
@@ -1031,8 +1031,8 @@
10321032 'ListDefinedTags': When trying to find all defined tags.
10331033 &$tags: The list of tags.
10341034
1035 -'LoadExtensionSchemaUpdates': called by maintenance/updaters.inc when upgrading
1036 -database schema
 1035+'LoadExtensionSchemaUpdates': called during database installation and updates
 1036+&updater: A DatabaseUpdater subclass
10371037
10381038 'LocalFile::getHistory': called before file history query performed
10391039 $file: the file
Index: trunk/phase3/includes/installer/DatabaseUpdater.php
@@ -26,17 +26,17 @@
2727 }
2828
2929 public static function newForDB( $db, $shared ) {
30 - switch( $db->getType() ) {
31 - case 'mysql':
32 - case 'sqlite':
33 - case 'oracle':
34 - $class = ucfirst( $db->getType() ) . 'Updater';
35 - return new $class( $db, $shared );
36 - default:
37 - throw new MWException( __METHOD__ . ' called for unsupported $wgDBtype' );
 30+ $type = $db->getType();
 31+ if( in_array( $type, Installer::getDBTypes() ) ) {
 32+ $class = ucfirst( $type ) . 'Updater';
 33+ return new $class( $db, $shared );
 34+ } else {
 35+ throw new MWException( __METHOD__ . ' called for unsupported $wgDBtype' );
3836 }
3937 }
4038
 39+ public function getDB() { return $this->db; }
 40+
4141 public function doUpdates() {
4242 global $IP, $wgVersion;
4343 require_once( "$IP/maintenance/updaters.inc" );
Index: trunk/phase3/includes/installer/PostgresUpdater.php
@@ -0,0 +1,23 @@
 2+<?php
 3+
 4+/**
 5+ * Class for handling updates to Postgres databases.
 6+ *
 7+ * @TODO @FIXME - Postgres should use sequential updates like Mysql, Sqlite
 8+ * and everybody else. It never got refactored like it should've. For now,
 9+ * just wrap the old do_postgres_updates() in this class so we can clean up
 10+ * the higher-level stuff.
 11+ *
 12+ * @ingroup Deployment
 13+ * @since 1.17
 14+ */
 15+
 16+class PostgresUpdater extends Updater {
 17+ protected function getCoreUpdateList() {
 18+ return array();
 19+ }
 20+
 21+ public function doUpdates() {
 22+ do_postgres_updates();
 23+ }
 24+}
Property changes on: trunk/phase3/includes/installer/PostgresUpdater.php
___________________________________________________________________
Added: svn:eol-style
125 + native
Index: trunk/phase3/includes/installer/Installer.php
@@ -61,7 +61,7 @@
6262 *
6363 * @var array
6464 */
65 - protected $dbTypes = array(
 65+ protected static $dbTypes = array(
6666 'mysql',
6767 'postgres',
6868 'sqlite',
@@ -118,8 +118,8 @@
119119 /**
120120 * Get a list of known DB types.
121121 */
122 - public function getDBTypes() {
123 - return $this->dbTypes;
 122+ public static function getDBTypes() {
 123+ return self::$dbTypes;
124124 }
125125
126126 /**
@@ -416,7 +416,7 @@
417417 $goodNames = array();
418418 $allNames = array();
419419
420 - foreach ( $this->dbTypes as $name ) {
 420+ foreach ( self::getDBTypes() as $name ) {
421421 $db = $this->getDBInstaller( $name );
422422 $readableName = wfMsg( 'config-type-' . $name );
423423
Index: trunk/phase3/includes/installer/CoreInstaller.php
@@ -200,7 +200,7 @@
201201 $this->settings[$var] = $GLOBALS[$var];
202202 }
203203
204 - foreach ( $this->dbTypes as $type ) {
 204+ foreach ( self::getDBTypes() as $type ) {
205205 $installer = $this->getDBInstaller( $type );
206206
207207 if ( !$installer->isCompiled() ) {
Index: trunk/phase3/includes/AutoLoader.php
@@ -437,6 +437,7 @@
438438 'MysqlInstaller' => 'includes/installer/MysqlInstaller.php',
439439 'MysqlUpdater' => 'includes/installer/MysqlUpdater.php',
440440 'PostgresInstaller' => 'includes/installer/PostgresInstaller.php',
 441+ 'PostgresUpdater' => 'includes/installer/PostgresUpdater.php',
441442 'SqliteInstaller' => 'includes/installer/SqliteInstaller.php',
442443 'SqliteUpdater' => 'includes/installer/SqliteUpdater.php',
443444 'OracleInstaller' => 'includes/installer/OracleInstaller.php',

Follow-up revisions

RevisionCommit summaryAuthorDate
r71417Fix for r71140: PostgresUpdater should extend DatabaseUpdater, not Updaterialex20:23, 21 August 2010

Comments

#Comment by OverlordQ (talk | contribs)   08:07, 21 August 2010

$ php maintenance/update.php MediaWiki 1.17alpha Updater

Going to run database updates for wikidb Depending on the size of your database this may take a while! Abort with control-c in the next five seconds (skip this countdown with --quick) ... 0 PHP Fatal error: Class 'Updater' not found in /var/www/com/w/includes/installer/PostgresUpdater.php on line 15

Fatal error: Class 'Updater' not found in /var/www/com/w/includes/installer/PostgresUpdater.php on line 15

#Comment by Platonides (talk | contribs)   20:12, 21 August 2010

I think it should extend DatabaseUpdater, not Updater.

#Comment by IAlex (talk | contribs)   20:24, 21 August 2010

Yes, fixed in r71417.

#Comment by Catrope (talk | contribs)   15:03, 12 December 2010
 	if ( $wgDBtype === 'postgres' ) {
-		do_postgres_updates();
 		return;
 	}

Why is this code still here? Why are things like deleting default messages skipped on postgres?

Code looks OK otherwise.

#Comment by Catrope (talk | contribs)   15:04, 12 December 2010

Delete default messages was done differently in r71163, but the general point stands: there's code below that if statement that gets skipped for postgres.

#Comment by 😂 (talk | contribs)   12:11, 14 December 2010

Historically, it was because the code below the if block was mySQL-specific (link table cleanup, etc etc) and would break postgres (and probably Oracle and any other DB, but this is old code :p)

At some point, various maintenance scripts have been fixed to use DB methods and aren't nearly as mySQL-specific anymore. But nobody bothered to fix update.php.

I can't find this happening anymore in trunk (as of r78369), but if you can point me at it, it's wrong.

#Comment by Catrope (talk | contribs)   12:21, 14 December 2010

Can't find this anywhere in trunk or REL1_17 (grepped for 'postgres' and only got what seem to be justifiable uses), so marking OK.

Status & tagging log