}
sub active_custom_fields {
- my (undef, $params) = @_;
- my $cache_id = 'active_custom_fields';
- my $can_cache = !exists $params->{bug_id};
- if ($params) {
+ my (undef, $params, $wants) = @_;
+ my $cache_id = 'active_custom_fields';
+ my $can_cache = !exists $params->{bug_id} && !$wants;
+ if ($can_cache && $params) {
$cache_id .= ($params->{product} ? '_p' . $params->{product}->id : '')
. ($params->{component} ? '_c' . $params->{component}->id : '');
$cache_id .= ':noext' if $params->{skip_extensions};
}
- if (!$can_cache || !exists request_cache->{$cache_id}) {
- my $fields
- = Bugzilla::Field->match({custom => 1, obsolete => 0, skip_extensions => 1});
- Bugzilla::Hook::process('active_custom_fields',
- {fields => \$fields, params => $params});
- if ($can_cache) {
- request_cache->{$cache_id} = $fields;
- }
- else {
- return @$fields;
+
+ if ($can_cache && exists request_cache->{$cache_id}) {
+ return @{request_cache->{$cache_id}};
+ }
+ else {
+ my $match_params = {custom => 1, obsolete => 0, skip_extensions => 1};
+ if ($wants) {
+ if ($wants->exclude->{custom}) {
+ return ();
+ }
+ elsif ($wants->is_specific) {
+ my @names = (grep {/^cf_/} $wants->includes);
+ return () unless @names;
+ $match_params->{name} = \@names;
+ }
}
+ my $fields = Bugzilla::Field->match($match_params);
+ Bugzilla::Hook::process('active_custom_fields',
+ {fields => \$fields, params => $params, wants => $wants});
+ request_cache->{$cache_id} = $fields if $can_cache;
+ return @$fields;
}
- return @{request_cache->{$cache_id}};
}
sub has_flags {
}
sub wants_object {
- my ($self) = @_;
- return $self->{__wants_object} if $self->{__wants_object};
- my $params = Bugzilla->input_params;
- my $wants = Bugzilla::WebService::Wants->new(
- cache => Bugzilla->request_cache->{filter_wants} ||= {},
- maybe include_fields => $params->{include_fields},
- maybe exclude_fields => $params->{exclude_fields},
- );
- return $self->{__wants_object} = $wants;
+ my ($class) = @_;
+ my $cache = Bugzilla->request_cache;
+
+ return $cache->{filter_wants_object} //= do {
+ my $params = Bugzilla->input_params;
+ Bugzilla::WebService::Wants->new(
+ cache => $cache->{filter_wants} ||= {},
+ maybe include_fields => $params->{include_fields},
+ maybe exclude_fields => $params->{exclude_fields},
+ );
+ };
}
1;
}
# And now custom fields
- my @custom_fields = Bugzilla->active_custom_fields({
- product => $bug->product_obj,
- component => $bug->component_obj,
- bug_id => $bug->id
- });
+ my @custom_fields = Bugzilla->active_custom_fields(
+ {
+ product => $bug->product_obj,
+ component => $bug->component_obj,
+ bug_id => $bug->id
+ },
+ $self->wants_object,
+ );
foreach my $field (@custom_fields) {
my $name = $field->name;
next if !filter_wants($params, $name, ['default', 'custom']);
sub active_custom_fields {
my ($self, $args) = @_;
+ my $wants = $args->{'wants'};
my $fields = $args->{'fields'};
my $params = $args->{'params'};
my $product = $params->{'product'};
my $component = $params->{'component'};
return if $params->{skip_extensions};
+ if ($wants && $wants->is_specific) {
+ return if none { $wants->include->{$_} } Bugzilla->tracking_flag_names;
+ }
# Create a hash of current fields based on field names
my %field_hash = map { $_->name => $_ } @$$fields;