From 620caf6860a86bf0f54918e8514c14d7cec5f2cc Mon Sep 17 00:00:00 2001 From: "mkanat%bugzilla.org" <> Date: Fri, 18 Jan 2008 02:41:44 +0000 Subject: Bug 402791: Move status and resolution updating from process_bug.cgi into Bugzilla::Bug Patch By Max Kanat-Alexander r=LpSolit, a=LpSolit --- Bugzilla/Status.pm | 98 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) (limited to 'Bugzilla/Status.pm') diff --git a/Bugzilla/Status.pm b/Bugzilla/Status.pm index 65baf04b8..5573fa836 100644 --- a/Bugzilla/Status.pm +++ b/Bugzilla/Status.pm @@ -106,6 +106,24 @@ sub can_change_to { return $self->{'can_change_to'}; } +sub allow_change_from { + my ($self, $old_status, $product) = @_; + + # Always allow transitions from a status to itself. + return 1 if ($old_status && $old_status->id == $self->id); + + if ($self->name eq 'UNCONFIRMED' && !$product->votes_to_confirm) { + # UNCONFIRMED is an invalid status transition if votes_to_confirm is 0 + # in this product. + return 0; + } + + my ($cond, $values) = $self->_status_condition($old_status); + my ($transition_allowed) = Bugzilla->dbh->selectrow_array( + "SELECT 1 FROM status_workflow WHERE $cond", undef, @$values); + return $transition_allowed ? 1 : 0; +} + sub can_change_from { my $self = shift; my $dbh = Bugzilla->dbh; @@ -128,6 +146,32 @@ sub can_change_from { return $self->{'can_change_from'}; } +sub comment_required_on_change_from { + my ($self, $old_status) = @_; + my ($cond, $values) = $self->_status_condition($old_status); + + my ($require_comment) = Bugzilla->dbh->selectrow_array( + "SELECT require_comment FROM status_workflow + WHERE $cond", undef, @$values); + return $require_comment; +} + +# Used as a helper for various functions that have to deal with old_status +# sometimes being NULL and sometimes having a value. +sub _status_condition { + my ($self, $old_status) = @_; + my @values; + my $cond = 'old_status IS NULL'; + # For newly-filed bugs + if ($old_status) { + $cond = 'old_status = ?'; + push(@values, $old_status->id); + } + $cond .= " AND new_status = ?"; + push(@values, $self->id); + return ($cond, \@values); +} + sub add_missing_bug_status_transitions { my $bug_status = shift || Bugzilla->params->{'duplicate_or_move_bug_status'}; my $dbh = Bugzilla->dbh; @@ -215,6 +259,60 @@ below. Returns: A list of Bugzilla::Status objects. +=item C + +=over + +=item B + +Tells you whether or not a change to this status from another status is +allowed. + +=item B + +=over + +=item C<$old_status> - The Bugzilla::Status you're changing from. + +=item C<$product> - A L representing the product of +the bug you're changing. Needed to check product-specific workflow +issues (such as whether or not the C status is enabled +in this product). + +=back + +=item B + +C<1> if you are allowed to change to this status from that status, or +C<0> if you aren't allowed. + +Note that changing from a status to itself is always allowed. + +=back + +=item C + +=over + +=item B + +Checks if a comment is required to change to this status from another +status, according to the current settings in the workflow. + +Note that this doesn't implement the checks enforced by the various +C parameters--those are checked by internal checks in +L. + +=item B + +C<$old_status> - The status you're changing from. + +=item B + +C<1> if a comment is required on this change, C<0> if not. + +=back + =item C Description: Insert all missing transitions to a given bug status. -- cgit v1.2.3-24-g4f1b