From: Kohei Yoshino Date: Fri, 26 Jul 2019 20:25:23 +0000 (-0400) Subject: Bug 1568592 - Custom fields are lost when using Edit Search X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f71f1cf209fafff0f132f766c43ae7c0e35a83e6;p=thirdparty%2Fbugzilla.git Bug 1568592 - Custom fields are lost when using Edit Search --- diff --git a/query.cgi b/query.cgi index 949251eb2..7e46081b6 100755 --- 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; }