]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 1568592 - Custom fields are lost when using Edit Search
authorKohei Yoshino <kohei.yoshino@gmail.com>
Fri, 26 Jul 2019 20:25:23 +0000 (16:25 -0400)
committerGitHub <noreply@github.com>
Fri, 26 Jul 2019 20:25:23 +0000 (16:25 -0400)
query.cgi

index 949251eb2281eb6996371f32632fb3b9fc466c78..7e46081b60f45322d70ce9564a9a51d2664d9011 100755 (executable)
--- a/query.cgi
+++ b/query.cgi
@@ -69,6 +69,7 @@ sub PrefillForm {
   my $cgi = Bugzilla->cgi;
   $buf = new Bugzilla::CGI($buf);
   my $foundone = 0;
+  my $custom_fields = {};
 
   # If there are old-style boolean charts in the URL (from an old saved
   # search or from an old link on the web somewhere) then convert them
@@ -95,6 +96,12 @@ sub PrefillForm {
       $default{'custom_search'}->[$2]->{$1} = $values[0];
     }
 
+    # If the name starts with `cf_`, it's a custom field's shorthand syntax.
+    # We'll append this to Custom Search conditions.
+    elsif ($name =~ /^cf_\w+$/) {
+      $custom_fields->{$name} = \@values;
+    }
+
     # If the name ends in a number (which it does for the fields which
     # are part of the email searching), we use the array
     # positions to show the defaults for that number field.
@@ -106,6 +113,28 @@ sub PrefillForm {
     }
   }
 
+  # Append custom fields to Custom Search
+  if (scalar keys %$custom_fields) {
+    $default{'custom_search'} //= [];
+
+    my @j_top = $buf->param('j_top');
+
+    # If the top joiner is `AND_G` or `OR`, wrap the current conditions with an
+    # extra group, then make the top joiner `AND`.
+    if (scalar @j_top && $j_top[0] ne 'AND') {
+      unshift(@{$default{'custom_search'}}, {f => 'OP', j => $j_top[0]});
+      push(@{$default{'custom_search'}}, {f => 'CP'});
+      $default{'j_top'} = ['AND'];
+    }
+
+    while (my ($name, $values) = each(%$custom_fields)) {
+      # Join multiple values with a comma, and use the `anyexact` operator
+      # because values may contain spaces.
+      push(@{$default{'custom_search'}},
+        {f => $name, o => 'anyexact', v => join(', ', @$values)});
+    }
+  }
+
   return $foundone;
 }