Index: trunk/extensions/Vector/switchExperimentPrefs.php |
— | — | @@ -0,0 +1,64 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +$path = '../..'; |
| 5 | + |
| 6 | +if ( getenv( 'MW_INSTALL_PATH' ) !== false ) { |
| 7 | + $path = getenv( 'MW_INSTALL_PATH' ); |
| 8 | +} |
| 9 | + |
| 10 | +require_once( $path . '/maintenance/Maintenance.php' ); |
| 11 | + |
| 12 | +class SwitchExperimentPrefs extends Maintenance { |
| 13 | + function __construct() { |
| 14 | + parent::__construct(); |
| 15 | + $this->addOption( 'pref', 'Preference to set', true, true ); |
| 16 | + $this->addOption( 'value', 'Value to set the preference to', true, true ); |
| 17 | + $this->mDescription = 'Set a preference for all users that have the vector-noexperiments preference enabled.'; |
| 18 | + } |
| 19 | + |
| 20 | + function execute() { |
| 21 | + $dbw = wfGetDB( DB_MASTER ); |
| 22 | + |
| 23 | + $batchSize = 100; |
| 24 | + $total = 0; |
| 25 | + $lastUserID = 0; |
| 26 | + while ( true ) { |
| 27 | + $dbw->begin(); |
| 28 | + $res = $dbw->select( 'user_properties', array( 'up_user' ), |
| 29 | + array( 'up_property' => 'vector-noexperiments', "up_user > $lastUserID" ), |
| 30 | + __METHOD__, |
| 31 | + array( 'LIMIT' => $batchSize ) ); |
| 32 | + if ( !$res->numRows() ) { |
| 33 | + $dbw->commit(); |
| 34 | + break; |
| 35 | + } |
| 36 | + $total += $res->numRows(); |
| 37 | + |
| 38 | + $ids = array(); |
| 39 | + foreach ( $res as $row ) { |
| 40 | + $ids[] = $row->up_user; |
| 41 | + } |
| 42 | + $lastUserID = max( $ids ); |
| 43 | + |
| 44 | + |
| 45 | + foreach ( $ids as $id ) { |
| 46 | + $user = User::newFromId( $id ); |
| 47 | + if ( !$user->isLoggedIn() ) |
| 48 | + continue; |
| 49 | + $user->setOption( $this->getOption( 'pref' ), $this->getOption( 'value' ) ); |
| 50 | + $user->saveSettings(); |
| 51 | + } |
| 52 | + |
| 53 | + echo "$total\n"; |
| 54 | + |
| 55 | + wfWaitForSlaves(); // Must be wfWaitForSlaves_masterPos(); on 1.17wmf1 |
| 56 | + } |
| 57 | + echo "Done\n"; |
| 58 | + |
| 59 | + } |
| 60 | +} |
| 61 | + |
| 62 | +$maintClass = 'SwitchExperimentPrefs'; |
| 63 | +require_once( DO_MAINTENANCE ); |
| 64 | + |
| 65 | + |
Property changes on: trunk/extensions/Vector/switchExperimentPrefs.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 66 | + native |