From 51eab6f557ee3fd249eeb582e449e2faf9d6f8fa Mon Sep 17 00:00:00 2001 From: Chad Horohoe Date: Fri, 20 Aug 2010 14:47:57 +0000 Subject: [PATCH] Refactor convertLinks to not use DB::newFromParams() crap, make updaters use the maintenance script to reduce duplication, other minor fixes --- maintenance/convertLinks.php | 37 +++++++++++++++++++----------------- maintenance/updaters.inc | 11 +++++------ 2 files changed, 25 insertions(+), 23 deletions(-) diff --git a/maintenance/convertLinks.php b/maintenance/convertLinks.php index af10e51b2f..0edfa131d9 100644 --- a/maintenance/convertLinks.php +++ b/maintenance/convertLinks.php @@ -31,17 +31,22 @@ class ConvertLinks extends Maintenance { The wiki should be put into read-only mode while this script executes"; } + public function getDbType() { + return self::DB_ADMIN; + } + public function execute() { global $wgDBtype; - if ( $wgDBtype == 'postgres' ) { - $this->output( "Links table already ok on Postgres.\n" ); + + $dbw = wfGetDB( DB_MASTER ); + + $type = $dbw->getType(); + if ( $type != 'mysql' ) { + $this->output( "Link table conversion not necessary for $type\n" ); return; } - $this->output( "Converting links table to ID-ID...\n" ); - - global $wgLang, $wgDBserver, $wgDBadminuser, $wgDBadminpassword, $wgDBname; - global $noKeys, $logPerformance, $fh; + global $wgLang, $noKeys, $logPerformance, $fh; $tuplesAdded = $numBadLinks = $curRowsRead = 0; # counters etc $totalTuplesInserted = 0; # total tuples INSERTed into links_temp @@ -68,8 +73,12 @@ The wiki should be put into read-only mode while this script executes"; $perfLogFilename = "convLinksPerf.txt"; # -------------------------------------------------------------------- - $dbw = wfGetDB( DB_MASTER ); list ( $cur, $links, $links_temp, $links_backup ) = $dbw->tableNamesN( 'cur', 'links', 'links_temp', 'links_backup' ); + + if( $dbw->tableExists( 'pagelinks' ) ) { + $this->output( "...have pagelinks; skipping old links table updates\n" ); + return; + } $res = $dbw->query( "SELECT l_from FROM $links LIMIT 1" ); if ( $dbw->fieldType( $res, 0 ) == "int" ) { @@ -172,22 +181,17 @@ The wiki should be put into read-only mode while this script executes"; # -------------------------------------------------------------------- if ( $overwriteLinksTable ) { - $dbConn = Database::newFromParams( $wgDBserver, $wgDBadminuser, $wgDBadminpassword, $wgDBname ); - if ( !( $dbConn->isOpen() ) ) { - $this->output( "Opening connection to database failed.\n" ); - return; - } # Check for existing links_backup, and delete it if it exists. $this->output( "Dropping backup links table if it exists..." ); - $dbConn->query( "DROP TABLE IF EXISTS $links_backup", DB_MASTER ); + $dbw->query( "DROP TABLE IF EXISTS $links_backup", DB_MASTER ); $this->output( " done.\n" ); # Swap in the new table, and move old links table to links_backup $this->output( "Swapping tables '$links' to '$links_backup'; '$links_temp' to '$links'..." ); - $dbConn->query( "RENAME TABLE links TO $links_backup, $links_temp TO $links", DB_MASTER ); + $dbw->query( "RENAME TABLE links TO $links_backup, $links_temp TO $links", DB_MASTER ); $this->output( " done.\n\n" ); - $dbConn->close(); + $dbw->close(); $this->output( "Conversion complete. The old table remains at $links_backup;\n" ); $this->output( "delete at your leisure.\n" ); } else { @@ -197,9 +201,8 @@ The wiki should be put into read-only mode while this script executes"; } private function createTempTable() { - global $wgDBserver, $wgDBadminuser, $wgDBadminpassword, $wgDBname; global $noKeys; - $dbConn = Database::newFromParams( $wgDBserver, $wgDBadminuser, $wgDBadminpassword, $wgDBname ); + $dbConn = wfGetDB( DB_MASTER ); if ( !( $dbConn->isOpen() ) ) { $this->output( "Opening connection to database failed.\n" ); diff --git a/maintenance/updaters.inc b/maintenance/updaters.inc index 56e7aea59b..ca18457311 100644 --- a/maintenance/updaters.inc +++ b/maintenance/updaters.inc @@ -9,7 +9,6 @@ if ( !defined( 'MEDIAWIKI' ) ) { exit( 1 ); } -require_once 'convertLinks.inc'; require_once 'userDupes.inc'; # Extension updates require_once( "$IP/includes/Hooks.php" ); @@ -514,12 +513,12 @@ function do_drop_img_type() { } function do_old_links_update() { - global $wgDatabase; - if ( $wgDatabase->tableExists( 'pagelinks' ) ) { - wfOut( "...have pagelinks; skipping old links table updates.\n" ); - } else { - convertLinks(); flush(); + if( !defined( 'MW_NO_SETUP' ) ) { + define( 'MW_NO_SETUP', true ); } + require( "convertLinks.php" ); + $cl = new ConvertLinks(); + $cl->execute(); } function fix_ancient_imagelinks() { -- 2.20.1