Commit 85e75aba authored by Tiago Mello's avatar Tiago Mello

Bug 586871: Convert all Bugzilla->get_fields calls to Bugzilla->fields

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