diff options
author | David Lawrence <dkl@redhat.com> | 2014-06-17 17:17:33 +0200 |
---|---|---|
committer | David Lawrence <dkl@redhat.com> | 2014-06-17 17:17:33 +0200 |
commit | 120d7ebcab7f6566205f1557bc788305dc40fb29 (patch) | |
tree | ca96720364d724f7fc47d7e494c7c0e3642815df /contrib | |
parent | 86ffc2b137368e556535920ff3c9732ff1839c0b (diff) | |
download | bugzilla-120d7ebcab7f6566205f1557bc788305dc40fb29.tar.gz bugzilla-120d7ebcab7f6566205f1557bc788305dc40fb29.tar.xz |
Bug 1021218: merge-users.pl fails if both users have bug_user_last_visit entries for the same bug
Diffstat (limited to 'contrib')
-rwxr-xr-x | contrib/merge-users.pl | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/contrib/merge-users.pl b/contrib/merge-users.pl index de2fe9ec5..5935d842a 100755 --- a/contrib/merge-users.pl +++ b/contrib/merge-users.pl @@ -164,6 +164,19 @@ Bugzilla::Hook::process('merge_users_before', { old_id => $old_id, new_id => $ne $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} }) { |