diff options
author | mkanat%bugzilla.org <> | 2008-01-18 03:41:44 +0100 |
---|---|---|
committer | mkanat%bugzilla.org <> | 2008-01-18 03:41:44 +0100 |
commit | 620caf6860a86bf0f54918e8514c14d7cec5f2cc (patch) | |
tree | ce5a8abe5895d7d3a1761ba7a529f856fc4cdb08 /Bugzilla/Status.pm | |
parent | f39fc76d9cd52a0e045dc8071d422348bc5c359b (diff) | |
download | bugzilla-620caf6860a86bf0f54918e8514c14d7cec5f2cc.tar.gz bugzilla-620caf6860a86bf0f54918e8514c14d7cec5f2cc.tar.xz |
Bug 402791: Move status and resolution updating from process_bug.cgi into Bugzilla::Bug
Patch By Max Kanat-Alexander <mkanat@bugzilla.org> r=LpSolit, a=LpSolit
Diffstat (limited to 'Bugzilla/Status.pm')
-rw-r--r-- | Bugzilla/Status.pm | 98 |
1 files changed, 98 insertions, 0 deletions
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<allow_change_from> + +=over + +=item B<Description> + +Tells you whether or not a change to this status from another status is +allowed. + +=item B<Params> + +=over + +=item C<$old_status> - The Bugzilla::Status you're changing from. + +=item C<$product> - A L<Bugzilla::Product> representing the product of +the bug you're changing. Needed to check product-specific workflow +issues (such as whether or not the C<UNCONFIRMED> status is enabled +in this product). + +=back + +=item B<Returns> + +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<comment_required_on_change_from> + +=over + +=item B<Description> + +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<commenton> parameters--those are checked by internal checks in +L<Bugzilla::Bug>. + +=item B<Params> + +C<$old_status> - The status you're changing from. + +=item B<Returns> + +C<1> if a comment is required on this change, C<0> if not. + +=back + =item C<add_missing_bug_status_transitions> Description: Insert all missing transitions to a given bug status. |