]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 290513: Move CheckIfVotedConfirmed() out of CGI.pl - Patch by Frédéric Buclin...
authorlpsolit%gmail.com <>
Wed, 20 Apr 2005 06:42:56 +0000 (06:42 +0000)
committerlpsolit%gmail.com <>
Wed, 20 Apr 2005 06:42:56 +0000 (06:42 +0000)
Bugzilla/Bug.pm
CGI.pl
votes.cgi

index 962b1de429537d97099aaf65ca6fa3d4ab87c60a..7d93139a1853432a7a7b617722e026d49bba75ad 100755 (executable)
@@ -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;
diff --git a/CGI.pl b/CGI.pl
index ec0d8909cb7a88ca8fc6d248ce0735baaf480586..d2a6b50efa04b9cfe3bb9665abbbbaa4829879a9 100644 (file)
--- a/CGI.pl
+++ b/CGI.pl
@@ -211,45 +211,6 @@ sub PutFooter {
       || ThrowTemplateError($::template->error());
 }
 
-sub CheckIfVotedConfirmed {
-    my ($id, $who) = (@_);
-    PushGlobalSQLState();
-    SendSQL("SELECT bugs.votes, bugs.bug_status, products.votestoconfirm, " .
-            "       bugs.everconfirmed, NOW() " .
-            "FROM bugs INNER JOIN products ON products.id = bugs.product_id " .
-            "WHERE bugs.bug_id = $id");
-    my ($votes, $status, $votestoconfirm, $everconfirmed, $timestamp) = (FetchSQLData());
-    my $sql_timestamp = SqlQuote($timestamp);
-    my $ret = 0;
-    if ($votes >= $votestoconfirm && $status eq 'UNCONFIRMED') {
-        SendSQL("UPDATE bugs SET bug_status = 'NEW', everconfirmed = 1, " .
-                "delta_ts = $sql_timestamp WHERE bug_id = $id");
-        my $fieldid = GetFieldID("bug_status");
-        SendSQL("INSERT INTO bugs_activity " .
-                "(bug_id, who, bug_when, fieldid, removed, added) VALUES " .
-                "($id, $who, $sql_timestamp, $fieldid, 'UNCONFIRMED', 'NEW')");
-        if (!$everconfirmed) {
-            $fieldid = GetFieldID("everconfirmed");
-            SendSQL("INSERT INTO bugs_activity " .
-                    "(bug_id, who, bug_when, fieldid, removed, added) VALUES " .
-                    "($id, $who, $sql_timestamp, $fieldid, '0', '1')");
-        }
-
-        AppendComment($id, DBID_to_name($who),
-                      "*** This bug has been confirmed by popular vote. ***",
-                      0, $timestamp);
-
-        $vars->{'type'} = "votes";
-        $vars->{'id'} = $id;
-        $vars->{'mailrecipients'} = { 'changer' => $who };
-
-        $template->process("bug/process/results.html.tmpl", $vars)
-          || ThrowTemplateError($template->error());
-        $ret = 1;
-    }
-    PopGlobalSQLState();
-    return $ret;
-}
 sub LogActivityEntry {
     my ($i,$col,$removed,$added,$whoid,$timestamp) = @_;
     # in the case of CCs, deps, and keywords, there's a possibility that someone
index 128dcba81c0308ae98843cf5e67209f976f5b7ea..3d1ac71139148db56c119d6a8b22c6a41c9b1afa 100755 (executable)
--- a/votes.cgi
+++ b/votes.cgi
@@ -28,6 +28,7 @@ use lib ".";
 
 use Bugzilla;
 use Bugzilla::Constants;
+use Bugzilla::Bug;
 
 require "CGI.pl";
 
@@ -323,7 +324,8 @@ sub record_votes {
              'dependencies READ', 'groups READ', 'fielddefs READ',
              'namedqueries READ', 'whine_queries READ', 'watch READ',
              'profiles AS watchers READ', 'profiles AS watched READ',
-             'user_group_map READ', 'bug_group_map READ');
+             'user_group_map READ', 'bug_group_map READ',
+             'email_setting READ');
     
     # Take note of, and delete the user's old votes from the database.
     SendSQL("SELECT bug_id FROM votes WHERE who = $who");