summaryrefslogtreecommitdiffstats
path: root/Bugzilla/Bug.pm
diff options
context:
space:
mode:
authorlpsolit%gmail.com <>2005-04-20 08:42:56 +0200
committerlpsolit%gmail.com <>2005-04-20 08:42:56 +0200
commit57394ff026769d28ef6b5d077cb4655adf032936 (patch)
tree780e1e6b6069ae190fcaf7f509ef69274dfd91ee /Bugzilla/Bug.pm
parent3e681ef2457ac8205f95b48e42922b17153180e2 (diff)
downloadbugzilla-57394ff026769d28ef6b5d077cb4655adf032936.tar.gz
bugzilla-57394ff026769d28ef6b5d077cb4655adf032936.tar.xz
Bug 290513: Move CheckIfVotedConfirmed() out of CGI.pl - Patch by Frédéric Buclin <LpSolit@gmail.com> r=wicked a=myk
Diffstat (limited to 'Bugzilla/Bug.pm')
-rwxr-xr-xBugzilla/Bug.pm57
1 files changed, 56 insertions, 1 deletions
diff --git a/Bugzilla/Bug.pm b/Bugzilla/Bug.pm
index 962b1de42..7d93139a1 100755
--- a/Bugzilla/Bug.pm
+++ b/Bugzilla/Bug.pm
@@ -51,7 +51,7 @@ use base qw(Exporter);
@Bugzilla::Bug::EXPORT = qw(
AppendComment ValidateComment
bug_alias_to_id
- RemoveVotes
+ RemoveVotes CheckIfVotedConfirmed
);
use constant MAX_COMMENT_LENGTH => 65535;
@@ -927,6 +927,61 @@ sub RemoveVotes {
}
}
+# If a user votes for a bug, or the number of votes required to
+# confirm a bug has been reduced, check if the bug is now confirmed.
+sub CheckIfVotedConfirmed {
+ my ($id, $who) = (@_);
+ my $dbh = Bugzilla->dbh;
+
+ my ($votes, $status, $everconfirmed, $votestoconfirm, $timestamp) =
+ $dbh->selectrow_array("SELECT votes, bug_status, everconfirmed, " .
+ " votestoconfirm, NOW() " .
+ "FROM bugs INNER JOIN products " .
+ " ON products.id = bugs.product_id " .
+ "WHERE bugs.bug_id = ?",
+ undef, $id);
+
+ my $ret = 0;
+ if ($votes >= $votestoconfirm && !$everconfirmed) {
+ if ($status eq 'UNCONFIRMED') {
+ my $fieldid = &::GetFieldID("bug_status");
+ $dbh->do("UPDATE bugs SET bug_status = 'NEW', everconfirmed = 1, " .
+ "delta_ts = ? WHERE bug_id = ?",
+ undef, ($timestamp, $id));
+ $dbh->do("INSERT INTO bugs_activity " .
+ "(bug_id, who, bug_when, fieldid, removed, added) " .
+ "VALUES (?, ?, ?, ?, ?, ?)",
+ undef, ($id, $who, $timestamp, $fieldid, 'UNCONFIRMED', 'NEW'));
+ }
+ else {
+ $dbh->do("UPDATE bugs SET everconfirmed = 1, delta_ts = ? " .
+ "WHERE bug_id = ?", undef, ($timestamp, $id));
+ }
+
+ my $fieldid = &::GetFieldID("everconfirmed");
+ $dbh->do("INSERT INTO bugs_activity " .
+ "(bug_id, who, bug_when, fieldid, removed, added) " .
+ "VALUES (?, ?, ?, ?, ?, ?)",
+ undef, ($id, $who, $timestamp, $fieldid, '0', '1'));
+
+ AppendComment($id, &::DBID_to_name($who),
+ "*** This bug has been confirmed by popular vote. ***",
+ 0, $timestamp);
+
+ my $template = Bugzilla->template;
+ my $vars = $::vars;
+
+ $vars->{'type'} = "votes";
+ $vars->{'id'} = $id;
+ $vars->{'mailrecipients'} = { 'changer' => $who };
+
+ $template->process("bug/process/results.html.tmpl", $vars)
+ || ThrowTemplateError($template->error());
+ $ret = 1;
+ }
+ return $ret;
+}
+
sub AUTOLOAD {
use vars qw($AUTOLOAD);
my $attr = $AUTOLOAD;