return @$fields;
}
-sub custom_field_names {
- # Get a list of custom fields and convert it into a list of their names.
- return map($_->{name},
- @{Bugzilla::Field->match({ custom=>1, obsolete=>0 })});
+sub active_custom_fields {
+ my $class = shift;
+ if (!exists $class->request_cache->{active_custom_fields}) {
+ $class->request_cache->{active_custom_fields} =
+ Bugzilla::Field->match({ custom => 1, obsolete => 0 });
+ }
+ return @{$class->request_cache->{active_custom_fields}};
}
sub hook_args {
# This is a sub because it needs to call other subroutines.
sub DB_COLUMNS {
my $dbh = Bugzilla->dbh;
- my @custom = Bugzilla->get_fields({ custom => 1, obsolete => 0});
- @custom = grep {$_->type != FIELD_TYPE_MULTI_SELECT} @custom;
+ my @custom = grep {$_->type != FIELD_TYPE_MULTI_SELECT}
+ Bugzilla->active_custom_fields;
my @custom_names = map {$_->name} @custom;
return qw(
alias
};
# Set up validators for custom fields.
- my @custom_fields = Bugzilla->get_fields({custom => 1, obsolete => 0});
- foreach my $field (@custom_fields) {
+ foreach my $field (Bugzilla->active_custom_fields) {
my $validator;
if ($field->type == FIELD_TYPE_SINGLE_SELECT) {
$validator = \&_check_select_field;
};
sub UPDATE_COLUMNS {
- my @custom = Bugzilla->get_fields({ custom => 1, obsolete => 0});
- @custom = grep {$_->type != FIELD_TYPE_MULTI_SELECT} @custom;
+ my @custom = grep {$_->type != FIELD_TYPE_MULTI_SELECT}
+ Bugzilla->active_custom_fields;
my @custom_names = map {$_->name} @custom;
my @columns = qw(
alias
}
# Insert the values into the multiselect value tables
- my @multi_selects = Bugzilla->get_fields(
- { custom => 1, type => FIELD_TYPE_MULTI_SELECT, obsolete => 0 });
+ my @multi_selects = grep {$_->type == FIELD_TYPE_MULTI_SELECT}
+ Bugzilla->active_custom_fields;
foreach my $field (@multi_selects) {
my $name = $field->name;
my ($removed, $added) = diff_arrays($old_bug->$name, $self->$name);
sub _extract_multi_selects {
my ($invocant, $params) = @_;
- my @multi_selects = Bugzilla->get_fields(
- { custom => 1, type => FIELD_TYPE_MULTI_SELECT, obsolete => 0 });
+ my @multi_selects = grep {$_->type == FIELD_TYPE_MULTI_SELECT}
+ Bugzilla->active_custom_fields;
my %ms_values;
foreach my $field (@multi_selects) {
my $name = $field->name;
# Conditional Fields
Bugzilla->params->{'useqacontact'} ? "qa_contact" : (),
# Custom Fields
- Bugzilla->custom_field_names
+ map { $_->name } Bugzilla->active_custom_fields
);
}
print Dumper(Bugzilla->get_fields());
# Display information about non-obsolete custom fields.
- print Dumper(Bugzilla->get_fields({ obsolete => 1, custom => 1 }));
-
- # Display a list of the names of non-obsolete custom fields.
- print Bugzilla->custom_field_names;
+ print Dumper(Bugzilla->active_custom_fields);
use Bugzilla::Field;
# Display information about non-obsolete custom fields.
# Bugzilla->get_fields() is a wrapper around Bugzilla::Field->match(),
# so both methods take the same arguments.
- print Dumper(Bugzilla::Field->match({ obsolete => 1, custom => 1 }));
+ print Dumper(Bugzilla::Field->match({ obsolete => 0, custom => 1 }));
# Create or update a custom field or field definition.
my $field = Bugzilla::Field->create(
DefineColumn("relevance" , "relevance" , "Relevance" );
DefineColumn("deadline" , $dbh->sql_date_format('bugs.deadline', '%Y-%m-%d') . " AS deadline", "Deadline");
-foreach my $field (Bugzilla->get_fields({ custom => 1, obsolete => 0})) {
+foreach my $field (Bugzilla->active_custom_fields) {
DefineColumn($field->name, 'bugs.' . $field->name, $field->description);
}
push(@masterlist, ("short_desc", "short_short_desc"));
my @custom_fields = grep { $_->type != FIELD_TYPE_MULTI_SELECT }
- Bugzilla->get_fields({ custom => 1, obsolete => 0 });
+ Bugzilla->active_custom_fields;
push(@masterlist, map { $_->name } @custom_fields);
$vars->{'masterlist'} = \@masterlist;
$vars->{'resolution'} = get_legal_field_values('resolution');
$vars->{'status'} = get_legal_field_values('bug_status');
$vars->{'custom_fields'} =
- [Bugzilla->get_fields({custom => 1, obsolete => 0, type => FIELD_TYPE_SINGLE_SELECT}),
- Bugzilla->get_fields({custom => 1, obsolete => 0, type => FIELD_TYPE_MULTI_SELECT})];
+ [ grep {$_->type == FIELD_TYPE_SINGLE_SELECT || $_->type == FIELD_TYPE_MULTI_SELECT}
+ Bugzilla->active_custom_fields ];
# Include a list of product objects.
if ($cgi->param('product')) {
$vars->{'token'} = issue_session_token('createbug:');
-my @enter_bug_fields = Bugzilla->get_fields({ custom => 1, obsolete => 0,
- enter_bug => 1 });
+my @enter_bug_fields = grep { $_->enter_bug } Bugzilla->active_custom_fields;
foreach my $field (@enter_bug_fields) {
$vars->{$field->name} = formvalue($field->name);
}
push( @values, $status );
# Custom fields
- foreach my $custom_field (Bugzilla->custom_field_names) {
+ foreach my $field (Bugzilla->active_custom_fields) {
+ my $custom_field = $field->name;
next unless defined($bug_fields{$custom_field});
- my $field = new Bugzilla::Field({name => $custom_field});
if ($field->type == FIELD_TYPE_FREETEXT) {
push(@query, $custom_field);
push(@values, clean_text($bug_fields{$custom_field}));
|| ThrowTemplateError($template->error());
# Include custom fields editable on bug creation.
-my @custom_bug_fields = grep {$_->type != FIELD_TYPE_MULTI_SELECT}
- Bugzilla->get_fields({ custom => 1, obsolete => 0, enter_bug => 1 });
+my @custom_bug_fields = grep {$_->type != FIELD_TYPE_MULTI_SELECT && $_->enter_bug}
+ Bugzilla->active_custom_fields;
# Undefined custom fields are ignored to ensure they will get their default
# value (e.g. "---" for custom single select fields).
$bug_params{'groups'} = \@selected_groups;
$bug_params{'comment'} = $comment;
-my @multi_selects = Bugzilla->get_fields(
- { type => FIELD_TYPE_MULTI_SELECT, custom => 1, obsolete => 0,
- enter_bug => 1 });
+my @multi_selects = grep {$_->type == FIELD_TYPE_MULTI_SELECT && $_->enter_bug}
+ Bugzilla->active_custom_fields;
+
foreach my $field (@multi_selects) {
$bug_params{$field->name} = [$cgi->param($field->name)];
}
deadline remaining_time estimated_time);
push(@set_fields, 'assigned_to') if !$cgi->param('set_default_assignee');
push(@set_fields, 'qa_contact') if !$cgi->param('set_default_qa_contact');
-my @custom_fields = Bugzilla->get_fields({custom => 1, obsolete => 0});
+my @custom_fields = Bugzilla->active_custom_fields;
my %methods = (
bug_severity => 'set_severity',
<tbody>
[% USE Bugzilla %]
- [% custom_fields = Bugzilla.get_fields({ obsolete => 0, custom => 1,
- enter_bug => 1 }) %]
- [% FOREACH field = custom_fields %]
+ [% FOREACH field = Bugzilla.active_custom_fields %]
+ [% NEXT UNLESS field.enter_bug %]
[% SET value = ${field.name} IF ${field.name}.defined %]
<tr>
[% PROCESS bug/field.html.tmpl editable=1 value_span=3 %]
[%# *** Custom Fields *** %]
[% USE Bugzilla %]
- [% fields = Bugzilla.get_fields({ obsolete => 0, custom => 1 }) %]
- [% IF fields %]
- [% FOREACH field = fields %]
- <tr>
- [% PROCESS bug/field.html.tmpl value=bug.${field.name}
- editable = bug.check_can_change_field(field.name, 0, 1)
- value_span = 2 %]
- </tr>
- [% END %]
+ [% FOREACH field = Bugzilla.active_custom_fields %]
+ <tr>
+ [% PROCESS bug/field.html.tmpl value=bug.${field.name}
+ editable = bug.check_can_change_field(field.name, 0, 1)
+ value_span = 2 %]
+ </tr>
[% END %]
[% END %]
[% USE Bugzilla %]
[% field_counter = 0 %]
- [% FOREACH field = Bugzilla.get_fields({ obsolete => 0, custom => 1 }) %]
+ [% FOREACH field = Bugzilla.active_custom_fields %]
[% field_counter = field_counter + 1 %]
[%# Odd-numbered fields get an opening <tr> %]
[% '<tr>' IF field_counter % 2 %]
[% END %]
[% USE Bugzilla %]
- [% FOREACH field = Bugzilla.get_fields({ obsolete => 0, custom => 1 }) %]
+ [% FOREACH field = Bugzilla.active_custom_fields %]
<tr>
[% PROCESS bug/field.html.tmpl value = dontchange
editable = 1