diff options
author | Byron Jones <glob@mozilla.com> | 2014-03-17 17:30:11 +0100 |
---|---|---|
committer | Byron Jones <glob@mozilla.com> | 2014-03-17 17:30:11 +0100 |
commit | fa99f05b2e7074e88efea8a0fb4f0c51de77b3e1 (patch) | |
tree | a96730e71272977f6f719784bcaa6835a9146137 /extensions/Review | |
parent | bf95aa6a012b934da8b9049c5e3551334ccb7a54 (diff) | |
download | bugzilla-fa99f05b2e7074e88efea8a0fb4f0c51de77b3e1.tar.gz bugzilla-fa99f05b2e7074e88efea8a0fb4f0c51de77b3e1.tar.xz |
Bug 981937: update review counter rebuilder to correct negative values
Diffstat (limited to 'extensions/Review')
-rw-r--r-- | extensions/Review/lib/Util.pm | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/extensions/Review/lib/Util.pm b/extensions/Review/lib/Util.pm index 83589e2d0..c00e31b6b 100644 --- a/extensions/Review/lib/Util.pm +++ b/extensions/Review/lib/Util.pm @@ -19,6 +19,7 @@ sub rebuild_review_counters { my $dbh = Bugzilla->dbh; $dbh->bz_start_transaction; + my $rows = $dbh->selectall_arrayref(" SELECT flags.requestee_id AS user_id, flagtypes.name AS flagtype, @@ -41,9 +42,28 @@ sub rebuild_review_counters { $current->{$row->{flagtype}} = $row->{count}; } _update_profile($dbh, $current) if $current->{id}; + + foreach my $field (qw( review feedback needinfo )) { + _fix_negatives($dbh, $field); + } + $dbh->bz_commit_transaction; } +sub _fix_negatives { + my ($dbh, $field) = @_; + my $user_ids = $dbh->selectcol_arrayref( + "SELECT userid FROM profiles WHERE ${field}_request_count < 0" + ); + return unless @$user_ids; + $dbh->do( + "UPDATE profiles SET ${field}_request_count = 0 WHERE " . $dbh->sql_in('userid', $user_ids) + ); + foreach my $user_id (@$user_ids) { + Bugzilla->memcached->clear({ table => 'profiles', id => $user_id }); + } +} + sub _update_profile { my ($dbh, $data) = @_; $dbh->do(" |