use CGI::Carp qw(fatalsToBrowser);
use Bugzilla::Attachment;
-use Bugzilla::BugMail;
use Bugzilla::Config;
use Bugzilla::Constants;
use Bugzilla::Field;
while (my ($name, $userid, $oldvotes, $votesperuser, $maxvotesperbug) = $sth->fetchrow_array()) {
push(@list, [$name, $userid, $oldvotes, $votesperuser, $maxvotesperbug]);
}
+
+ # @messages stores all emails which have to be sent, if any.
+ # This array is passed to the caller which will send these emails itself.
+ my @messages = ();
+
if (scalar(@list)) {
foreach my $ref (@list) {
my ($name, $userid, $oldvotes, $votesperuser, $maxvotesperbug) = (@$ref);
$substs{"count"} = $removedvotes . "\n " . $newvotestext;
my $msg = perform_substs(Param("voteremovedmail"), \%substs);
- Bugzilla::BugMail::MessageToMTA($msg);
+ push(@messages, $msg);
}
my $votes = $dbh->selectrow_array("SELECT SUM(vote_count) " .
"FROM votes WHERE bug_id = ?",
$dbh->do("UPDATE bugs SET votes = ? WHERE bug_id = ?",
undef, ($votes, $id));
}
+ # Now return the array containing emails to be sent.
+ return \@messages;
}
# If a user votes for a bug, or the number of votes required to
# Dawn Endico <endico@mozilla.org>
# Joe Robins <jmrobins@tgix.com>
# Gavin Shelley <bugzilla@chimpychompy.org>
-# Fr��ic Buclin <LpSolit@gmail.com>
+# Frédéric Buclin <LpSolit@gmail.com>
# Greg Hendricks <ghendricks@novell.com>
# Lance Larsh <lance.larsh@oracle.com>
#
use Bugzilla::Bug;
use Bugzilla::Series;
use Bugzilla::Config qw(:DEFAULT $datadir);
+use Bugzilla::BugMail;
use Bugzilla::Product;
use Bugzilla::Classification;
use Bugzilla::Milestone;
foreach my $vote (@$votes) {
my ($who, $id) = (@$vote);
- RemoveVotes($id, $who, "The rules for voting on this product " .
- "has changed;\nyou had too many votes " .
- "for a single bug.");
+ # If some votes are removed, RemoveVotes() returns a list
+ # of messages to send to voters.
+ my $msgs =
+ RemoveVotes($id, $who, "The rules for voting on this product " .
+ "has changed;\nyou had too many votes " .
+ "for a single bug.");
+ foreach my $msg (@$msgs) {
+ Bugzilla::BugMail::MessageToMTA($msg);
+ }
my $name = DBID_to_name($who);
push(@toomanyvotes_list,
undef, ($product->id, $who));
foreach my $bug_id (@$bug_ids) {
- RemoveVotes($bug_id, $who, "The rules for voting on this " .
- "product has changed; you had " .
- "too many\ntotal votes, so all " .
- "votes have been removed.");
+ # RemoveVotes() returns a list of messages to send
+ # in case some voters had too many votes.
+ my $msgs =
+ RemoveVotes($bug_id, $who, "The rules for voting on this " .
+ "product has changed; you had " .
+ "too many\ntotal votes, so all " .
+ "votes have been removed.");
+ foreach my $msg (@$msgs) {
+ Bugzilla::BugMail::MessageToMTA($msg);
+ }
my $name = DBID_to_name($who);
push(@toomanytotalvotes_list,
#
my $origOwner = "";
my $origQaContact = "";
-
+
+ # $msgs will store emails which have to be sent to voters, if any.
+ my $msgs;
+
foreach my $c (@::log_columns) {
my $col = $c; # We modify it, don't want to modify array
# values in place.
}
if ($col eq 'product') {
- RemoveVotes($id, 0,
- "This bug has been moved to a different product");
+ # If some votes have been removed, RemoveVotes() returns
+ # a list of messages to send to voters.
+ # We delay the sending of these messages till tables are unlocked.
+ $msgs = RemoveVotes($id, 0,
+ "This bug has been moved to a different product");
}
-
+
if ($col eq 'bug_status'
&& IsOpenedState($old) ne IsOpenedState($new))
{
}
$dbh->bz_unlock_tables();
+ # Now is a good time to send email to voters.
+ foreach my $msg (@$msgs) {
+ Bugzilla::BugMail::MessageToMTA($msg);
+ }
+
if ($duplicate) {
# Check to see if Reporter of this bug is reporter of Dupe
SendSQL("SELECT reporter FROM bugs WHERE bug_id = " .