From a0cb5b08f1d4c9218d64d8e0471ce0fb5578939c Mon Sep 17 00:00:00 2001 From: "lpsolit%gmail.com" <> Date: Wed, 1 Jul 2009 11:02:20 +0000 Subject: Bug 500900: Confirming bugs requires NEW state to exist - Patch by Frédéric Buclin r/a=mkanat MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Bugzilla/Bug.pm | 48 +++++++++++++++++------------------------------- 1 file changed, 17 insertions(+), 31 deletions(-) (limited to 'Bugzilla/Bug.pm') diff --git a/Bugzilla/Bug.pm b/Bugzilla/Bug.pm index 69f27ebac..a2db3572a 100644 --- a/Bugzilla/Bug.pm +++ b/Bugzilla/Bug.pm @@ -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; } -- cgit v1.2.3-24-g4f1b