00001 <?php
00023 require_once( dirname(__FILE__) . '/Maintenance.php' );
00024
00025 class MigrateUserGroup extends Maintenance {
00026 public function __construct() {
00027 parent::__construct();
00028 $this->mDescription = "Re-assign users from an old group to a new one";
00029 $this->addArg( 'oldgroup', 'Old user group key', true );
00030 $this->addArg( 'newgroup', 'New user group key', true );
00031 $this->setBatchSize( 200 );
00032 }
00033
00034 public function execute() {
00035 $count = 0;
00036 $oldGroup = $this->getArg( 0 );
00037 $newGroup = $this->getArg( 1 );
00038 $dbw = wfGetDB( DB_MASTER );
00039 $start = $dbw->selectField( 'user_groups', 'MIN(ug_user)',
00040 array('ug_group' => $oldGroup), __FUNCTION__ );
00041 $end = $dbw->selectField( 'user_groups', 'MAX(ug_user)',
00042 array('ug_group' => $oldGroup), __FUNCTION__ );
00043 if( $start === null ) {
00044 $this->error( "Nothing to do - no users in the '$oldGroup' group", true );
00045 }
00046 # Do remaining chunk
00047 $end += $this->mBatchSize - 1;
00048 $blockStart = $start;
00049 $blockEnd = $start + $this->mBatchSize - 1;
00050
00051 while( $blockEnd <= $end ) {
00052 $this->output( "Doing users $blockStart to $blockEnd\n" );
00053 $dbw->begin();
00054 $dbw->update( 'user_groups',
00055 array('ug_group' => $newGroup),
00056 array('ug_group' => $oldGroup,
00057 "ug_user BETWEEN $blockStart AND $blockEnd" )
00058 );
00059 $count += $dbw->affectedRows();
00060 $dbw->commit();
00061 $blockStart += $this->mBatchSize;
00062 $blockEnd += $this->mBatchSize;
00063 wfWaitForSlaves( 5 );
00064 }
00065 $this->output( "Done! $count user(s) in group '$oldGroup' are now in '$newGroup' instead.\n" );
00066 }
00067 }
00068
00069 $maintClass = "MigrateUserGroup";
00070 require_once( DO_MAINTENANCE );