r71359 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r71358‎ | r71359 | r71360 >
Date:14:47, 20 August 2010
Author:demon
Status:ok (Comments)
Tags:
Comment:
Refactor convertLinks to not use DB::newFromParams() crap, make updaters use the maintenance script to reduce duplication, other minor fixes
Modified paths:
  • /trunk/phase3/maintenance/convertLinks.php (modified) (history)
  • /trunk/phase3/maintenance/updaters.inc (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/updaters.inc
@@ -9,7 +9,6 @@
1010 exit( 1 );
1111 }
1212
13 -require_once 'convertLinks.inc';
1413 require_once 'userDupes.inc';
1514 # Extension updates
1615 require_once( "$IP/includes/Hooks.php" );
@@ -514,12 +513,12 @@
515514 }
516515
517516 function do_old_links_update() {
518 - global $wgDatabase;
519 - if ( $wgDatabase->tableExists( 'pagelinks' ) ) {
520 - wfOut( "...have pagelinks; skipping old links table updates.\n" );
521 - } else {
522 - convertLinks(); flush();
 517+ if( !defined( 'MW_NO_SETUP' ) ) {
 518+ define( 'MW_NO_SETUP', true );
523519 }
 520+ require( "convertLinks.php" );
 521+ $cl = new ConvertLinks();
 522+ $cl->execute();
524523 }
525524
526525 function fix_ancient_imagelinks() {
Index: trunk/phase3/maintenance/convertLinks.php
@@ -31,17 +31,22 @@
3232 The wiki should be put into read-only mode while this script executes";
3333 }
3434
 35+ public function getDbType() {
 36+ return self::DB_ADMIN;
 37+ }
 38+
3539 public function execute() {
3640 global $wgDBtype;
37 - if ( $wgDBtype == 'postgres' ) {
38 - $this->output( "Links table already ok on Postgres.\n" );
 41+
 42+ $dbw = wfGetDB( DB_MASTER );
 43+
 44+ $type = $dbw->getType();
 45+ if ( $type != 'mysql' ) {
 46+ $this->output( "Link table conversion not necessary for $type\n" );
3947 return;
4048 }
4149
42 - $this->output( "Converting links table to ID-ID...\n" );
43 -
44 - global $wgLang, $wgDBserver, $wgDBadminuser, $wgDBadminpassword, $wgDBname;
45 - global $noKeys, $logPerformance, $fh;
 50+ global $wgLang, $noKeys, $logPerformance, $fh;
4651
4752 $tuplesAdded = $numBadLinks = $curRowsRead = 0; # counters etc
4853 $totalTuplesInserted = 0; # total tuples INSERTed into links_temp
@@ -68,8 +73,12 @@
6974 $perfLogFilename = "convLinksPerf.txt";
7075 # --------------------------------------------------------------------
7176
72 - $dbw = wfGetDB( DB_MASTER );
7377 list ( $cur, $links, $links_temp, $links_backup ) = $dbw->tableNamesN( 'cur', 'links', 'links_temp', 'links_backup' );
 78+
 79+ if( $dbw->tableExists( 'pagelinks' ) ) {
 80+ $this->output( "...have pagelinks; skipping old links table updates\n" );
 81+ return;
 82+ }
7483
7584 $res = $dbw->query( "SELECT l_from FROM $links LIMIT 1" );
7685 if ( $dbw->fieldType( $res, 0 ) == "int" ) {
@@ -172,22 +181,17 @@
173182 # --------------------------------------------------------------------
174183
175184 if ( $overwriteLinksTable ) {
176 - $dbConn = Database::newFromParams( $wgDBserver, $wgDBadminuser, $wgDBadminpassword, $wgDBname );
177 - if ( !( $dbConn->isOpen() ) ) {
178 - $this->output( "Opening connection to database failed.\n" );
179 - return;
180 - }
181185 # Check for existing links_backup, and delete it if it exists.
182186 $this->output( "Dropping backup links table if it exists..." );
183 - $dbConn->query( "DROP TABLE IF EXISTS $links_backup", DB_MASTER );
 187+ $dbw->query( "DROP TABLE IF EXISTS $links_backup", DB_MASTER );
184188 $this->output( " done.\n" );
185189
186190 # Swap in the new table, and move old links table to links_backup
187191 $this->output( "Swapping tables '$links' to '$links_backup'; '$links_temp' to '$links'..." );
188 - $dbConn->query( "RENAME TABLE links TO $links_backup, $links_temp TO $links", DB_MASTER );
 192+ $dbw->query( "RENAME TABLE links TO $links_backup, $links_temp TO $links", DB_MASTER );
189193 $this->output( " done.\n\n" );
190194
191 - $dbConn->close();
 195+ $dbw->close();
192196 $this->output( "Conversion complete. The old table remains at $links_backup;\n" );
193197 $this->output( "delete at your leisure.\n" );
194198 } else {
@@ -197,9 +201,8 @@
198202 }
199203
200204 private function createTempTable() {
201 - global $wgDBserver, $wgDBadminuser, $wgDBadminpassword, $wgDBname;
202205 global $noKeys;
203 - $dbConn = Database::newFromParams( $wgDBserver, $wgDBadminuser, $wgDBadminpassword, $wgDBname );
 206+ $dbConn = wfGetDB( DB_MASTER );
204207
205208 if ( !( $dbConn->isOpen() ) ) {
206209 $this->output( "Opening connection to database failed.\n" );

Follow-up revisions

RevisionCommit summaryAuthorDate
r71420Follow up r71359. $wgDBtype uneeded now.platonides22:11, 21 August 2010
r78245Per CR on r71359: Fix DB_MASTER where it should be __METHOD__demon15:29, 12 December 2010

Comments

#Comment by Platonides (talk | contribs)   22:07, 21 August 2010

This looks fragile. Have you tested it with an old install?

Wouldn't you be opening the connection as $wgDBuser instead of $wgDBadminuser?

What if it doesn't have permissions to create temporary tables?

I think that if there's an error connecting, you will be thrown an exception, not going via $dbConn->isOpen() branch.

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

Wouldn't you be opening the connection as $wgDBuser instead of $wgDBadminuser?

The getDbType() takes care of it.

#Comment by 😂 (talk | contribs)   19:30, 22 August 2010

> This looks fragile. Have you tested it with an old install?

Functionally, it hasn't changed. I just change calling conventions to wfGetDB(), which should work as expected in all modern versions of MW. We're not backporting it.

> Wouldn't you be opening the connection as $wgDBuser instead of $wgDBadminuser?

Nope, like you said.

> What if it doesn't have permissions to create temporary tables?

Then that's a general problem with the script and $wgDBadminuser. It didn't change with this commit.

> I think that if there's an error connecting, you will be thrown an exception, not going via $dbConn->isOpen() branch.

True, and it probably will already be handled somewhere in the DB class. The check to isOpen() can be safely removed IMO.

#Comment by Catrope (talk | contribs)   14:12, 12 December 2010
+			$dbw->query( "DROP TABLE IF EXISTS $links_backup", DB_MASTER );

This doesn't do what you think it does. $dbw was created to be a DB_MASTER connection, so you don't need to specify that again, and DatabaseBase::query() takes no such parameter. Instead, the second parameter is $fname. Seems to have been broken before this commit, though, so not a fixme.

#Comment by 😂 (talk | contribs)   15:30, 12 December 2010

Fixed in r78245.

Status & tagging log