summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTiago Mello <timello@gmail.com>2010-08-24 23:03:20 +0200
committerTiago Mello <timello@gmail.com>2010-08-24 23:03:20 +0200
commitd94865b30a92be8a3a900f8d1d8262d36044b1ca (patch)
tree529e23fb497c5100c9e63432d6ddb7dc9e24058c
parent85e75aba6a7131da9d63b1f628a27e986bb428c5 (diff)
downloadbugzilla-d94865b30a92be8a3a900f8d1d8262d36044b1ca.tar.gz
bugzilla-d94865b30a92be8a3a900f8d1d8262d36044b1ca.tar.xz
Bug 583243: Add a new hook 'search_operator_field_override'.
r/a=mkanat
-rw-r--r--Bugzilla/Hook.pm23
-rw-r--r--Bugzilla/Search.pm23
-rw-r--r--extensions/Example/Extension.pm21
3 files changed, 64 insertions, 3 deletions
diff --git a/Bugzilla/Hook.pm b/Bugzilla/Hook.pm
index e00289344..789ad8740 100644
--- a/Bugzilla/Hook.pm
+++ b/Bugzilla/Hook.pm
@@ -433,6 +433,29 @@ The definition is structured as:
=back
+=head2 search_operator_field_override
+
+This allows you to modify L<Bugzilla::Search/OPERATOR_FIELD_OVERRIDE>,
+which determines the search functions for fields. It allows you to specify
+custom search functionality for certain fields.
+
+See L<Bugzilla::Search/OPERATOR_FIELD_OVERRIDE> for reference and see
+the code in the example extension.
+
+Note that the interface to this hook is B<UNSTABLE> and it may change in the
+future.
+
+Params:
+
+=over
+
+=item C<operators> - See L<Bugzilla::Search/OPERATOR_FIELD_OVERRIDE> to get
+an idea of the structure.
+
+=item C<search> - The L<Bugzilla::Search> object.
+
+=back
+
=head2 bugmail_recipients
This allows you to modify the list of users who are going to be receiving
diff --git a/Bugzilla/Search.pm b/Bugzilla/Search.pm
index cde1f8e35..0a5b5eb22 100644
--- a/Bugzilla/Search.pm
+++ b/Bugzilla/Search.pm
@@ -1597,16 +1597,17 @@ sub do_search_function {
return if $args->{term};
}
- my $override = OPERATOR_FIELD_OVERRIDE->{$actual_field};
+ my $operator_field_override = $self->_get_operator_field_override();
+ my $override = $operator_field_override->{$actual_field};
if (!$override) {
# Multi-select fields get special handling.
if ($self->_multi_select_fields->{$actual_field}) {
- $override = OPERATOR_FIELD_OVERRIDE->{_multi_select};
+ $override = $operator_field_override->{_multi_select};
}
# And so do attachment fields, if they don't have a specific
# individual override.
elsif ($actual_field =~ /^attachments\./) {
- $override = OPERATOR_FIELD_OVERRIDE->{attachments};
+ $override = $operator_field_override->{attachments};
}
}
@@ -1671,6 +1672,22 @@ sub _pick_override_function {
return $search_func;
}
+sub _get_operator_field_override {
+ my $self = shift;
+ my $cache = Bugzilla->request_cache;
+
+ return $cache->{operator_field_override}
+ if defined $cache->{operator_field_override};
+
+ my %operator_field_override = %{ OPERATOR_FIELD_OVERRIDE() };
+ Bugzilla::Hook::process('search_operator_field_override',
+ { search => $self,
+ operators => \%operator_field_override });
+
+ $cache->{operator_field_override} = \%operator_field_override;
+ return $cache->{operator_field_override};
+}
+
###########################
# Search Function Helpers #
###########################
diff --git a/extensions/Example/Extension.pm b/extensions/Example/Extension.pm
index 87061aa06..4d85d01f8 100644
--- a/extensions/Example/Extension.pm
+++ b/extensions/Example/Extension.pm
@@ -196,6 +196,27 @@ sub buglist_columns {
$columns->{'example'} = { 'name' => 'bugs.delta_ts' , 'title' => 'Example' };
}
+sub search_operator_field_override {
+ my ($self, $args) = @_;
+
+ my $operators = $args->{'operators'};
+
+ my $original = $operators->{component}->{_non_changed};
+ $operators->{component} = {
+ _non_changed => sub { _component_nonchanged($original, @_) }
+ };
+}
+
+sub _component_nonchanged {
+ my $original = shift;
+ my ($invocant, $args) = @_;
+
+ $invocant->$original($args);
+ # Actually, it does not change anything in the result,
+ # just an example.
+ $args->{term} = $args->{term} . " OR 1=2";
+}
+
sub bugmail_recipients {
my ($self, $args) = @_;
my $recipients = $args->{recipients};