Index: trunk/extensions/Narayam/maintenance/FixNarayamDisablePref.php |
— | — | @@ -0,0 +1,57 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +// Standard boilerplate to define $IP |
| 5 | +if ( getenv( 'MW_INSTALL_PATH' ) !== false ) { |
| 6 | + $IP = getenv( 'MW_INSTALL_PATH' ); |
| 7 | +} else { |
| 8 | + $dir = dirname( __FILE__ ); $IP = "$dir/../../.."; |
| 9 | +} |
| 10 | +require_once( "$IP/maintenance/Maintenance.php" ); |
| 11 | + |
| 12 | +class FixNarayamDisablePref extends Maintenance { |
| 13 | + function __construct() { |
| 14 | + parent::__construct(); |
| 15 | + } |
| 16 | + |
| 17 | + function execute() { |
| 18 | + $dbw = wfGetDB( DB_MASTER ); |
| 19 | + |
| 20 | + $table = 'user_properties'; |
| 21 | + $oldPropName = 'narayamDisable'; |
| 22 | + $newPropName = 'narayamEnable'; |
| 23 | + echo "Fixing $oldPropName to $newPropName\n"; |
| 24 | + |
| 25 | + $batchSize = 100; |
| 26 | + $allIds = array(); |
| 27 | + while ( true ) { |
| 28 | + $dbw->begin(); |
| 29 | + $res = $dbw->select( |
| 30 | + $table, |
| 31 | + array( 'up_user' ), |
| 32 | + array( 'up_property' => $oldPropName, 'up_value' => 1 ), |
| 33 | + __METHOD__, |
| 34 | + array( 'LIMIT' => $batchSize, 'FOR UPDATE' ) ); |
| 35 | + if ( !$res->numRows() ) { |
| 36 | + $dbw->commit(); |
| 37 | + break; |
| 38 | + } |
| 39 | + |
| 40 | + $ids = array(); |
| 41 | + foreach ( $res as $row ) { |
| 42 | + $ids[] = $row->up_user; |
| 43 | + } |
| 44 | + $dbw->update( |
| 45 | + $table, |
| 46 | + array( 'up_property' => $newPropName, 'up_value' => 0 ), |
| 47 | + array( 'up_property' => $oldPropName, 'up_user' => $ids ), |
| 48 | + __METHOD__ ); |
| 49 | + |
| 50 | + wfWaitForSlaves( 10 ); |
| 51 | + } |
| 52 | + |
| 53 | + echo "Done\n"; |
| 54 | + } |
| 55 | +} |
| 56 | + |
| 57 | +$maintClass = 'FixNarayamDisablePref'; |
| 58 | +require_once( RUN_MAINTENANCE_IF_MAIN ); |
Property changes on: trunk/extensions/Narayam/maintenance/FixNarayamDisablePref.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 59 | + native |