]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 500900: Confirming bugs requires NEW state to exist - Patch by Frédéric Buclin...
authorlpsolit%gmail.com <>
Wed, 1 Jul 2009 11:04:23 +0000 (11:04 +0000)
committerlpsolit%gmail.com <>
Wed, 1 Jul 2009 11:04:23 +0000 (11:04 +0000)
Bugzilla/Bug.pm
Bugzilla/Product.pm
process_bug.cgi
template/en/default/global/code-error.html.tmpl
votes.cgi

index 69f27ebac5e505b684b3d26e44e9867f5ba965d2..a2db3572abed0cdc5438db76bad43c673296b306 100644 (file)
@@ -3355,45 +3355,31 @@ 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;
-
-    # XXX - Use bug methods to update the bug status and everconfirmed.
+    my $id = shift;
     my $bug = new Bugzilla::Bug($id);
 
-    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 (!$bug->everconfirmed && $bug->votes >= $bug->product_obj->votes_to_confirm) {
         $bug->add_comment('', { type => CMT_POPULAR_VOTES });
-        $bug->update();
 
-        if ($status eq 'UNCONFIRMED') {
-            my $fieldid = get_field_id("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'));
+        if ($bug->bug_status eq 'UNCONFIRMED') {
+            # Get a valid open state.
+            my $new_status;
+            foreach my $state (@{$bug->status->can_change_to}) {
+                if ($state->is_open && $state->name ne 'UNCONFIRMED') {
+                    $new_status = $state->name;
+                    last;
+                }
+            }
+            ThrowCodeError('no_open_bug_status') unless $new_status;
+
+            $bug->set_status($new_status);
         }
         else {
-            $dbh->do("UPDATE bugs SET everconfirmed = 1, delta_ts = ? " .
-                     "WHERE bug_id = ?", undef, ($timestamp, $id));
+            # If the bug is in a closed state, only set everconfirmed to 1.
+            $bug->_set_everconfirmed(1);
         }
-
-        my $fieldid = get_field_id("everconfirmed");
-        $dbh->do("INSERT INTO bugs_activity " .
-                 "(bug_id, who, bug_when, fieldid, removed, added) " .
-                 "VALUES (?, ?, ?, ?, ?, ?)",
-                 undef, ($id, $who, $timestamp, $fieldid, '0', '1'));
+        $bug->update();
 
         $ret = 1;
     }
index 88292d27e1af8629cb9508d44ad0106ce83124f6..0b1a11a5dd53971f48c83d03e3a4868ec1f21451 100644 (file)
@@ -149,7 +149,6 @@ sub preload {
 sub update {
     my $self = shift;
     my $dbh = Bugzilla->dbh;
-    my $user = Bugzilla->user;
 
     # Don't update the DB if something goes wrong below -> transaction.
     $dbh->bz_start_transaction();
@@ -242,7 +241,7 @@ sub update {
 
         my @updated_bugs = ();
         foreach my $bug_id (@$bug_list) {
-            my $confirmed = CheckIfVotedConfirmed($bug_id, $user->id);
+            my $confirmed = CheckIfVotedConfirmed($bug_id);
             push (@updated_bugs, $bug_id) if $confirmed;
         }
         $changes->{'confirmed_bugs'} = \@updated_bugs;
index 83041230bb18605b4ec650370484764cf99ea6c6..9faaf7445a07370b19f0359fe0646874da38ecd6 100755 (executable)
@@ -583,7 +583,7 @@ foreach my $bug (@bug_objects) {
         # a list of messages to send to voters.
         # We delay the sending of these messages till changes are committed.
         @msgs = RemoveVotes($bug->id, 0, 'votes_bug_moved');
-        CheckIfVotedConfirmed($bug->id, Bugzilla->user->id);
+        CheckIfVotedConfirmed($bug->id);
     }
 
     # Set and update flags.
index da8f902d47a2cdb436225d1e3cf07d7cecb7f852..1d0eed39d8505e47de3de3ec35956498db958f0b 100644 (file)
@@ -32,7 +32,7 @@
   # in this file; if you do not wish to change it, use the "none" filter.
   #%]
 
-[% PROCESS global/variables.none.tmpl %]
+[% PROCESS "global/field-descs.none.tmpl" %]
 
 [% DEFAULT title = "Internal Error" %]
 
     You cannot set the resolution of [% terms.abug %] to MOVED without
     moving the [% terms.bug %].
 
+  [% ELSIF error == "no_open_bug_status" %]
+    [% title = "$terms.Bug Cannot Be Confirmed" %]
+    There is no valid transition from
+    [%+ get_status("UNCONFIRMED") FILTER html %] to an open state.
+
   [% ELSIF error == "param_must_be_numeric" %]
     [% title = "Invalid Parameter" %]
     Invalid parameter passed to [% function FILTER html %].
index 3e33d8fa9a4253157cff7465581634953b0130f0..1c72431c45e7a8b3b8a0a853292a88ab60c1c2a6 100755 (executable)
--- a/votes.cgi
+++ b/votes.cgi
@@ -342,7 +342,7 @@ sub record_votes {
         my $v = $sth_getVotes->fetchrow_array || 0;
         $sth_updateVotes->execute($v, $id);
 
-        my $confirmed = CheckIfVotedConfirmed($id, $who);
+        my $confirmed = CheckIfVotedConfirmed($id);
         push (@updated_bugs, $id) if $confirmed;
     }
     $dbh->bz_commit_transaction();