From: Aaron Schulz Date: Tue, 1 Sep 2009 20:53:55 +0000 (+0000) Subject: Added a script to move users from one group to another X-Git-Tag: 1.31.0-rc.0~39977 X-Git-Url: http://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/exercices/?a=commitdiff_plain;h=c578da64afb6b488bb7869fb08635d629b9c34a7;p=lhc%2Fweb%2Fwiklou.git Added a script to move users from one group to another --- diff --git a/maintenance/migrateUserGroup.php b/maintenance/migrateUserGroup.php new file mode 100644 index 0000000000..9ac70d110f --- /dev/null +++ b/maintenance/migrateUserGroup.php @@ -0,0 +1,71 @@ +mDescription = "Re-assign users from an old group to a new one"; + $this->addArg( 'oldgroup', 'Old user group key', true ); + $this->addArg( 'newgroup', 'New user group key', true ); + $this->setBatchSize( 200 ); + } + + public function execute() { + $count = 0; + $oldGroup = $this->getArg( 0 ); + $newGroup = $this->getArg( 1 ); + $dbr = wfGetDB( DB_SLAVE ); + $start = $dbr->selectField( 'user_groups', 'MIN(ug_user)', + array('ug_group' => $oldGroup), __FUNCTION__ ); + $end = $dbr->selectField( 'user_groups', 'MAX(ug_user)', + array('ug_group' => $oldGroup), __FUNCTION__ ); + if( $start === null ) { + $this->error( "Nothing to do - no users in the '$oldGroup' group", true ); + } + # Do remaining chunk + $end += $this->mBatchSize - 1; + $blockStart = $start; + $blockEnd = $start + $this->mBatchSize - 1; + // Migrate users over in batches... + $dbw = wfGetDB( DB_MASTER ); + while( $blockEnd <= $end ) { + $this->output( "Doing users $blockStart to $blockEnd\n" ); + $dbw->begin(); + $dbw->update( 'user_groups', + array('ug_group' => $newGroup), + array('ug_group' => $oldGroup, + "ug_user BETWEEN $blockStart AND $blockEnd" ) + ); + $count += $dbw->affectedRows(); + $dbw->commit(); + $blockStart += $this->mBatchSize; + $blockEnd += $this->mBatchSize; + wfWaitForSlaves( 5 ); + } + $this->output( "Done! $count user(s) in group '$oldGroup' are now in '$newGroup' instead.\n" ); + } +} + +$maintClass = "MigrateUserGroup"; +require_once( DO_MAINTENANCE );