]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 1021218: merge-users.pl fails if both users have bug_user_last_visit entries...
authorDavid Lawrence <dkl@redhat.com>
Tue, 17 Jun 2014 15:13:38 +0000 (15:13 +0000)
committerDavid Lawrence <dkl@redhat.com>
Tue, 17 Jun 2014 15:13:38 +0000 (15:13 +0000)
r=glob,a=glob

contrib/merge-users.pl

index eb205cac2035367fbb8b2b426f9fb599901c681d..272f5586af1e2778bff7db8db75d90e7047e6069 100755 (executable)
@@ -145,6 +145,19 @@ $dbh->bz_start_transaction();
 $dbh->do('DELETE FROM logincookies WHERE userid = ?', undef, $old_id);
 $dbh->do('DELETE FROM tokens WHERE userid = ?', undef, $old_id);
 
+# Special care needs to be done with bug_user_last_visit table as the
+# source user and destination user may have visited the same bug id at one time.
+# In this case we remove the one with the oldest timestamp.
+my $dupe_ids = $dbh->selectcol_arrayref("
+    SELECT earlier.id
+      FROM bug_user_last_visit as earlier
+           INNER JOIN bug_user_last_visit as later
+           ON (earlier.user_id != later.user_id AND earlier.last_visit_ts < later.last_visit_ts
+               AND earlier.bug_id = later.bug_id)
+     WHERE (earlier.user_id = ? OR earlier.user_id = ?)",
+    undef, $old_id, $new_id);
+$dbh->do("DELETE FROM bug_user_last_visit WHERE " . $dbh->sql_in('id', $dupe_ids));
+
 # Migrate records from old user to new user.
 foreach my $table (keys %changes) {
     foreach my $column_list (@{ $changes{$table} }) {