| Index: trunk/phase3/maintenance/upgrade1_5.php |
| — | — | @@ -12,13 +12,16 @@ |
| 13 | 13 | // Run this, FOLLOWED BY update.php, for upgrading |
| 14 | 14 | // from 1.4.5 release to 1.5. |
| 15 | 15 | |
| | 16 | +$options = array( 'step' ); |
| | 17 | + |
| 16 | 18 | require_once( 'commandLine.inc' ); |
| 17 | 19 | require_once( 'cleanupDupes.inc' ); |
| 18 | 20 | require_once( 'userDupes.inc' ); |
| 19 | 21 | require_once( 'updaters.inc' ); |
| 20 | 22 | |
| 21 | 23 | $upgrade = new FiveUpgrade(); |
| 22 | | -$upgrade->upgrade(); |
| | 24 | +$step = isset( $options['step'] ) ? $options['step'] : null; |
| | 25 | +$upgrade->upgrade( $step ); |
| 23 | 26 | |
| 24 | 27 | class FiveUpgrade { |
| 25 | 28 | function FiveUpgrade() { |
| — | — | @@ -29,14 +32,27 @@ |
| 30 | 33 | $this->dbr->bufferResults( false ); |
| 31 | 34 | } |
| 32 | 35 | |
| 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(); |
| 39 | 54 | |
| 40 | | - $this->upgradeCleanup(); |
| | 55 | + if( $this->doing( 'cleanup' ) ) |
| | 56 | + $this->upgradeCleanup(); |
| 41 | 57 | } |
| 42 | 58 | |
| 43 | 59 | |
| — | — | @@ -793,28 +809,99 @@ |
| 794 | 810 | $this->log( 'done with oldimage table.' ); |
| 795 | 811 | } |
| 796 | 812 | |
| | 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 | + |
| 797 | 879 | /** |
| 798 | 880 | * Rename all our temporary tables into final place. |
| 799 | 881 | * We've left things in place so a read-only wiki can continue running |
| 800 | 882 | * on the old code during all this. |
| 801 | 883 | */ |
| 802 | 884 | 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' ); |
| 805 | 886 | |
| 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' ); |
| 817 | 891 | } |
| 818 | 892 | |
| | 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 | + |
| 819 | 906 | } |
| 820 | 907 | |
| 821 | 908 | ?> |
| \ No newline at end of file |