]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 583243: Add new hook 'search_operator_field_override'
authorTiago Mello <timello@gmail.com>
Tue, 24 Aug 2010 21:19:56 +0000 (18:19 -0300)
committerTiago Mello <timello@gmail.com>
Tue, 24 Aug 2010 21:19:56 +0000 (18:19 -0300)
r/a=mkanat

Bugzilla/Hook.pm
Bugzilla/Search.pm
extensions/Example/Extension.pm

index e0028934484a8860547e4c737975d2fcdf9f48d6..789ad87401a56240be0788630826ec44aaf2f36e 100644 (file)
@@ -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
index 42e73f770534eed27e51b13111b2e7b3c53023b0..05ec0934c25d1fc94ef279c149bdc085e187979b 100644 (file)
@@ -1146,16 +1146,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 (grep { $_->name eq $actual_field } @{ $args->{multi_fields} }) {
-            $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};
         }
     }
     
@@ -1202,6 +1203,21 @@ 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};
+}
 
 sub SqlifyDate {
     my ($str) = @_;
index 87061aa06172b7f336a268760b5010f889474c9c..2a6f6946dc4ec6102fca102195bf0de4a7473b37 100644 (file)
@@ -196,6 +196,30 @@ 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 = shift;
+
+    my %func_args = @_;
+    $invocant->$original(%func_args);
+
+    # Actually, it does not change anything in the result,
+    # just an example.
+    my ($term) = @func_args{qw(term)};
+    $$term = $$term . " OR 1=2";
+}
+
 sub bugmail_recipients {
     my ($self, $args) = @_;
     my $recipients = $args->{recipients};