]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 586871: Convert all Bugzilla->get_fields calls to Bugzilla->fields
authorTiago Mello <timello@gmail.com>
Tue, 24 Aug 2010 20:25:49 +0000 (17:25 -0300)
committerTiago Mello <timello@gmail.com>
Tue, 24 Aug 2010 20:25:49 +0000 (17:25 -0300)
r/a=mkanat

16 files changed:
Bugzilla.pm
Bugzilla/Bug.pm
Bugzilla/BugMail.pm
Bugzilla/Field.pm
Bugzilla/Install/DB.pm
Bugzilla/Migrate.pm
Bugzilla/Search.pm
Bugzilla/Search/Quicksearch.pm
Bugzilla/WebService/Bug.pm
editvalues.cgi
query.cgi
report.cgi
template/en/default/admin/custom_fields/cf-js.js.tmpl
template/en/default/admin/custom_fields/create.html.tmpl
template/en/default/admin/custom_fields/edit.html.tmpl
template/en/default/admin/custom_fields/list.html.tmpl

index d97049678289fcb6c6362f901f9cf4a7c49edcf2..c911de73351f8f5d13c181be2f9690ab4257038d 100644 (file)
@@ -563,28 +563,27 @@ sub fields {
 
     my $fields = $cache->{fields};
     my %requested;
-    if (my $types = $criteria->{type}) {
+    if (my $types = delete $criteria->{type}) {
         $types = ref($types) ? $types : [$types];
         %requested = map { %{ $fields->{by_type}->{$_} || {} } } @$types;
     }
     else {
         %requested = %{ $fields->{by_name} };
     }
-    
-    my $do_by_name = $criteria->{by_name};
 
-    return $do_by_name ? \%requested : [values %requested];
-}
+    my $do_by_name = delete $criteria->{by_name};
 
-# DEPRECATED. Use fields() instead.
-sub get_fields {
-    my $class = shift;
-    my $criteria = shift;
-    # This function may be called during installation, and Field::match
-    # may fail at that time. so we want to return an empty list in that
-    # case.
-    my $fields = eval { Bugzilla::Field->match($criteria) } || [];
-    return @$fields;
+    # Filtering before returning the fields based on
+    # the criterias.
+    foreach my $filter (keys %$criteria) {
+        foreach my $field (keys %requested) {
+            if ($requested{$field}->$filter != $criteria->{$filter}) {
+                delete $requested{$field};
+            }
+        }
+    }
+
+    return $do_by_name ? \%requested : [values %requested];
 }
 
 sub active_custom_fields {
index 915ce5307e77be03d716189625aeff897a30f891..4c89223528b192ec9edcc186f96befdcaa474221 100644 (file)
@@ -195,11 +195,11 @@ sub VALIDATOR_DEPENDENCIES {
         version          => ['product'],
     );
 
-    my @custom_deps = Bugzilla->get_fields(
-        { visibility_field_id => NOT_NULL });
-    foreach my $field (@custom_deps) {
-        $deps{$field->name} = [$field->visibility_field->name];
+    foreach my $field (@{ Bugzilla->fields }) {
+        $deps{$field->name} = [ $field->visibility_field->name ]
+            if $field->{visibility_field_id};
     }
+
     $cache->{bug_validator_dependencies} = \%deps;
     return \%deps;
 };
@@ -242,7 +242,7 @@ use constant NUMERIC_COLUMNS => qw(
 );
 
 sub DATE_COLUMNS {
-    my @fields = Bugzilla->get_fields({ type => FIELD_TYPE_DATETIME });
+    my @fields = @{ Bugzilla->fields({ type => FIELD_TYPE_DATETIME }) };
     return map { $_->name } @fields;
 }
 
@@ -739,9 +739,9 @@ sub run_create_validators {
     Bugzilla::Hook::process('bug_end_of_create_validators',
                             { params => $params });
 
-    my @mandatory_fields = Bugzilla->get_fields({ is_mandatory => 1,
-                                                  enter_bug    => 1,
-                                                  obsolete     => 0 });
+    my @mandatory_fields = @{ Bugzilla->fields({ is_mandatory => 1,
+                                                 enter_bug    => 1,
+                                                 obsolete     => 0 }) };
     foreach my $field (@mandatory_fields) {
         $class->_check_field_is_mandatory($params->{$field->name}, $field,
                                           $params);
@@ -3501,7 +3501,7 @@ sub bug_alias_to_id {
 sub editable_bug_fields {
     my @fields = Bugzilla->dbh->bz_table_columns('bugs');
     # Obsolete custom fields are not editable.
-    my @obsolete_fields = Bugzilla->get_fields({obsolete => 1, custom => 1});
+    my @obsolete_fields = @{ Bugzilla->fields({obsolete => 1, custom => 1}) };
     @obsolete_fields = map { $_->name } @obsolete_fields;
     foreach my $remove ("bug_id", "reporter", "creation_ts", "delta_ts", 
                         "lastdiffed", @obsolete_fields) 
@@ -4061,8 +4061,9 @@ sub AUTOLOAD {
 
       return $self->{$attr} if defined $self->{$attr};
 
-      $self->{_multi_selects} ||= [Bugzilla->get_fields(
-          {custom => 1, type => FIELD_TYPE_MULTI_SELECT })];
+      $self->{_multi_selects} ||= Bugzilla->fields(
+          { custom => 1, type => FIELD_TYPE_MULTI_SELECT });
+
       if ( grep($_->name eq $attr, @{$self->{_multi_selects}}) ) {
           # There is a bug in Perl 5.10.0, which is fixed in 5.10.1,
           # which taints $attr at this point. trick_taint() can go
index c76b7dbbd5e95969b8de52a56c28ef451bbc3b32..2ac5752938c7b9def44e1ab177d5ac0ad10852ee 100644 (file)
@@ -408,7 +408,7 @@ sub _get_diffs {
 
 sub _get_new_bugmail_fields {
     my $bug = shift;
-    my @fields = Bugzilla->get_fields({obsolete => 0, mailhead => 1});
+    my @fields = @{ Bugzilla->fields({obsolete => 0, in_new_bugmail => 1}) };
     my @diffs;
 
     foreach my $field (@fields) {
index ee11689361a549836430f2da53baab19f5bac61a..daf708179279f4891e75bd6c7b23a6ff39c89097 100644 (file)
@@ -28,7 +28,7 @@ Bugzilla::Field - a particular piece of information about bugs
   use Data::Dumper;
 
   # Display information about all fields.
-  print Dumper(Bugzilla->get_fields());
+  print Dumper(Bugzilla->fields());
 
   # Display information about non-obsolete custom fields.
   print Dumper(Bugzilla->active_custom_fields);
@@ -36,9 +36,9 @@ Bugzilla::Field - a particular piece of information about bugs
   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 => 0, custom => 1 }));
+  # Bugzilla->fields() is a wrapper around Bugzilla::Field->get_all(),
+  # with arguments which filter the fields before returning them.
+  print Dumper(Bugzilla->fields({ obsolete => 0, custom => 1 }));
 
   # Create or update a custom field or field definition.
   my $field = Bugzilla::Field->create(
index 01270aab663b08264b5efc3f5b960da974231ce3..bfce7779f545e040e4b987297b1dbdd7008e3025 100644 (file)
@@ -3257,9 +3257,9 @@ sub _fix_logincookies_ipaddr {
 }
 
 sub _fix_invalid_custom_field_names {
-    my @fields = Bugzilla->get_fields({ custom => 1 });
+    my $fields = Bugzilla->fields({ custom => 1 });
 
-    foreach my $field (@fields) {
+    foreach my $field (@$fields) {
         next if $field->name =~ /^[a-zA-Z0-9_]+$/;
         # The field name is illegal and can break the DB. Kill the field!
         $field->set_obsolete(1);
index e72c5c52e6926dd16b749e983066aea96a6593e7..8c38408000e3d7622a34860b9b8c04762aed4531 100644 (file)
@@ -254,7 +254,7 @@ sub debug {
 
 sub bug_fields {
     my $self = shift;
-    $self->{bug_fields} ||= { map { $_->{name} => $_ } Bugzilla->get_fields };
+    $self->{bug_fields} ||= Bugzilla->fields({ by_name => 1 });
     return $self->{bug_fields};
 }
 
index abd3fd53ea475e8199cdae2ed112ddd9d9c694e4..cde1f8e350268ac5876a8ccbf56dc0cfa3ef91a9 100644 (file)
@@ -557,7 +557,8 @@ sub COLUMNS {
     }
 
     # Do the actual column-getting from fielddefs, now.
-    foreach my $field (Bugzilla->get_fields({ obsolete => 0, buglist => 1 })) {
+    my @fields = @{ Bugzilla->fields({ obsolete => 0, buglist => 1 }) };
+    foreach my $field (@fields) {
         my $id = $field->name;
         $id = $old_names{$id} if exists $old_names{$id};
         my $sql;
@@ -593,8 +594,8 @@ sub REPORT_COLUMNS {
            flagtypes.name keywords relevance);
 
     # Multi-select fields are not currently supported.
-    my @multi_selects = Bugzilla->get_fields(
-        { obsolete => 0, type => FIELD_TYPE_MULTI_SELECT });
+    my @multi_selects = @{Bugzilla->fields(
+        { obsolete => 0, type => FIELD_TYPE_MULTI_SELECT })};
     push(@no_report_columns, map { $_->name } @multi_selects);
 
     # If you're not a time-tracker, you can't use time-tracking
index b96dd3d4d54b3d45a614fef2f09f09d75fc96951..602b78af0f8d973bb64732008cb4c3aac4d96ccc 100644 (file)
@@ -80,7 +80,7 @@ sub FIELD_MAP {
     # Get all the fields whose names don't contain periods. (Fields that
     # contain periods are always handled in MAPPINGS.) 
     my @db_fields = grep { $_->name !~ /\./ } 
-                         Bugzilla->get_fields({ obsolete => 0 });
+                         @{ Bugzilla->fields({ obsolete => 0 }) };
     my %full_map = (%{ MAPPINGS() }, map { $_->name => $_->name } @db_fields);
 
     # Eliminate the fields that start with bug_ or rep_, because those are
index 8558e04f7789e343f6b2818940e307272906917a..95335538583f902ebdf91738bdccef37d6e27f6e 100644 (file)
@@ -104,7 +104,7 @@ sub fields {
     }
 
     if (!defined $params->{ids} and !defined $params->{names}) {
-        @fields = Bugzilla->get_fields({ obsolete => 0 });
+        @fields = @{ Bugzilla->fields({ obsolete => 0 }) };
     }
 
     my @fields_out;
@@ -558,8 +558,8 @@ sub legal_values {
     my $field = Bugzilla::Bug::FIELD_MAP->{$params->{field}} 
                 || $params->{field};
 
-    my @global_selects = grep { !$_->is_abnormal }
-                         Bugzilla->get_fields({ is_select => 1 });
+    my @global_selects =
+        @{ Bugzilla->fields({ is_select => 1, is_abnormal => 0 }) };
 
     my $values;
     if (grep($_->name eq $field, @global_selects)) {
index 3f08a1671f52a9623f4f1a2fe18371200b5fb824..53ea78512054a59f85dfaef4cee95210f2d82943 100755 (executable)
@@ -75,8 +75,8 @@ my $token  = $cgi->param('token');
 # field = '' -> Show nice list of fields
 #
 if (!$cgi->param('field')) {
-    my @field_list = grep { !$_->is_abnormal }
-                          Bugzilla->get_fields({ is_select => 1 });
+    my @field_list =
+        @{ Bugzilla->fields({ is_select => 1, is_abnormal => 0 }) };
 
     $vars->{'fields'} = \@field_list;
     $template->process("admin/fieldvalues/select-field.html.tmpl", $vars)
index d45a950b28688191af6c361f5a851cbdcea8e252..39bee889bececf8f4fc90188a1dcaa0ddb0b4aa4 100755 (executable)
--- a/query.cgi
+++ b/query.cgi
@@ -225,7 +225,7 @@ $vars->{'bug_severity'} = Bugzilla::Field->new({name => 'bug_severity'})->legal_
 $vars->{'resolution'} = Bugzilla::Field->new({name => 'resolution'})->legal_values;
 
 # Boolean charts
-my @fields = Bugzilla->get_fields({ obsolete => 0 });
+my @fields = @{ Bugzilla->fields({ obsolete => 0 }) };
 
 # If we're not in the time-tracking group, exclude time-tracking fields.
 if (!Bugzilla->user->is_timetracker) {
index dd5a0bb1593520a325093fca0814706b8b19c7ef..d3751aa67faab066ed61764a64ff63bc97024054 100755 (executable)
@@ -319,7 +319,7 @@ sub get_names {
     
     # These are all the fields we want to preserve the order of in reports.
     my %fields;
-    my @select_fields = Bugzilla->get_fields({ is_select => 1 });
+    my @select_fields = @{ Bugzilla->fields({ is_select => 1 }) };
     foreach my $field (@select_fields) {
         my @names =  map($_->name, @{$field->legal_values});
         unshift @names, ' ' if $field->name eq 'resolution'; 
index 528b88b2d10d32a167ad69dc02b09419e2287fc4..f9c31b5c769190224c0af4d6894aa9ead8b44555 100644 (file)
@@ -25,7 +25,7 @@ function toggleCheckbox(this_checkbox, other_checkbox_id) {
 
 var select_values = new Array();
 [% USE Bugzilla %]
-[% FOREACH sel_field = Bugzilla.get_fields({ is_select => 1 }) %]
+[% FOREACH sel_field = Bugzilla.fields({ is_select => 1 }) %]
   select_values[[% sel_field.id FILTER js %]] = [
   [% FOREACH legal_value = sel_field.legal_values %]
     [%# Prefix components with the name of their product so that admins
index fcdf73bc78df0ddb356f30220e6cf36cc6be5e3d..b96738473c1b64fdb4416281991902c2e677fbe1 100644 (file)
@@ -123,7 +123,7 @@ YAHOO.util.Event.onDOMReady(function() {onChangeType(document.getElementById('ty
         <select name="visibility_field_id" id="visibility_field_id"
                 onchange="onChangeVisibilityField()">
           <option></option>
-          [% FOREACH sel_field = Bugzilla.get_fields({ is_select => 1 }) %]
+          [% FOREACH sel_field = Bugzilla.fields({ is_select => 1 }) %]
             <option value="[% sel_field.id FILTER html %]">
               [% sel_field.description FILTER html %]
               ([% sel_field.name FILTER html %])
@@ -149,7 +149,7 @@ YAHOO.util.Event.onDOMReady(function() {onChangeType(document.getElementById('ty
       <td>
         <select disabled="disabled" name="value_field_id" id="value_field_id">
           <option></option>
-          [% FOREACH sel_field = Bugzilla.get_fields({ is_select => 1 }) %]
+          [% FOREACH sel_field = Bugzilla.fields({ is_select => 1 }) %]
             <option value="[% sel_field.id FILTER html %]">
               [% sel_field.description FILTER html %]
               ([% sel_field.name FILTER html %])
index ec4e3276d0b754e201b99dfc6d0ef3a650f21221..48c3396f30cb478e8d4a9614350ef14c47fac09f 100644 (file)
         <select name="visibility_field_id" id="visibility_field_id"
                 onchange="onChangeVisibilityField()">
           <option></option>
-          [% FOREACH sel_field = Bugzilla.get_fields({ is_select => 1 }) %]
+          [% FOREACH sel_field = Bugzilla.fields({ is_select => 1 }) %]
             [% NEXT IF sel_field.id == field.id %]
             <option value="[% sel_field.id FILTER html %]"
              [% ' selected="selected"' 
         <td>
           <select name="value_field_id" id="value_field_id">
             <option></option>
-            [% FOREACH sel_field = Bugzilla.get_fields({ is_select => 1 }) %]
+            [% FOREACH sel_field = Bugzilla.fields({ is_select => 1 }) %]
               [% NEXT IF sel_field.id == field.id %]
               <option value="[% sel_field.id FILTER html %]"
                [% ' selected="selected"' 
index 385650a632272ef948d25de0ffdf64f198b23764..689aa059171bc9f654f21f96aef20c5ccb088b33 100644 (file)
@@ -69,7 +69,7 @@
 %]
 
 [% USE Bugzilla %]
-[% custom_fields = Bugzilla.get_fields({ custom => 1 }) %]
+[% custom_fields = Bugzilla.fields({ custom => 1 }) %]
 
 [%# We want to display the type name of fields, not their type ID. %]
 [% overrides.type = {} %]