MediaWiki r9631 - Code Review

Jump to: navigation, search
Repository:MediaWiki
Revision:r9630‎ | r9631 (on ViewVC)‎ | r9632 >
Date:06:04, 25 June 2005
Author:vibber
Status:old
Tags:
Comment:
* watchlist conversion (utf8 and namespace doubling)
* fix cleanup
* --step option to test only one conversion step
Modified paths:

Diff [purge]

Index: trunk/phase3/maintenance/upgrade1_5.php
@@ -12,13 +12,16 @@
1313 // Run this, FOLLOWED BY update.php, for upgrading
1414 // from 1.4.5 release to 1.5.
1515
 16+$options = array( 'step' );
 17+
1618 require_once( 'commandLine.inc' );
1719 require_once( 'cleanupDupes.inc' );
1820 require_once( 'userDupes.inc' );
1921 require_once( 'updaters.inc' );
2022
2123 $upgrade = new FiveUpgrade();
22 -$upgrade->upgrade();
 24+$step = isset( $options['step'] ) ? $options['step'] : null;
 25+$upgrade->upgrade( $step );
2326
2427 class FiveUpgrade {
2528 function FiveUpgrade() {
@@ -29,14 +32,27 @@
3033 $this->dbr->bufferResults( false );
3134 }
3235
33 - function upgrade() {
34 - $this->upgradePage();
35 - $this->upgradeLinks();
36 - $this->upgradeUser();
37 - $this->upgradeImage();
38 - $this->upgradeOldImage();
 36+ function doing( $step ) {
 37+ return is_null( $this->step ) || $step == $this->step;
 38+ }
 39+
 40+ function upgrade( $step ) {
 41+ $this->step = $step;
 42+ if( $this->doing( 'page' ) )
 43+ $this->upgradePage();
 44+ if( $this->doing( 'links' ) )
 45+ $this->upgradeLinks();
 46+ if( $this->doing( 'user' ) )
 47+ $this->upgradeUser();
 48+ if( $this->doing( 'image' ) )
 49+ $this->upgradeImage();
 50+ if( $this->doing( 'oldimage' ) )
 51+ $this->upgradeOldImage();
 52+ if( $this->doing( 'watchlist' ) )
 53+ $this->upgradeWatchlist();
3954
40 - $this->upgradeCleanup();
 55+ if( $this->doing( 'cleanup' ) )
 56+ $this->upgradeCleanup();
4157 }
4258
4359
@@ -793,28 +809,99 @@
794810 $this->log( 'done with oldimage table.' );
795811 }
796812
 813+
 814+ function upgradeWatchlist() {
 815+ $fname = 'FiveUpgrade::upgradeWatchlist';
 816+ $chunksize = 100;
 817+
 818+ extract( $this->dbw->tableNames( 'watchlist', 'watchlist_temp' ) );
 819+
 820+ $this->log( 'Migrating watchlist table to watchlist_temp...' );
 821+ $this->dbw->query(
 822+"CREATE TABLE $watchlist_temp (
 823+ -- Key to user_id
 824+ wl_user int(5) unsigned NOT NULL,
 825+
 826+ -- Key to page_namespace/page_title
 827+ -- Note that users may watch patches which do not exist yet,
 828+ -- or existed in the past but have been deleted.
 829+ wl_namespace int NOT NULL default '0',
 830+ wl_title varchar(255) binary NOT NULL default '',
 831+
 832+ -- Timestamp when user was last sent a notification e-mail;
 833+ -- cleared when the user visits the page.
 834+ -- FIXME: add proper null support etc
 835+ wl_notificationtimestamp varchar(14) binary NOT NULL default '0',
 836+
 837+ UNIQUE KEY (wl_user, wl_namespace, wl_title),
 838+ KEY namespace_title (wl_namespace,wl_title)
 839+
 840+) TYPE=InnoDB;", $fname );
 841+
 842+ // Fix encoding for Latin-1 upgrades, add some fields,
 843+ // and double article to article+talk pairs
 844+ $numwatched = $this->dbw->selectField( 'watchlist', 'count(*)', '', $fname );
 845+
 846+ $this->setChunkScale( $chunksize, $numwatched * 2, 'watchlist_temp', $fname );
 847+ $result = $this->dbr->select( 'watchlist',
 848+ array(
 849+ 'wl_user',
 850+ 'wl_namespace',
 851+ 'wl_title' ),
 852+ '',
 853+ $fname );
 854+
 855+ $add = array();
 856+ while( $row = $this->dbr->fetchObject( $result ) ) {
 857+ $now = $this->dbw->timestamp();
 858+ $add[] = array(
 859+ 'wl_user' => $row->wl_user,
 860+ 'wl_namespace' => Namespace::getSubject( $row->wl_namespace ),
 861+ 'wl_title' => $this->conv( $row->wl_title ),
 862+ 'wl_notificationtimestamp' => '0' );
 863+ $this->addChunk( $add );
 864+
 865+ $add[] = array(
 866+ 'wl_user' => $row->wl_user,
 867+ 'wl_namespace' => Namespace::getTalk( $row->wl_namespace ),
 868+ 'wl_title' => $this->conv( $row->wl_title ),
 869+ 'wl_notificationtimestamp' => '0' );
 870+ $this->addChunk( $add );
 871+ }
 872+ $this->lastChunk( $add );
 873+ $this->dbr->freeResult( $result );
 874+
 875+ $this->log( 'Done converting watchlist.' );
 876+ }
 877+
 878+
797879 /**
798880 * Rename all our temporary tables into final place.
799881 * We've left things in place so a read-only wiki can continue running
800882 * on the old code during all this.
801883 */
802884 function upgradeCleanup() {
803 - $this->log( "Renaming old to text..." );
804 - $this->dbw->query( "ALTER TABLE $old RENAME TO $text", $fname );
 885+ $this->renameTable( 'old', 'text' );
805886
806 - $this->log( 'Renaming user to user_old and user_temp to user...' );
807 - $this->dbw->query( "ALTER TABLE $user RENAME TO $user_old" );
808 - $this->dbw->query( "ALTER TABLE $user_temp RENAME TO $user" );
809 -
810 - $this->log( 'Renaming image to image_old and image_temp to image...' );
811 - $this->dbw->query( "ALTER TABLE $image RENAME TO $image_old" );
812 - $this->dbw->query( "ALTER TABLE $image_temp RENAME TO $image" );
813 -
814 - $this->log( 'Renaming oldimage to oldimage_old and oldimage_temp to oldimage...' );
815 - $this->dbw->query( "ALTER TABLE $oldimage RENAME TO $oldimage_old" );
816 - $this->dbw->query( "ALTER TABLE $oldimage_temp RENAME TO $oldimage" );
 887+ $this->swap( 'user' );
 888+ $this->swap( 'image' );
 889+ $this->swap( 'oldimage' );
 890+ $this->swap( 'watchlist' );
817891 }
818892
 893+ function renameTable( $from, $to ) {
 894+ $this->log( 'Renaming $from to $to...' );
 895+
 896+ $fromtable = $this->dbw->tableName( $from );
 897+ $totable = $this->dbw->tableName( $to );
 898+ $this->dbw->query( "ALTER TABLE $fromtable RENAME TO $totable" );
 899+ }
 900+
 901+ function swap( $base ) {
 902+ $this->renameTable( $base, "{$base}_old" );
 903+ $this->renameTable( "{$base}_temp", $base );
 904+ }
 905+
819906 }
820907
821908 ?>
\ No newline at end of file

Status & tagging log

  • 15:03, 12 September 2011 Meno25 (Talk | contribs) changed the status of r9631 [removed: ok added: old]
  • 14:05, 18 June 2009 ^demon (Talk | contribs) changed the status of r9631 [removed: new added: ok]
Personal tools
Namespaces

Variants
Views
Actions
Navigation
Support
Download
Development
Communication
Toolbox