]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 415652: Implement Bugzilla->active_custom_fields - Patch by Frédéric Buclin...
authorlpsolit%gmail.com <>
Mon, 25 Feb 2008 22:06:24 +0000 (22:06 +0000)
committerlpsolit%gmail.com <>
Mon, 25 Feb 2008 22:06:24 +0000 (22:06 +0000)
14 files changed:
Bugzilla.pm
Bugzilla/Bug.pm
Bugzilla/Field.pm
buglist.cgi
colchange.cgi
config.cgi
enter_bug.cgi
importxml.pl
post_bug.cgi
process_bug.cgi
template/en/default/bug/create/create.html.tmpl
template/en/default/bug/edit.html.tmpl
template/en/default/bug/show-multiple.html.tmpl
template/en/default/list/edit-multiple.html.tmpl

index c77c039ceb3b994d22af6a68aea9235b464bf090..e35c75934c2676fd424a74ea55b1c0745d2328a6 100644 (file)
@@ -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 {
index 5cbe8a6198d0ab299934462373df43ba5a4618d9..a5d25885e944d27edd19d60e054878ae6028f3f1 100755 (executable)
@@ -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
     );
 }
 
index 5272f0ed679b88ac998ef4c37b5ca30aecc47814..0d7479034ded25c3b7e503144417cc37d6169120 100644 (file)
@@ -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(
index b87cdf970841e7fadd77c264cf9b650715fc6a8c..670844bb9502e5a21c0534433b81a2204c6cc811 100755 (executable)
@@ -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);
 }
 
index c580547ce3df35f7654565a1741ff8b54e9c25e8..b2d33de7efbf583bf4249fb91327371e2496a9e3 100755 (executable)
@@ -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;
index ad8dbf0fe529399244caf60a4f74ea8996325056..026b070d616ef93bf977fc9d6fd48e87c57b9f4a 100755 (executable)
@@ -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')) {
index cce5a431e58ba430e03bdf945317969a62ccc295..ee362e3020813e10acfd7989dbd0dc19f7ece048 100755 (executable)
@@ -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);
 }
index 80506971cf9b631d04a04a50a640b55fcdd07406..1ed9253b8b043d28971801cd5dfe22803afafffa 100755 (executable)
@@ -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}));
index fbfdf27f7578d68b2a085f3801110a32655d141f..957e7b75f0527f65b95f738b048bece0d7e89f31 100755 (executable)
@@ -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)];
 }
index 4ea6c1f7f947521b404b0ec651da40dc55bb74f5..93b2ec1ff3e83f5314c1219eb27705d84dc9b0a4 100755 (executable)
@@ -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',
index 8bc4ab4655c538518e5b0f32627c4d64210b0819..c8fd0fc10dd0b55b80163d9cf019d510cf1a8c88 100644 (file)
@@ -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 %]
index 63913beee0e7fb2add5c6980f14c8993beb604a0..1cdf5e7988a7a226f613c4899b1a84fa9f8c3d82 100644 (file)
 [%# *** 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 %]
 
index 2104c90a49e25a3a96160279c1d539a2ce07a151..2562903a6024b9f1252c05075110942aeb83870d 100644 (file)
 
     [% 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 %]
index 9aa110359e8c653df4a966781b2d919ff8bddff1..5607371eb7c7946cf370b94fe40f7c76a168bd9f 100644 (file)
   [% 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