From 85e75aba6a7131da9d63b1f628a27e986bb428c5 Mon Sep 17 00:00:00 2001 From: Tiago Mello Date: Tue, 24 Aug 2010 17:25:49 -0300 Subject: Bug 586871: Convert all Bugzilla->get_fields calls to Bugzilla->fields r/a=mkanat --- Bugzilla.pm | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) (limited to 'Bugzilla.pm') diff --git a/Bugzilla.pm b/Bugzilla.pm index d97049678..c911de733 100644 --- a/Bugzilla.pm +++ b/Bugzilla.pm @@ -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 { -- cgit v1.2.3-24-g4f1b