Commit 93ed3ae8 authored by mkanat%kerio.com's avatar mkanat%kerio.com

Bug 282628: Move OpenStates and IsOpenedState out of globals.pl

Patch By Max Kanat-Alexander <mkanat@bugzilla.org> r=wicked, a=myk
parent eb411e0d
......@@ -54,6 +54,7 @@ use base qw(Exporter);
bug_alias_to_id ValidateBugAlias ValidateBugID
RemoveVotes CheckIfVotedConfirmed
LogActivityEntry
is_open_state
);
#####################################################################
......@@ -203,7 +204,7 @@ sub initBug {
}
$self->{'isunconfirmed'} = ($self->{bug_status} eq 'UNCONFIRMED');
$self->{'isopened'} = &::IsOpenedState($self->{bug_status});
$self->{'isopened'} = is_open_state($self->{bug_status});
return $self;
}
......@@ -758,6 +759,12 @@ sub EmitDependList {
return $list_ref;
}
# Tells you whether or not the argument is a valid "open" state.
sub is_open_state {
my ($state) = @_;
return (grep($_ eq $state, BUG_STATE_OPEN) ? 1 : 0);
}
sub ValidateTime {
my ($time, $field) = @_;
......@@ -979,7 +986,7 @@ sub CountOpenDependencies {
"FROM bugs, dependencies " .
"WHERE blocked IN (" . (join "," , @bug_list) . ") " .
"AND bug_id = dependson " .
"AND bug_status IN ('" . (join "','", &::OpenStates()) . "') " .
"AND bug_status IN ('" . (join "','", BUG_STATE_OPEN) . "') " .
$dbh->sql_group_by('blocked'));
$sth->execute();
......
......@@ -37,6 +37,7 @@ use Bugzilla::User;
use Bugzilla::Constants;
use Bugzilla::Config qw(:DEFAULT $datadir);
use Bugzilla::Util;
use Bugzilla::Bug;
use Date::Parse;
use Date::Format;
......@@ -309,7 +310,7 @@ sub ProcessOneBug {
$interestingchange = 0;
}
$thisdiff .= FormatTriple($fielddescription{$what}, $old, $new);
if ($what eq 'bug_status' && &::IsOpenedState($old) ne &::IsOpenedState($new)) {
if ($what eq 'bug_status' && is_open_state($old) ne is_open_state($new)) {
$interestingchange = 1;
}
......
......@@ -94,6 +94,8 @@ use base qw(Exporter);
FIELD_TYPE_UNKNOWN
FIELD_TYPE_FREETEXT
BUG_STATE_OPEN
);
@Bugzilla::Constants::EXPORT_OK = qw(contenttypes);
......@@ -256,4 +258,8 @@ use constant SENDMAIL_EXE => '/usr/lib/sendmail.exe';
use constant FIELD_TYPE_UNKNOWN => 0;
use constant FIELD_TYPE_FREETEXT => 1;
# States that are considered to be "open" for bugs.
use constant BUG_STATE_OPEN => ('NEW', 'REOPENED', 'ASSIGNED',
'UNCONFIRMED');
1;
......@@ -41,6 +41,7 @@ use Bugzilla::Constants;
use Bugzilla::Group;
use Bugzilla::User;
use Bugzilla::Field;
use Bugzilla::Bug;
use Date::Format;
use Date::Parse;
......@@ -186,11 +187,11 @@ sub init {
$params->delete('bug_status');
}
elsif ($bug_statuses[0] eq '__open__') {
$params->param('bug_status', map(&::IsOpenedState($_) ? $_ : undef,
$params->param('bug_status', map(is_open_state($_) ? $_ : undef,
@::legal_bug_status));
}
elsif ($bug_statuses[0] eq "__closed__") {
$params->param('bug_status', map(&::IsOpenedState($_) ? undef : $_,
$params->param('bug_status', map(is_open_state($_) ? undef : $_,
@::legal_bug_status));
}
}
......
......@@ -26,6 +26,8 @@ use strict;
use Bugzilla;
use Bugzilla::Config;
use Bugzilla::Error;
use Bugzilla::Constants;
use Bugzilla::Bug;
use base qw(Exporter);
@Bugzilla::Search::Quicksearch::EXPORT = qw(quicksearch);
......@@ -153,12 +155,12 @@ sub quicksearch {
my @words = splitString($searchstring);
my $searchComments = $#words < Param('quicksearch_comment_cutoff');
my @openStates = &::OpenStates();
my @openStates = BUG_STATE_OPEN;
my @closedStates;
my (%states, %resolutions);
foreach (@::legal_bug_status) {
push(@closedStates, $_) unless &::IsOpenedState($_);
push(@closedStates, $_) unless is_open_state($_);
}
foreach (@openStates) { $states{$_} = 1 }
if ($words[0] eq 'ALL') {
......
......@@ -40,6 +40,7 @@ use Bugzilla::Util;
use Bugzilla::User;
use Bugzilla::Error;
use MIME::Base64;
use Bugzilla::Bug;
# for time2str - replace by TT Date plugin??
use Date::Format ();
......@@ -415,7 +416,7 @@ sub get_bug_link {
$pre = "<i>";
$post = "</i>";
}
elsif (! &::IsOpenedState($bug_state)) {
elsif (!is_open_state($bug_state)) {
$pre = '<span class="bz_closed">';
$title .= " $bug_res";
$post = '</span>';
......
......@@ -1007,7 +1007,7 @@ $vars->{'buglist_joined'} = join(',', @bugidlist);
$vars->{'columns'} = $columns;
$vars->{'displaycolumns'} = \@displaycolumns;
my @openstates = OpenStates();
my @openstates = BUG_STATE_OPEN;
$vars->{'openstates'} = \@openstates;
$vars->{'closedstates'} = ['CLOSED', 'VERIFIED', 'RESOLVED'];
......
......@@ -1449,6 +1449,9 @@ import Bugzilla::Util qw(bz_crypt trim html_quote is_7bit_clean);
require Bugzilla::User;
import Bugzilla::User qw(insert_new_user);
require Bugzilla::Bug;
import Bugzilla::Bug qw(is_open_state);
# globals.pl clears the PATH, but File::Find uses Cwd::cwd() instead of
# Cwd::getcwd(), which we need to do because `pwd` isn't in the path - see
# http://www.xray.mpe.mpg.de/mailing-lists/perl5-porters/2001-09/msg00115.html
......@@ -3545,7 +3548,7 @@ if (!$series_exists) {
$data{$fields[$i]}{$numbers[0]} = $numbers[$i + 1];
# Keep a total of the number of open bugs for this day
if (IsOpenedState($fields[$i])) {
if (is_open_state($fields[$i])) {
$data{$open_name}{$numbers[0]} += $numbers[$i + 1];
}
}
......@@ -4120,7 +4123,7 @@ if (@$broken_nonopen_series) {
join("&", map { "bug_status=" . url_quote($_) }
('UNCONFIRMED', 'NEW', 'ASSIGNED', 'REOPENED'));
my $open_bugs_query_base_new =
join("&", map { "bug_status=" . url_quote($_) } OpenStates());
join("&", map { "bug_status=" . url_quote($_) } BUG_STATE_OPEN);
my $sth_openbugs_series =
$dbh->prepare("SELECT series_id FROM series
WHERE query IN (?, ?)");
......
......@@ -33,6 +33,7 @@ use lib qw(.);
require "globals.pl";
use Bugzilla;
use Bugzilla::Constants;
use Bugzilla::Bug;
# Suppress "used only once" warnings.
use vars
......@@ -80,7 +81,7 @@ $vars->{'products'} = $user->get_selectable_products;
my @open_status;
my @closed_status;
foreach my $status (@::legal_bug_status) {
IsOpenedState($status) ? push(@open_status, $status)
is_open_state($status) ? push(@open_status, $status)
: push(@closed_status, $status);
}
$vars->{'open_status'} = \@open_status;
......
......@@ -294,7 +294,7 @@ if ($action eq 'new') {
# For localisation reasons, we get the name of the "global" subcategory
# and the title of the "open" query from the submitted form.
my @openedstatuses = OpenStates();
my @openedstatuses = BUG_STATE_OPEN;
my $query =
join("&", map { "bug_status=" . url_quote($_) } @openedstatuses);
push(@series, [$open_name, $query]);
......
......@@ -472,25 +472,6 @@ sub GroupIdToName {
return $name;
}
# Determines if the given bug_status string represents an "Opened" bug. This
# routine ought to be parameterizable somehow, as people tend to introduce
# new states into Bugzilla.
sub IsOpenedState {
my ($state) = (@_);
if (grep($_ eq $state, OpenStates())) {
return 1;
}
return 0;
}
# This sub will return an array containing any status that
# is considered an open bug.
sub OpenStates {
return ('NEW', 'REOPENED', 'ASSIGNED', 'UNCONFIRMED');
}
############# Live code below here (that is, not subroutine defs) #############
use Bugzilla;
......
......@@ -896,7 +896,7 @@ sub process_bug {
my $valid_status = check_field('bug_status',
scalar $bug_fields{'bug_status'},
\@::legal_bug_status, ERR_LEVEL );
my $is_open = IsOpenedState($bug_fields{'bug_status'});
my $is_open = is_open_state($bug_fields{'bug_status'});
my $status = $bug_fields{'bug_status'} || undef;
my $resolution = $bug_fields{'resolution'} || undef;
......
......@@ -500,7 +500,7 @@ sub CheckCanChangeField {
if ($field eq "canconfirm"
|| ($field eq "bug_status"
&& $oldvalue eq 'UNCONFIRMED'
&& IsOpenedState($newvalue)))
&& is_open_state($newvalue)))
{
$PrivilegesRequired = 3;
return $UserInCanConfirmGroupSet;
......@@ -785,7 +785,7 @@ sub ChangeStatus {
# confirmed or not
$::query .= "bug_status = CASE WHEN everconfirmed = 1 THEN " .
SqlQuote($str) . " ELSE 'UNCONFIRMED' END";
} elsif (IsOpenedState($str)) {
} elsif (is_open_state($str)) {
# Note that we cannot combine this with the above branch - here we
# need to check if bugs.bug_status is open, (since we don't want to
# reopen closed bugs when reassigning), while above the whole point
......@@ -811,7 +811,7 @@ sub ChangeStatus {
# This also relies on the fact that confirming and accepting have
# already called DoConfirm before this is called
my @open_state = map(SqlQuote($_), OpenStates());
my @open_state = map(SqlQuote($_), BUG_STATE_OPEN);
my $open_state = join(", ", @open_state);
# If we are changing everconfirmed to 1, we have to take this change
......@@ -2040,7 +2040,7 @@ foreach my $id (@idlist) {
}
if ($col eq 'bug_status'
&& IsOpenedState($old) ne IsOpenedState($new))
&& is_open_state($old) ne is_open_state($new))
{
$check_dep_bugs = 1;
}
......
......@@ -737,7 +737,7 @@ BugCheck("bugs LEFT JOIN duplicates ON bugs.bug_id = duplicates.dupe WHERE " .
Status("Checking statuses/resolutions");
my @open_states = map(SqlQuote($_), OpenStates());
my @open_states = map(SqlQuote($_), BUG_STATE_OPEN);
my $open_states = join(', ', @open_states);
BugCheck("bugs WHERE bug_status IN ($open_states) AND resolution != ''",
......
......@@ -188,7 +188,7 @@ foreach my $k (keys(%seen)) {
push(@params, "shape=box");
}
if (IsOpenedState($stat)) {
if (is_open_state($stat)) {
push(@params, "color=green");
}
......
......@@ -166,7 +166,7 @@ sub GetBug {
WHERE bugs.bug_id = ?", undef, $id);
}
$bug->{'open'} = $bug->{'exists'} && IsOpenedState($bug->{'status'});
$bug->{'open'} = $bug->{'exists'} && is_open_state($bug->{'status'});
$bug->{'dependencies'} = [];
return $bug;
......
......@@ -186,7 +186,7 @@ sub show_user {
push (@bugs, { id => $id,
summary => $summary,
count => $count,
opened => IsOpenedState($status) });
opened => is_open_state($status) });
}
# In case we didn't populate this earlier (i.e. an error, or
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment