From 3b53b9f05ee1543df57034d5c74a1c2b3dffc9d5 Mon Sep 17 00:00:00 2001 From: "lpsolit%gmail.com" <> Date: Sun, 17 Apr 2005 00:17:04 +0000 Subject: Bug 290511: Move RemoveVotes() out of globals.pl - Patch by Frédéric Buclin r=mkanat a=justdave MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- globals.pl | 88 -------------------------------------------------------------- 1 file changed, 88 deletions(-) (limited to 'globals.pl') diff --git a/globals.pl b/globals.pl index a9c3a36ce..d33319e98 100644 --- a/globals.pl +++ b/globals.pl @@ -1040,94 +1040,6 @@ sub OpenStates { } -sub RemoveVotes { - my ($id, $who, $reason) = (@_); - my $whopart = ""; - if ($who) { - $whopart = " AND votes.who = $who"; - } - SendSQL("SELECT profiles.login_name, profiles.userid, votes.vote_count, " . - "products.votesperuser, products.maxvotesperbug " . - "FROM profiles " . - "LEFT JOIN votes ON profiles.userid = votes.who " . - "LEFT JOIN bugs USING(bug_id) " . - "LEFT JOIN products ON products.id = bugs.product_id " . - "WHERE votes.bug_id = $id " . - $whopart); - my @list; - while (MoreSQLData()) { - my ($name, $userid, $oldvotes, $votesperuser, $maxvotesperbug) = (FetchSQLData()); - push(@list, [$name, $userid, $oldvotes, $votesperuser, $maxvotesperbug]); - } - if (0 < @list) { - foreach my $ref (@list) { - my ($name, $userid, $oldvotes, $votesperuser, $maxvotesperbug) = (@$ref); - my $s; - - $maxvotesperbug = $votesperuser if ($votesperuser < $maxvotesperbug); - - # If this product allows voting and the user's votes are in - # the acceptable range, then don't do anything. - next if $votesperuser && $oldvotes <= $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; - - my $removedvotes = $oldvotes - $newvotes; - - $s = $oldvotes == 1 ? "" : "s"; - my $oldvotestext = "You had $oldvotes vote$s on this bug."; - - $s = $removedvotes == 1 ? "" : "s"; - my $removedvotestext = "You had $removedvotes vote$s removed from this bug."; - - my $newvotestext; - if ($newvotes) { - SendSQL("UPDATE votes SET vote_count = $newvotes " . - "WHERE bug_id = $id AND who = $userid"); - $s = $newvotes == 1 ? "" : "s"; - $newvotestext = "You still have $newvotes vote$s on this bug." - } else { - SendSQL("DELETE FROM votes WHERE bug_id = $id AND who = $userid"); - $newvotestext = "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 losing 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 %substs; - - $substs{"to"} = $name . Param('emailsuffix'); - $substs{"bugid"} = $id; - $substs{"reason"} = $reason; - - $substs{"votesremoved"} = $removedvotes; - $substs{"votesold"} = $oldvotes; - $substs{"votesnew"} = $newvotes; - - $substs{"votesremovedtext"} = $removedvotestext; - $substs{"votesoldtext"} = $oldvotestext; - $substs{"votesnewtext"} = $newvotestext; - - $substs{"count"} = $removedvotes . "\n " . $newvotestext; - - my $msg = PerformSubsts(Param("voteremovedmail"), - \%substs); - - Bugzilla::BugMail::MessageToMTA($msg); - } - SendSQL("SELECT SUM(vote_count) FROM votes WHERE bug_id = $id"); - my $v = FetchOneColumn(); - $v ||= 0; - SendSQL("UPDATE bugs SET votes = $v WHERE bug_id = $id"); - } -} - ############################################################################### # Constructs a format object from URL parameters. You most commonly call it -- cgit v1.2.3-24-g4f1b