--- /dev/null
+<?php\r
+/**\r
+ * Re-assign users from an old group to a new one\r
+ *\r
+ * This program is free software; you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation; either version 2 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License along\r
+ * with this program; if not, write to the Free Software Foundation, Inc.,\r
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.\r
+ * http://www.gnu.org/copyleft/gpl.html\r
+ *\r
+ * @ingroup Maintenance\r
+ */\r
+\r
+require_once( dirname(__FILE__) . '/Maintenance.php' );\r
+\r
+class MigrateUserGroup extends Maintenance {\r
+ public function __construct() {\r
+ parent::__construct();\r
+ $this->mDescription = "Re-assign users from an old group to a new one";\r
+ $this->addArg( 'oldgroup', 'Old user group key', true );\r
+ $this->addArg( 'newgroup', 'New user group key', true );\r
+ $this->setBatchSize( 200 );\r
+ }\r
+\r
+ public function execute() {\r
+ $count = 0;\r
+ $oldGroup = $this->getArg( 0 );\r
+ $newGroup = $this->getArg( 1 );\r
+ $dbr = wfGetDB( DB_SLAVE );\r
+ $start = $dbr->selectField( 'user_groups', 'MIN(ug_user)',\r
+ array('ug_group' => $oldGroup), __FUNCTION__ );\r
+ $end = $dbr->selectField( 'user_groups', 'MAX(ug_user)',\r
+ array('ug_group' => $oldGroup), __FUNCTION__ );\r
+ if( $start === null ) {\r
+ $this->error( "Nothing to do - no users in the '$oldGroup' group", true );\r
+ }\r
+ # Do remaining chunk\r
+ $end += $this->mBatchSize - 1;\r
+ $blockStart = $start;\r
+ $blockEnd = $start + $this->mBatchSize - 1;\r
+ // Migrate users over in batches...\r
+ $dbw = wfGetDB( DB_MASTER );\r
+ while( $blockEnd <= $end ) {\r
+ $this->output( "Doing users $blockStart to $blockEnd\n" );\r
+ $dbw->begin();\r
+ $dbw->update( 'user_groups',\r
+ array('ug_group' => $newGroup),\r
+ array('ug_group' => $oldGroup,\r
+ "ug_user BETWEEN $blockStart AND $blockEnd" )\r
+ );\r
+ $count += $dbw->affectedRows();\r
+ $dbw->commit();\r
+ $blockStart += $this->mBatchSize;\r
+ $blockEnd += $this->mBatchSize;\r
+ wfWaitForSlaves( 5 );\r
+ }\r
+ $this->output( "Done! $count user(s) in group '$oldGroup' are now in '$newGroup' instead.\n" );\r
+ }\r
+}\r
+\r
+$maintClass = "MigrateUserGroup";\r
+require_once( DO_MAINTENANCE );\r