From 9a1f1af9c1a052d05547c3ffdc1f77bb059e08e8 Mon Sep 17 00:00:00 2001 From: Alexandre Emsenhuber Date: Sun, 12 Sep 2010 15:32:30 +0000 Subject: [PATCH] Moved FiveUpgrade.inc to upgrade1_5.php and made FiveUpgrade extends Maintenance since nothing else is using this class Todo: maybe just remove this script entirely since it's useless for most people and parts of it are just broken, e.g. calls to wfImageDir() and wfImageArchiveDir() that were removed in r22580. --- maintenance/{FiveUpgrade.inc => upgrade1_5.php} | 138 ++++++++++++++---------- 1 file changed, 83 insertions(+), 55 deletions(-) rename maintenance/{FiveUpgrade.inc => upgrade1_5.php} (93%) diff --git a/maintenance/FiveUpgrade.inc b/maintenance/upgrade1_5.php similarity index 93% rename from maintenance/FiveUpgrade.inc rename to maintenance/upgrade1_5.php index fda34b9b1fe..e0e021424d1 100644 --- a/maintenance/FiveUpgrade.inc +++ b/maintenance/upgrade1_5.php @@ -1,10 +1,19 @@ 1.5 schema upgrade. + * This does only the main tables + UTF-8 and is designed to allow upgrades to + * interleave with other updates on the replication stream so that large wikis + * can be upgraded without disrupting other services. + * + * Note: this script DOES NOT apply every update, nor will it probably handle + * much older versions, etc. + * Run this, FOLLOWED BY update.php, for upgrading from 1.4.5 release to 1.5. + * * @file * @ingroup Maintenance */ -require_once( 'updaters.inc' ); +require_once( dirname( __FILE__ ) . '/Maintenance.php' ); define( 'MW_UPGRADE_COPY', false ); define( 'MW_UPGRADE_ENCODE', true ); @@ -14,25 +23,31 @@ define( 'MW_UPGRADE_CALLBACK', null ); // for self-documentation only /** * @ingroup Maintenance */ -class FiveUpgrade { - function FiveUpgrade() { - $this->conversionTables = $this->prepareWindows1252(); +class FiveUpgrade extends Maintenance { + function __construct() { + parent::__construct(); - $this->loadBalancers = array(); - $this->dbw = wfGetDB( DB_MASTER ); - $this->dbr = $this->streamConnection(); + $this->mDescription = 'Script for upgrades from 1.4 to 1.5 (NOT 1.15) in very special cases.'; - $this->cleanupSwaps = array(); - $this->emailAuth = false; # don't preauthenticate emails - $this->maxLag = 10; # if slaves are lagged more than 10 secs, wait + $this->addOption( 'upgrade', 'Really run the script' ); + $this->addOption( 'noimage', '' ); + $this->addOption( 'step', 'Only do a specific step', false, true ); } - function doing( $step ) { - return is_null( $this->step ) || $step == $this->step; + public function getDbType() { + return Maintenance::DB_ADMIN; } - function upgrade( $step ) { - $this->step = $step; + public function execute() { + $this->output( "ATTENTION: This script is for upgrades from 1.4 to 1.5 (NOT 1.15) in very special cases.\n" ); + $this->output( "Use update.php for usual updates.\n" ); + + if ( !$this->hasOption( 'upgrade' ) ) { + $this->output( "Please run this script with --upgrade key to actually run the updater.\n" ); + return; + } + + $this->setMembers(); $tables = array( 'page', @@ -47,7 +62,9 @@ class FiveUpgrade { 'categorylinks', 'ipblocks', 'recentchanges', - 'querycache' ); + 'querycache' + ); + foreach ( $tables as $table ) { if ( $this->doing( $table ) ) { $method = 'upgrade' . ucfirst( $table ); @@ -60,6 +77,22 @@ class FiveUpgrade { } } + protected function setMembers() { + $this->conversionTables = $this->prepareWindows1252(); + + $this->loadBalancers = array(); + $this->dbw = wfGetDB( DB_MASTER ); + $this->dbr = $this->streamConnection(); + + $this->cleanupSwaps = array(); + $this->emailAuth = false; # don't preauthenticate emails + $this->maxLag = 10; # if slaves are lagged more than 10 secs, wait + $this->step = $this->getOption( 'step', null ); + } + + function doing( $step ) { + return is_null( $this->step ) || $step == $this->step; + } /** * Open a connection to the master server with the admin rights. @@ -175,12 +208,11 @@ class FiveUpgrade { /** * Dump timestamp and message to output - * @param string $message + * @param $message String * @access private */ function log( $message ) { - echo wfWikiID() . ' ' . wfTimestamp( TS_DB ) . ': ' . $message . "\n"; - flush(); + $this->output( wfWikiID() . ' ' . wfTimestamp( TS_DB ) . ': ' . $message . "\n" ); } /** @@ -290,8 +322,6 @@ class FiveUpgrade { * @access private */ function copyTable( $name, $tabledef, $fields, $callback = null ) { - $fname = 'FiveUpgrade::copyTable'; - $name_temp = $name . '_temp'; $this->log( "Migrating $name table to $name_temp..." ); @@ -300,10 +330,10 @@ class FiveUpgrade { // Create temporary table; we're going to copy everything in there, // then at the end rename the final tables into place. $def = str_replace( '$1', $table_temp, $tabledef ); - $this->dbw->query( $def, $fname ); + $this->dbw->query( $def, __METHOD__ ); - $numRecords = $this->dbw->selectField( $name, 'COUNT(*)', '', $fname ); - $this->setChunkScale( 100, $numRecords, $name_temp, $fname ); + $numRecords = $this->dbw->selectField( $name, 'COUNT(*)', '', __METHOD__ ); + $this->setChunkScale( 100, $numRecords, $name_temp, __METHOD__ ); // Pull all records from the second, streaming database connection. $sourceFields = array_keys( array_filter( $fields, @@ -311,7 +341,7 @@ class FiveUpgrade { $result = $this->dbr->select( $name, $sourceFields, '', - $fname ); + __METHOD__ ); $add = array(); while ( $row = $this->dbr->fetchObject( $result ) ) { @@ -340,12 +370,10 @@ class FiveUpgrade { } function upgradePage() { - $fname = "FiveUpgrade::upgradePage"; $chunksize = 100; if ( $this->dbw->tableExists( 'page' ) ) { - $this->log( 'Page table already exists; aborting.' ); - die( -1 ); + $this->error( 'Page table already exists.', true ); } $this->log( "Checking cur table for unique title index and applying if necessary" ); @@ -373,7 +401,7 @@ class FiveUpgrade { UNIQUE INDEX name_title (page_namespace,page_title), INDEX (page_random), INDEX (page_len) - ) TYPE=InnoDB", $fname ); + ) TYPE=InnoDB", __METHOD__ ); $this->dbw->query( "CREATE TABLE $revision ( rev_id int(8) unsigned NOT NULL auto_increment, rev_page int(8) unsigned NOT NULL, @@ -391,9 +419,9 @@ class FiveUpgrade { INDEX page_timestamp (rev_page,rev_timestamp), INDEX user_timestamp (rev_user,rev_timestamp), INDEX usertext_timestamp (rev_user_text,rev_timestamp) - ) TYPE=InnoDB", $fname ); + ) TYPE=InnoDB", __METHOD__ ); - $maxold = intval( $this->dbw->selectField( 'old', 'max(old_id)', '', $fname ) ); + $maxold = intval( $this->dbw->selectField( 'old', 'max(old_id)', '', __METHOD__ ) ); $this->log( "Last old record is {$maxold}" ); global $wgLegacySchemaConversion; @@ -411,7 +439,7 @@ class FiveUpgrade { $cur_flags = "''"; } - $maxcur = $this->dbw->selectField( 'cur', 'max(cur_id)', '', $fname ); + $maxcur = $this->dbw->selectField( 'cur', 'max(cur_id)', '', __METHOD__ ); $this->log( "Last cur entry is $maxcur" ); /** @@ -420,12 +448,12 @@ class FiveUpgrade { * based on the flags (and may be originally binary!) while the meta * fields will be converted in the old -> rev and cur -> page steps. */ - $this->setChunkScale( $chunksize, $maxcur, 'old', $fname ); + $this->setChunkScale( $chunksize, $maxcur, 'old', __METHOD__ ); $result = $this->dbr->query( "SELECT cur_id, cur_namespace, cur_title, $cur_text AS text, cur_comment, cur_user, cur_user_text, cur_timestamp, cur_minor_edit, $cur_flags AS flags FROM $cur - ORDER BY cur_id", $fname ); + ORDER BY cur_id", __METHOD__ ); $add = array(); while ( $row = $this->dbr->fetchObject( $result ) ) { $add[] = array( @@ -446,18 +474,18 @@ class FiveUpgrade { * Copy revision metadata from old into revision. * We'll also do UTF-8 conversion of usernames and comments. */ - # $newmaxold = $this->dbw->selectField( 'old', 'max(old_id)', '', $fname ); - # $this->setChunkScale( $chunksize, $newmaxold, 'revision', $fname ); - # $countold = $this->dbw->selectField( 'old', 'count(old_id)', '', $fname ); - $countold = $this->dbw->selectField( 'old', 'max(old_id)', '', $fname ); - $this->setChunkScale( $chunksize, $countold, 'revision', $fname ); + # $newmaxold = $this->dbw->selectField( 'old', 'max(old_id)', '', __METHOD__ ); + # $this->setChunkScale( $chunksize, $newmaxold, 'revision', __METHOD__ ); + # $countold = $this->dbw->selectField( 'old', 'count(old_id)', '', __METHOD__ ); + $countold = $this->dbw->selectField( 'old', 'max(old_id)', '', __METHOD__ ); + $this->setChunkScale( $chunksize, $countold, 'revision', __METHOD__ ); $this->log( "......Setting up revision table." ); $result = $this->dbr->query( "SELECT old_id, cur_id, old_comment, old_user, old_user_text, old_timestamp, old_minor_edit FROM $old,$cur WHERE old_namespace=cur_namespace AND old_title=cur_title", - $fname ); + __METHOD__ ); $add = array(); while ( $row = $this->dbr->fetchObject( $result ) ) { @@ -480,13 +508,13 @@ class FiveUpgrade { * We'll also do UTF-8 conversion of titles. */ $this->log( "......Setting up page table." ); - $this->setChunkScale( $chunksize, $maxcur, 'page', $fname ); + $this->setChunkScale( $chunksize, $maxcur, 'page', __METHOD__ ); $result = $this->dbr->query( " SELECT cur_id, cur_namespace, cur_title, cur_restrictions, cur_counter, cur_is_redirect, cur_is_new, cur_random, cur_touched, rev_id, LENGTH(cur_text) AS len FROM $cur,$revision WHERE cur_id=rev_page AND rev_timestamp=cur_timestamp AND rev_id > {$maxold} - ORDER BY cur_id", $fname ); + ORDER BY cur_id", __METHOD__ ); $add = array(); while ( $row = $this->dbr->fetchObject( $result ) ) { $add[] = array( @@ -510,7 +538,6 @@ class FiveUpgrade { } function upgradeLinks() { - $fname = 'FiveUpgrade::upgradeLinks'; $chunksize = 200; list ( $links, $brokenlinks, $pagelinks, $cur ) = $this->dbw->tableNamesN( 'links', 'brokenlinks', 'pagelinks', 'cur' ); @@ -543,13 +570,13 @@ CREATE TABLE $pagelinks ( ) TYPE=InnoDB" ); $this->log( 'Importing live links -> pagelinks' ); - $nlinks = $this->dbw->selectField( 'links', 'count(*)', '', $fname ); + $nlinks = $this->dbw->selectField( 'links', 'count(*)', '', __METHOD__ ); if ( $nlinks ) { - $this->setChunkScale( $chunksize, $nlinks, 'pagelinks', $fname ); + $this->setChunkScale( $chunksize, $nlinks, 'pagelinks', __METHOD__ ); $result = $this->dbr->query( " SELECT l_from,cur_namespace,cur_title FROM $links, $cur - WHERE l_to=cur_id", $fname ); + WHERE l_to=cur_id", __METHOD__ ); $add = array(); while ( $row = $this->dbr->fetchObject( $result ) ) { $add[] = array( @@ -564,12 +591,12 @@ CREATE TABLE $pagelinks ( } $this->log( 'Importing brokenlinks -> pagelinks' ); - $nbrokenlinks = $this->dbw->selectField( 'brokenlinks', 'count(*)', '', $fname ); + $nbrokenlinks = $this->dbw->selectField( 'brokenlinks', 'count(*)', '', __METHOD__ ); if ( $nbrokenlinks ) { - $this->setChunkScale( $chunksize, $nbrokenlinks, 'pagelinks', $fname ); + $this->setChunkScale( $chunksize, $nbrokenlinks, 'pagelinks', __METHOD__ ); $result = $this->dbr->query( "SELECT bl_from, bl_to FROM $brokenlinks", - $fname ); + __METHOD__ ); $add = array(); while ( $row = $this->dbr->fetchObject( $result ) ) { $pagename = $this->conv( $row->bl_to ); @@ -690,8 +717,7 @@ END; } function imageCallback( $row, $copy ) { - global $options; - if ( !isset( $options['noimage'] ) ) { + if ( !$this->hasOption( 'noimage' ) ) { // Fill in the new image info fields $info = $this->imageInfo( $row->img_name ); @@ -839,7 +865,6 @@ END; function upgradeWatchlist() { - $fname = 'FiveUpgrade::upgradeWatchlist'; $chunksize = 100; list ( $watchlist, $watchlist_temp ) = $this->dbw->tableNamesN( 'watchlist', 'watchlist_temp' ); @@ -864,20 +889,20 @@ END; UNIQUE KEY (wl_user, wl_namespace, wl_title), KEY namespace_title (wl_namespace,wl_title) -) TYPE=InnoDB;", $fname ); +) TYPE=InnoDB;", __METHOD__ ); // Fix encoding for Latin-1 upgrades, add some fields, // and double article to article+talk pairs - $numwatched = $this->dbw->selectField( 'watchlist', 'count(*)', '', $fname ); + $numwatched = $this->dbw->selectField( 'watchlist', 'count(*)', '', __METHOD__ ); - $this->setChunkScale( $chunksize, $numwatched * 2, 'watchlist_temp', $fname ); + $this->setChunkScale( $chunksize, $numwatched * 2, 'watchlist_temp', __METHOD__ ); $result = $this->dbr->select( 'watchlist', array( 'wl_user', 'wl_namespace', 'wl_title' ), '', - $fname ); + __METHOD__ ); $add = array(); while ( $row = $this->dbr->fetchObject( $result ) ) { @@ -1276,3 +1301,6 @@ END } } + +$maintClass = 'FiveUpgrade'; +require( DO_MAINTENANCE ); -- 2.11.4.GIT