| Index: branches/wmf/1.17wmf1/maintenance/wmf/fixUsabilityPrefs2.php |
| — | — | @@ -0,0 +1,118 @@ |
| | 2 | +<?php |
| | 3 | + |
| | 4 | +require( dirname( __FILE__ ) . '/../Maintenance.php' ); |
| | 5 | + |
| | 6 | +class FixUsabilityPrefs extends Maintenance { |
| | 7 | + function __construct() { |
| | 8 | + parent::__construct(); |
| | 9 | + } |
| | 10 | + |
| | 11 | + function execute() { |
| | 12 | + $dbw = wfGetDB( DB_MASTER ); |
| | 13 | + |
| | 14 | + echo "Fixing usebetatoolbar\n"; |
| | 15 | + |
| | 16 | + $batchSize = 100; |
| | 17 | + $allIds = array(); |
| | 18 | + while ( true ) { |
| | 19 | + $dbw->begin(); |
| | 20 | + $res = $dbw->select( 'user_properties', array( 'up_user' ), |
| | 21 | + array( 'up_property' => 'usebetatoolbar', 'up_value' => '' ), |
| | 22 | + __METHOD__, |
| | 23 | + array( 'LIMIT' => $batchSize, 'FOR UPDATE' ) ); |
| | 24 | + if ( !$res->numRows() ) { |
| | 25 | + $dbw->commit(); |
| | 26 | + break; |
| | 27 | + } |
| | 28 | + |
| | 29 | + $ids = array(); |
| | 30 | + foreach ( $res as $row ) { |
| | 31 | + $ids[] = $row->up_user; |
| | 32 | + } |
| | 33 | + $dbw->update( 'user_properties', array( 'up_value' => 0 ), |
| | 34 | + array( 'up_property' => 'usebetatoolbar', 'up_user' => $ids ), |
| | 35 | + __METHOD__ ); |
| | 36 | + $dbw->commit(); |
| | 37 | + $allIds = array_merge( $allIds, $ids ); |
| | 38 | + wfWaitForSlaves( 10 ); |
| | 39 | + } |
| | 40 | + |
| | 41 | + echo "Fixing wikieditor-*\n"; |
| | 42 | + |
| | 43 | + $likeWikieditor = $dbw->buildLike( 'wikieditor-', $dbw->anyString() ); |
| | 44 | + while ( true ) { |
| | 45 | + $dbw->begin(); |
| | 46 | + $res = $dbw->select( 'user_properties', array( 'DISTINCT up_user' ), |
| | 47 | + array( "up_property $likeWikieditor" ), |
| | 48 | + __METHOD__, |
| | 49 | + array( 'LIMIT' => $batchSize, 'FOR UPDATE' ) ); |
| | 50 | + if ( !$res->numRows() ) { |
| | 51 | + $dbw->commit(); |
| | 52 | + break; |
| | 53 | + } |
| | 54 | + |
| | 55 | + $ids = array(); |
| | 56 | + foreach ( $res as $row ) { |
| | 57 | + $ids[] = $row->up_user; |
| | 58 | + } |
| | 59 | + $dbw->delete( 'user_properties', |
| | 60 | + array( "up_property $likeWikieditor", 'up_user' => $ids ), |
| | 61 | + __METHOD__ ); |
| | 62 | + $dbw->commit(); |
| | 63 | + $allIds = array_merge( $allIds, $ids ); |
| | 64 | + wfWaitForSlaves( 10 ); |
| | 65 | + } |
| | 66 | + |
| | 67 | + $allIds = array_unique( $allIds ); |
| | 68 | + |
| | 69 | + echo "Fixing usenavigabletoc\n"; |
| | 70 | + |
| | 71 | + while ( true ) { |
| | 72 | + $dbw->begin(); |
| | 73 | + $res = $dbw->select( 'user_properties', array( 'DISTINCT up_user' ), |
| | 74 | + array( "up_property" => "usenavigabletoc" ), |
| | 75 | + __METHOD__, |
| | 76 | + array( 'LIMIT' => $batchSize, 'FOR UPDATE' ) ); |
| | 77 | + if ( !$res->numRows() ) { |
| | 78 | + $dbw->commit(); |
| | 79 | + break; |
| | 80 | + } |
| | 81 | + |
| | 82 | + $ids = array(); |
| | 83 | + foreach ( $res as $row ) { |
| | 84 | + $ids[] = $row->up_user; |
| | 85 | + } |
| | 86 | + $dbw->delete( 'user_properties', |
| | 87 | + array( "up_property" => "usenavigabletoc", 'up_user' => $ids ), |
| | 88 | + __METHOD__ ); |
| | 89 | + $dbw->commit(); |
| | 90 | + $allIds = array_merge( $allIds, $ids ); |
| | 91 | + wfWaitForSlaves( 10 ); |
| | 92 | + } |
| | 93 | + |
| | 94 | + |
| | 95 | + echo "Invalidating user cache\n"; |
| | 96 | + $i = 0; |
| | 97 | + foreach ( $allIds as $id ) { |
| | 98 | + $user = User::newFromId( $id ); |
| | 99 | + if ( !$user->isLoggedIn() ) { |
| | 100 | + continue; |
| | 101 | + } |
| | 102 | + $dbw->begin(); |
| | 103 | + $user->invalidateCache(); |
| | 104 | + $dbw->commit(); |
| | 105 | + $i++; |
| | 106 | + if ( $i % 1000 == 0 ) { |
| | 107 | + wfWaitForSlaves( 10 ); |
| | 108 | + } |
| | 109 | + } |
| | 110 | + |
| | 111 | + echo "Done\n"; |
| | 112 | + |
| | 113 | + } |
| | 114 | +} |
| | 115 | + |
| | 116 | +$maintClass = 'FixUsabilityPrefs'; |
| | 117 | +require_once( DO_MAINTENANCE ); |
| | 118 | + |
| | 119 | + |