Fix whitespace; change tabs to spaces.
[lhc/web/wiklou.git] / maintenance / migrateUserGroup.php
index 9ac70d1..297aaf3 100644 (file)
@@ -1,71 +1,70 @@
-<?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
+<?php
+/**
+ * Re-assign users from an old group to a new one
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @ingroup Maintenance
+ */
+
+require_once( dirname( __FILE__ ) . '/Maintenance.php' );
+
+class MigrateUserGroup extends Maintenance {
+       public function __construct() {
+               parent::__construct();
+               $this->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 );
+               $dbw = wfGetDB( DB_MASTER );
+               $start = $dbw->selectField( 'user_groups', 'MIN(ug_user)',
+                       array( 'ug_group' => $oldGroup ), __FUNCTION__ );
+               $end = $dbw->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...
+               while ( $blockEnd <= $end ) {
+                       $this->output( "Doing users $blockStart to $blockEnd\n" );
+                       $dbw->begin( __METHOD__ );
+                       $dbw->update( 'user_groups',
+                               array( 'ug_group' => $newGroup ),
+                               array( 'ug_group' => $oldGroup,
+                                       "ug_user BETWEEN $blockStart AND $blockEnd" )
+                       );
+                       $count += $dbw->affectedRows();
+                       $dbw->commit( __METHOD__ );
+                       $blockStart += $this->mBatchSize;
+                       $blockEnd += $this->mBatchSize;
+                       wfWaitForSlaves();
+               }
+               $this->output( "Done! $count user(s) in group '$oldGroup' are now in '$newGroup' instead.\n" );
+       }
+}
+
+$maintClass = "MigrateUserGroup";
+require_once( RUN_MAINTENANCE_IF_MAIN );