diff options
-rwxr-xr-x | contrib/merge-users.pl | 7 | ||||
-rw-r--r-- | extensions/UserProfile/Extension.pm | 19 |
2 files changed, 26 insertions, 0 deletions
diff --git a/contrib/merge-users.pl b/contrib/merge-users.pl index ee6ec8628..99fe3fef0 100755 --- a/contrib/merge-users.pl +++ b/contrib/merge-users.pl @@ -50,6 +50,7 @@ use Bugzilla; use Bugzilla::Constants; use Bugzilla::Util; use Bugzilla::User; +use Bugzilla::Hook; use Getopt::Long; use Pod::Usage; @@ -156,6 +157,9 @@ foreach my $table (qw(logincookies tokens profiles)) { # Start the transaction $dbh->bz_start_transaction(); +# BMO - pre-work hook +Bugzilla::Hook::process('merge_users_before', { old_id => $old_id, new_id => $new_id }); + # Delete old records from logincookies and tokens tables. $dbh->do('DELETE FROM logincookies WHERE userid = ?', undef, $old_id); $dbh->do('DELETE FROM tokens WHERE userid = ?', undef, $old_id); @@ -234,6 +238,9 @@ $dbh->do('DELETE FROM profiles WHERE userid = ?', undef, $old_id); my $user = new Bugzilla::User($new_id); $user->derive_regexp_groups(); +# BMO - post-work hook +Bugzilla::Hook::process('merge_users_after', { old_id => $old_id, new_id => $new_id }); + # Commit the transaction $dbh->bz_commit_transaction(); diff --git a/extensions/UserProfile/Extension.pm b/extensions/UserProfile/Extension.pm index 72bbe261b..43213be54 100644 --- a/extensions/UserProfile/Extension.pm +++ b/extensions/UserProfile/Extension.pm @@ -178,6 +178,25 @@ sub reorg_move_bugs { print "Updated $count users.\n"; } +sub merge_users_before { + my ($self, $args) = @_; + my ($old_id, $new_id) = @$args{qw(old_id new_id)}; + # when users are merged, we have to delete all the statistics for both users + # we'll recalcuate the stats after the merge + print "deleting user profile statistics for $old_id and $new_id\n"; + my $dbh = Bugzilla->dbh; + foreach my $table (qw( profiles_statistics profiles_statistics_status profiles_statistics_products )) { + $dbh->do("DELETE FROM $table WHERE " . $dbh->sql_in('user_id', [ $old_id, $new_id ])); + } +} + +sub merge_users_after { + my ($self, $args) = @_; + my $new_id = $args->{new_id}; + print "generating user profile statistics $new_id\n"; + update_statistics_by_user($new_id); +} + sub webservice_user_get { my ($self, $args) = @_; my ($service, $users) = @$args{qw(webservice users)}; |