From: Kohei Yoshino Date: Fri, 2 Aug 2019 20:21:55 +0000 (-0400) Subject: Bug 1568695 - Allow to use merge date pronouns with changed before/after operator X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=83a0e49811679c2bac4c7a889d2e9ec491779bc0;p=thirdparty%2Fbugzilla.git Bug 1568695 - Allow to use merge date pronouns with changed before/after operator --- diff --git a/Bugzilla/Hook.pm b/Bugzilla/Hook.pm index 22b15c876..172ff905a 100644 --- a/Bugzilla/Hook.pm +++ b/Bugzilla/Hook.pm @@ -597,19 +597,18 @@ Params: =back -=head2 search_timestamp_translate +=head2 search_date_pronoun -This happens in L and allows you to -support pronouns for specific dates, such as a product release date. Check the -`value` argument and replace it with actual date where needed. +This happens in L and allows you to support +pronouns for specific dates, such as a product release date. Pronouns must be +quoted with percent signs like C<%LAST_RELEASE_DATE%>. Params: =over -=item C - The L object. - -=item C - The original arguments including C. +=item C - A capitalized pronoun without percent signs can be found in +the C. Add an actual date back to the C if it's a supported pronoun. =back diff --git a/Bugzilla/Search.pm b/Bugzilla/Search.pm index 8155192f1..19b18b30a 100644 --- a/Bugzilla/Search.pm +++ b/Bugzilla/Search.pm @@ -2257,11 +2257,7 @@ sub _timestamp_translate { my $value = $args->{value}; my $dbh = Bugzilla->dbh; - # Allow to support custom date pronouns - Bugzilla::Hook::process('search_timestamp_translate', - {search => $self, args => $args}); - - return if $value !~ /^(?:[\+\-]?\d+[hdwmy]s?|now)$/i; + return if $value !~ /^(?:[\+\-]?\d+[hdwmy]s?|now)$/i && $value !~ /^%\w+%$/; $value = SqlifyDate($value); @@ -2306,6 +2302,16 @@ sub SqlifyDate { return sprintf("%4d-%02d-%02d 00:00:00", $year + 1900, $month + 1, $mday); } + # Allow to support custom date pronouns + if ($str =~ /^%(\w+)%$/) { + my $pronoun = {name => uc($1)}; + Bugzilla::Hook::process('search_date_pronoun', {pronoun => $pronoun}); + unless ($pronoun->{date}) { + ThrowUserError('illegal_date_pronoun', {pronoun => $str}); + } + return $pronoun->{date}; + } + if ($str =~ /^(-|\+)?(\d+)([hdwmy])(s?)$/i) { # relative date my ($sign, $amount, $unit, $startof, $date) = ($1, $2, lc $3, lc $4, time); my ($sec, $min, $hour, $mday, $month, $year, $wday) = localtime($date); diff --git a/Bugzilla/WebService/Constants.pm b/Bugzilla/WebService/Constants.pm index 502db62d3..7198dac2c 100644 --- a/Bugzilla/WebService/Constants.pm +++ b/Bugzilla/WebService/Constants.pm @@ -70,6 +70,7 @@ use constant WS_ERROR_CODE => { number_too_large => 54, number_too_small => 55, illegal_date => 56, + illegal_date_pronoun => 57, # Bug errors usually occupy the 100-200 range. improper_bug_id_field_value => 100, diff --git a/extensions/BMO/Extension.pm b/extensions/BMO/Extension.pm index 89120d62e..4c3430ffb 100644 --- a/extensions/BMO/Extension.pm +++ b/extensions/BMO/Extension.pm @@ -2738,18 +2738,16 @@ sub search_params_to_data_structure { # Allow to use Firefox release date pronouns, including `%LAST_MERGE_DATE%`, # `%LAST_RELEASE_DATE%` and `%LAST_SOFTFREEZE_DATE%`. -sub search_timestamp_translate { +sub search_date_pronoun { my ($self, $args) = @_; - $args = $args->{args}; - my $key = uc($args->{value}); - $key =~ s/^%([A-Z_]+)%$/$1/; + my $pronoun = $args->{pronoun}; + my $key = $pronoun->{name}; my $keys = ['LAST_MERGE_DATE', 'LAST_RELEASE_DATE', 'LAST_SOFTFREEZE_DATE']; return unless grep(/^$key$/, @$keys); my $date = _fetch_product_version_file('firefox')->{$key}; ThrowUserError('product_date_pronouns_unavailable') unless $date; - $args->{value} = $date; - $args->{quoted} = Bugzilla->dbh->quote($date); + $pronoun->{date} = $date; } sub tf_buglist_columns { diff --git a/template/en/default/global/user-error.html.tmpl b/template/en/default/global/user-error.html.tmpl index eaca85822..b6aeeb054 100644 --- a/template/en/default/global/user-error.html.tmpl +++ b/template/en/default/global/user-error.html.tmpl @@ -977,6 +977,10 @@ Please use the format '[% format FILTER html %]'. [% END %] + [% ELSIF error == "illegal_date_pronoun" %] + [% title = "Illegal Date Pronoun" %] + '[% pronoun FILTER html %]' is not a legal date pronoun. + [% ELSIF error == "illegal_email_address" %] [% title = "Invalid Email Address" %] The e-mail address you entered ([% addr FILTER html %])