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 { ...@@ -430,10 +430,13 @@ sub get_fields {
return @$fields; return @$fields;
} }
sub custom_field_names { sub active_custom_fields {
# Get a list of custom fields and convert it into a list of their names. my $class = shift;
return map($_->{name}, if (!exists $class->request_cache->{active_custom_fields}) {
@{Bugzilla::Field->match({ custom=>1, obsolete=>0 })}); $class->request_cache->{active_custom_fields} =
Bugzilla::Field->match({ custom => 1, obsolete => 0 });
}
return @{$class->request_cache->{active_custom_fields}};
} }
sub hook_args { sub hook_args {
......
...@@ -68,8 +68,8 @@ use constant LIST_ORDER => ID_FIELD; ...@@ -68,8 +68,8 @@ use constant LIST_ORDER => ID_FIELD;
# This is a sub because it needs to call other subroutines. # This is a sub because it needs to call other subroutines.
sub DB_COLUMNS { sub DB_COLUMNS {
my $dbh = Bugzilla->dbh; my $dbh = Bugzilla->dbh;
my @custom = Bugzilla->get_fields({ custom => 1, obsolete => 0}); my @custom = grep {$_->type != FIELD_TYPE_MULTI_SELECT}
@custom = grep {$_->type != FIELD_TYPE_MULTI_SELECT} @custom; Bugzilla->active_custom_fields;
my @custom_names = map {$_->name} @custom; my @custom_names = map {$_->name} @custom;
return qw( return qw(
alias alias
...@@ -130,8 +130,7 @@ sub VALIDATORS { ...@@ -130,8 +130,7 @@ sub VALIDATORS {
}; };
# Set up validators for custom fields. # Set up validators for custom fields.
my @custom_fields = Bugzilla->get_fields({custom => 1, obsolete => 0}); foreach my $field (Bugzilla->active_custom_fields) {
foreach my $field (@custom_fields) {
my $validator; my $validator;
if ($field->type == FIELD_TYPE_SINGLE_SELECT) { if ($field->type == FIELD_TYPE_SINGLE_SELECT) {
$validator = \&_check_select_field; $validator = \&_check_select_field;
...@@ -167,8 +166,8 @@ use constant UPDATE_VALIDATORS => { ...@@ -167,8 +166,8 @@ use constant UPDATE_VALIDATORS => {
}; };
sub UPDATE_COLUMNS { sub UPDATE_COLUMNS {
my @custom = Bugzilla->get_fields({ custom => 1, obsolete => 0}); my @custom = grep {$_->type != FIELD_TYPE_MULTI_SELECT}
@custom = grep {$_->type != FIELD_TYPE_MULTI_SELECT} @custom; Bugzilla->active_custom_fields;
my @custom_names = map {$_->name} @custom; my @custom_names = map {$_->name} @custom;
my @columns = qw( my @columns = qw(
alias alias
...@@ -566,8 +565,8 @@ sub update { ...@@ -566,8 +565,8 @@ sub update {
} }
# Insert the values into the multiselect value tables # Insert the values into the multiselect value tables
my @multi_selects = Bugzilla->get_fields( my @multi_selects = grep {$_->type == FIELD_TYPE_MULTI_SELECT}
{ custom => 1, type => FIELD_TYPE_MULTI_SELECT, obsolete => 0 }); Bugzilla->active_custom_fields;
foreach my $field (@multi_selects) { foreach my $field (@multi_selects) {
my $name = $field->name; my $name = $field->name;
my ($removed, $added) = diff_arrays($old_bug->$name, $self->$name); my ($removed, $added) = diff_arrays($old_bug->$name, $self->$name);
...@@ -625,8 +624,8 @@ sub update { ...@@ -625,8 +624,8 @@ sub update {
sub _extract_multi_selects { sub _extract_multi_selects {
my ($invocant, $params) = @_; my ($invocant, $params) = @_;
my @multi_selects = Bugzilla->get_fields( my @multi_selects = grep {$_->type == FIELD_TYPE_MULTI_SELECT}
{ custom => 1, type => FIELD_TYPE_MULTI_SELECT, obsolete => 0 }); Bugzilla->active_custom_fields;
my %ms_values; my %ms_values;
foreach my $field (@multi_selects) { foreach my $field (@multi_selects) {
my $name = $field->name; my $name = $field->name;
...@@ -1581,7 +1580,7 @@ sub fields { ...@@ -1581,7 +1580,7 @@ sub fields {
# Conditional Fields # Conditional Fields
Bugzilla->params->{'useqacontact'} ? "qa_contact" : (), Bugzilla->params->{'useqacontact'} ? "qa_contact" : (),
# Custom Fields # 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 ...@@ -30,17 +30,14 @@ Bugzilla::Field - a particular piece of information about bugs
print Dumper(Bugzilla->get_fields()); print Dumper(Bugzilla->get_fields());
# Display information about non-obsolete custom fields. # Display information about non-obsolete custom fields.
print Dumper(Bugzilla->get_fields({ obsolete => 1, custom => 1 })); print Dumper(Bugzilla->active_custom_fields);
# Display a list of the names of non-obsolete custom fields.
print Bugzilla->custom_field_names;
use Bugzilla::Field; use Bugzilla::Field;
# Display information about non-obsolete custom fields. # Display information about non-obsolete custom fields.
# Bugzilla->get_fields() is a wrapper around Bugzilla::Field->match(), # Bugzilla->get_fields() is a wrapper around Bugzilla::Field->match(),
# so both methods take the same arguments. # 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. # Create or update a custom field or field definition.
my $field = Bugzilla::Field->create( my $field = Bugzilla::Field->create(
......
...@@ -672,7 +672,7 @@ DefineColumn("percentage_complete", ...@@ -672,7 +672,7 @@ DefineColumn("percentage_complete",
DefineColumn("relevance" , "relevance" , "Relevance" ); DefineColumn("relevance" , "relevance" , "Relevance" );
DefineColumn("deadline" , $dbh->sql_date_format('bugs.deadline', '%Y-%m-%d') . " AS deadline", "Deadline"); 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); DefineColumn($field->name, 'bugs.' . $field->name, $field->description);
} }
......
...@@ -81,7 +81,7 @@ if (Bugzilla->user->in_group(Bugzilla->params->{"timetrackinggroup"})) { ...@@ -81,7 +81,7 @@ if (Bugzilla->user->in_group(Bugzilla->params->{"timetrackinggroup"})) {
push(@masterlist, ("short_desc", "short_short_desc")); push(@masterlist, ("short_desc", "short_short_desc"));
my @custom_fields = grep { $_->type != FIELD_TYPE_MULTI_SELECT } 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); push(@masterlist, map { $_->name } @custom_fields);
$vars->{'masterlist'} = \@masterlist; $vars->{'masterlist'} = \@masterlist;
......
...@@ -56,8 +56,8 @@ $vars->{'keyword'} = [map($_->name, Bugzilla::Keyword->get_all)]; ...@@ -56,8 +56,8 @@ $vars->{'keyword'} = [map($_->name, Bugzilla::Keyword->get_all)];
$vars->{'resolution'} = get_legal_field_values('resolution'); $vars->{'resolution'} = get_legal_field_values('resolution');
$vars->{'status'} = get_legal_field_values('bug_status'); $vars->{'status'} = get_legal_field_values('bug_status');
$vars->{'custom_fields'} = $vars->{'custom_fields'} =
[Bugzilla->get_fields({custom => 1, obsolete => 0, type => FIELD_TYPE_SINGLE_SELECT}), [ grep {$_->type == FIELD_TYPE_SINGLE_SELECT || $_->type == FIELD_TYPE_MULTI_SELECT}
Bugzilla->get_fields({custom => 1, obsolete => 0, type => FIELD_TYPE_MULTI_SELECT})]; Bugzilla->active_custom_fields ];
# Include a list of product objects. # Include a list of product objects.
if ($cgi->param('product')) { if ($cgi->param('product')) {
......
...@@ -383,8 +383,7 @@ $vars->{'cloned_bug_id'} = $cloned_bug_id; ...@@ -383,8 +383,7 @@ $vars->{'cloned_bug_id'} = $cloned_bug_id;
$vars->{'token'} = issue_session_token('createbug:'); $vars->{'token'} = issue_session_token('createbug:');
my @enter_bug_fields = Bugzilla->get_fields({ custom => 1, obsolete => 0, my @enter_bug_fields = grep { $_->enter_bug } Bugzilla->active_custom_fields;
enter_bug => 1 });
foreach my $field (@enter_bug_fields) { foreach my $field (@enter_bug_fields) {
$vars->{$field->name} = formvalue($field->name); $vars->{$field->name} = formvalue($field->name);
} }
......
...@@ -1028,9 +1028,9 @@ sub process_bug { ...@@ -1028,9 +1028,9 @@ sub process_bug {
push( @values, $status ); push( @values, $status );
# Custom fields # 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}); next unless defined($bug_fields{$custom_field});
my $field = new Bugzilla::Field({name => $custom_field});
if ($field->type == FIELD_TYPE_FREETEXT) { if ($field->type == FIELD_TYPE_FREETEXT) {
push(@query, $custom_field); push(@query, $custom_field);
push(@values, clean_text($bug_fields{$custom_field})); push(@values, clean_text($bug_fields{$custom_field}));
......
...@@ -124,8 +124,8 @@ $template->process($format->{'template'}, $vars, \$comment) ...@@ -124,8 +124,8 @@ $template->process($format->{'template'}, $vars, \$comment)
|| ThrowTemplateError($template->error()); || ThrowTemplateError($template->error());
# Include custom fields editable on bug creation. # Include custom fields editable on bug creation.
my @custom_bug_fields = grep {$_->type != FIELD_TYPE_MULTI_SELECT} my @custom_bug_fields = grep {$_->type != FIELD_TYPE_MULTI_SELECT && $_->enter_bug}
Bugzilla->get_fields({ custom => 1, obsolete => 0, enter_bug => 1 }); Bugzilla->active_custom_fields;
# Undefined custom fields are ignored to ensure they will get their default # Undefined custom fields are ignored to ensure they will get their default
# value (e.g. "---" for custom single select fields). # value (e.g. "---" for custom single select fields).
...@@ -167,9 +167,9 @@ $bug_params{'cc'} = [$cgi->param('cc')]; ...@@ -167,9 +167,9 @@ $bug_params{'cc'} = [$cgi->param('cc')];
$bug_params{'groups'} = \@selected_groups; $bug_params{'groups'} = \@selected_groups;
$bug_params{'comment'} = $comment; $bug_params{'comment'} = $comment;
my @multi_selects = Bugzilla->get_fields( my @multi_selects = grep {$_->type == FIELD_TYPE_MULTI_SELECT && $_->enter_bug}
{ type => FIELD_TYPE_MULTI_SELECT, custom => 1, obsolete => 0, Bugzilla->active_custom_fields;
enter_bug => 1 });
foreach my $field (@multi_selects) { foreach my $field (@multi_selects) {
$bug_params{$field->name} = [$cgi->param($field->name)]; $bug_params{$field->name} = [$cgi->param($field->name)];
} }
......
...@@ -307,7 +307,7 @@ my @set_fields = qw(op_sys rep_platform priority bug_severity ...@@ -307,7 +307,7 @@ my @set_fields = qw(op_sys rep_platform priority bug_severity
deadline remaining_time estimated_time); deadline remaining_time estimated_time);
push(@set_fields, 'assigned_to') if !$cgi->param('set_default_assignee'); push(@set_fields, 'assigned_to') if !$cgi->param('set_default_assignee');
push(@set_fields, 'qa_contact') if !$cgi->param('set_default_qa_contact'); 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 = ( my %methods = (
bug_severity => 'set_severity', bug_severity => 'set_severity',
......
...@@ -421,10 +421,9 @@ function handleWantsAttachment(wants_attachment) { ...@@ -421,10 +421,9 @@ function handleWantsAttachment(wants_attachment) {
<tbody> <tbody>
[% USE Bugzilla %] [% 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 %] [% SET value = ${field.name} IF ${field.name}.defined %]
<tr> <tr>
[% PROCESS bug/field.html.tmpl editable=1 value_span=3 %] [% PROCESS bug/field.html.tmpl editable=1 value_span=3 %]
......
...@@ -907,16 +907,13 @@ ...@@ -907,16 +907,13 @@
[%# *** Custom Fields *** %] [%# *** Custom Fields *** %]
[% USE Bugzilla %] [% USE Bugzilla %]
[% fields = Bugzilla.get_fields({ obsolete => 0, custom => 1 }) %] [% FOREACH field = Bugzilla.active_custom_fields %]
[% IF fields %]
[% FOREACH field = fields %]
<tr> <tr>
[% PROCESS bug/field.html.tmpl value=bug.${field.name} [% PROCESS bug/field.html.tmpl value=bug.${field.name}
editable = bug.check_can_change_field(field.name, 0, 1) editable = bug.check_can_change_field(field.name, 0, 1)
value_span = 2 %] value_span = 2 %]
</tr> </tr>
[% END %] [% END %]
[% END %]
[% END %] [% END %]
[%############################################################################%] [%############################################################################%]
......
...@@ -178,7 +178,7 @@ ...@@ -178,7 +178,7 @@
[% USE Bugzilla %] [% USE Bugzilla %]
[% field_counter = 0 %] [% field_counter = 0 %]
[% FOREACH field = Bugzilla.get_fields({ obsolete => 0, custom => 1 }) %] [% FOREACH field = Bugzilla.active_custom_fields %]
[% field_counter = field_counter + 1 %] [% field_counter = field_counter + 1 %]
[%# Odd-numbered fields get an opening <tr> %] [%# Odd-numbered fields get an opening <tr> %]
[% '<tr>' IF field_counter % 2 %] [% '<tr>' IF field_counter % 2 %]
......
...@@ -240,7 +240,7 @@ ...@@ -240,7 +240,7 @@
[% END %] [% END %]
[% USE Bugzilla %] [% USE Bugzilla %]
[% FOREACH field = Bugzilla.get_fields({ obsolete => 0, custom => 1 }) %] [% FOREACH field = Bugzilla.active_custom_fields %]
<tr> <tr>
[% PROCESS bug/field.html.tmpl value = dontchange [% PROCESS bug/field.html.tmpl value = dontchange
editable = 1 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