summaryrefslogtreecommitdiffstats
path: root/globals.pl
diff options
context:
space:
mode:
authorjustdave%syndicomm.com <>2001-08-16 11:46:15 +0200
committerjustdave%syndicomm.com <>2001-08-16 11:46:15 +0200
commit161e3c5fc8dc93096527e2ebd68995c466be2646 (patch)
treea764c755afce14b7ce80ea44aee1ccb20ca0ba31 /globals.pl
parentc368a62f281af9d9b401ab465a4144ead0d82b03 (diff)
downloadbugzilla-161e3c5fc8dc93096527e2ebd68995c466be2646.tar.gz
bugzilla-161e3c5fc8dc93096527e2ebd68995c466be2646.tar.xz
Fix for bug 92593: Changing a bugs product will no longer remove the votes from that bug unless the number of votes for a given user is beyond what is allowed per-bug on the new product. Only the per-bug vote count is checked. If the user is beyond the per-product vote limit for the new product, it is left alone, on the theory that it's better to preserve the votes on the bug. The user will be forced to reduce their votes to fit the product limit the next time they try to vote on something.
Patch by Jake Steenhagen <jake@acutex.net> r= justdave@syndicomm.com
Diffstat (limited to 'globals.pl')
-rw-r--r--globals.pl42
1 files changed, 35 insertions, 7 deletions
diff --git a/globals.pl b/globals.pl
index 9c0410573..3d14c9153 100644
--- a/globals.pl
+++ b/globals.pl
@@ -1185,19 +1185,48 @@ sub RemoveVotes {
if ($who) {
$whopart = " AND votes.who = $who";
}
- SendSQL("SELECT profiles.login_name, votes.count " .
- "FROM votes, profiles " .
+ SendSQL("SELECT profiles.login_name, profiles.userid, votes.count, " .
+ "products.votesperuser, products.maxvotesperbug " .
+ "FROM profiles " .
+ "LEFT JOIN votes ON profiles.userid = votes.who " .
+ "LEFT JOIN bugs USING(bug_id) " .
+ "LEFT JOIN products USING(product)" .
"WHERE votes.bug_id = $id " .
- "AND profiles.userid = votes.who" .
$whopart);
my @list;
while (MoreSQLData()) {
- my ($name, $count) = (FetchSQLData());
- push(@list, [$name, $count]);
+ my ($name, $userid, $count, $votesperuser, $maxvotesperbug) = (FetchSQLData());
+ push(@list, [$name, $userid, $count, $votesperuser, $maxvotesperbug]);
}
if (0 < @list) {
foreach my $ref (@list) {
- my ($name, $count) = (@$ref);
+ my ($name, $userid, $count, $votesperuser, $maxvotesperbug) = (@$ref);
+
+ # If this product allows voting and the user's votes are in
+ # the acceptable range, then don't do anything.
+ next if $votesperuser && $count <= $maxvotesperbug;
+
+ # If the user has more votes on this bug than this product
+ # allows, then reduce the number of votes so it fits
+ my $newvotes = $votesperuser ? $maxvotesperbug : 0;
+ if ($newvotes) {
+ SendSQL("UPDATE votes SET count = $newvotes " .
+ "WHERE bug_id = $id AND who = $userid");
+ my $s = $newvotes == 1 ? "" : "s";
+ $count = ($count - $newvotes) .
+ "\n You still have $newvotes vote$s on this bug";
+ } else {
+ SendSQL("DELETE FROM votes WHERE bug_id = $id AND who = $userid");
+ $count = "$count\n You have no more votes remaining on this bug";
+ }
+
+ # Notice that we did not make sure that the user fit within the $votesperuser
+ # range. This is considered to be an acceptable alternative to loosing votes
+ # during product moves. Then next time the user attempts to change their votes,
+ # they will be forced to fit within the $votesperuser limit.
+
+ # Now lets send the e-mail to alert the user to the fact that their votes have
+ # been reduced or removed.
my $sendmailparm = '-ODeliveryMode=deferred';
if (Param('sendmailnow')) {
$sendmailparm = '';
@@ -1214,7 +1243,6 @@ sub RemoveVotes {
close SENDMAIL;
}
}
- SendSQL("DELETE FROM votes WHERE bug_id = $id" . $whopart);
SendSQL("SELECT SUM(count) FROM votes WHERE bug_id = $id");
my $v = FetchOneColumn();
$v ||= 0;