Commit 816eb1e9 authored by lpsolit%gmail.com's avatar lpsolit%gmail.com

Bug 415652: Implement Bugzilla->active_custom_fields - Patch by Fré©ric…

Bug 415652: Implement Bugzilla->active_custom_fields - Patch by Fré©ric Buclin <LpSolit@gmail.com> r/a=mkanat
parent 8ef50bda
......@@ -430,10 +430,13 @@ sub get_fields {
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 {
......
......@@ -68,8 +68,8 @@ use constant LIST_ORDER => ID_FIELD;
# 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
......@@ -130,8 +130,7 @@ sub VALIDATORS {
};
# 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;
......@@ -167,8 +166,8 @@ use constant UPDATE_VALIDATORS => {
};
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
......@@ -566,8 +565,8 @@ sub update {
}
# 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);
......@@ -625,8 +624,8 @@ sub update {
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;
......@@ -1581,7 +1580,7 @@ sub fields {
# Conditional Fields
Bugzilla->params->{'useqacontact'} ? "qa_contact" : (),
# Custom Fields
Bugzilla->custom_field_names
map { $_->name } Bugzilla->active_custom_fields
);
}
......
......@@ -30,17 +30,14 @@ Bugzilla::Field - a particular piece of information about bugs
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(
......
......@@ -672,7 +672,7 @@ DefineColumn("percentage_complete",
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);
}
......
......@@ -81,7 +81,7 @@ if (Bugzilla->user->in_group(Bugzilla->params->{"timetrackinggroup"})) {
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;
......
......@@ -56,8 +56,8 @@ $vars->{'keyword'} = [map($_->name, Bugzilla::Keyword->get_all)];
$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')) {
......
......@@ -383,8 +383,7 @@ $vars->{'cloned_bug_id'} = $cloned_bug_id;
$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);
}
......
......@@ -1028,9 +1028,9 @@ sub process_bug {
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}));
......
......@@ -124,8 +124,8 @@ $template->process($format->{'template'}, $vars, \$comment)
|| 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).
......@@ -167,9 +167,9 @@ $bug_params{'cc'} = [$cgi->param('cc')];
$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)];
}
......
......@@ -307,7 +307,7 @@ my @set_fields = qw(op_sys rep_platform priority bug_severity
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',
......
......@@ -421,10 +421,9 @@ function handleWantsAttachment(wants_attachment) {
<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 %]
......
......@@ -907,15 +907,12 @@
[%# *** 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 %]
......
......@@ -178,7 +178,7 @@
[% 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 %]
......
......@@ -240,7 +240,7 @@
[% 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
......
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