Update migrateUserGroup to deal with primary key issue
authorMark A. Hershberger <mah@everybody.org>
Wed, 20 Jun 2012 19:52:58 +0000 (15:52 -0400)
committerMax Semenik <maxsem.wiki@gmail.com>
Fri, 29 Jun 2012 19:39:25 +0000 (23:39 +0400)
Update migrateUserGroup so that if a user is in both the old group and
the new group, the script still succeeds.  Otherwise, it will fail
with violations to the PRIMARY KEY index on the user_groups table.

Change-Id: I7bfda03f5735633d03b81092dad29d73293cd182

maintenance/migrateUserGroup.php

index 297aaf3..e6eea66 100644 (file)
@@ -54,7 +54,15 @@ class MigrateUserGroup extends Maintenance {
                        $dbw->update( 'user_groups',
                                array( 'ug_group' => $newGroup ),
                                array( 'ug_group' => $oldGroup,
-                                       "ug_user BETWEEN $blockStart AND $blockEnd" )
+                                       "ug_user BETWEEN $blockStart AND $blockEnd" ),
+                               __METHOD__,
+                               array( 'IGNORE' )
+                       );
+                       $count += $dbw->affectedRows();
+                       $dbw->delete( 'user_groups',
+                               array( 'ug_group' => $oldGroup,
+                                       "ug_user BETWEEN $blockStart AND $blockEnd" ),
+                               __METHOD__
                        );
                        $count += $dbw->affectedRows();
                        $dbw->commit( __METHOD__ );