]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 533878: Allow relative date searches involving date/time custom fields
authorByron Jones <bjones@mozilla.com>
Wed, 24 Jul 2013 08:18:47 +0000 (16:18 +0800)
committerByron Jones <bjones@mozilla.com>
Wed, 24 Jul 2013 08:18:47 +0000 (16:18 +0800)
r=LpSolit, a=sgreen

Bugzilla/Search.pm
t/011pod.t

index 7205f09c5ef76b2a4cadedaf38bcbf761b8cce50..beca95ae13b9476dff1e03b7809b028a48d9e694 100644 (file)
@@ -322,20 +322,31 @@ use constant OPERATOR_FIELD_OVERRIDE => {
 
 # These are fields where special action is taken depending on the
 # *value* passed in to the chart, sometimes.
-use constant SPECIAL_PARSING => {
-    # Pronoun Fields (Ones that can accept %user%, etc.)
-    assigned_to => \&_contact_pronoun,
-    cc          => \&_contact_pronoun,
-    commenter   => \&_contact_pronoun,
-    qa_contact  => \&_contact_pronoun,
-    reporter    => \&_contact_pronoun,
-    'setters.login_name' => \&_contact_pronoun,
-    'requestees.login_name' => \&_contact_pronoun,
-
-    # Date Fields that accept the 1d, 1w, 1m, 1y, etc. format.
-    creation_ts => \&_timestamp_translate,
-    deadline    => \&_timestamp_translate,
-    delta_ts    => \&_timestamp_translate,
+# This is a sub because custom fields are dynamic
+sub SPECIAL_PARSING {
+    my $map = {
+        # Pronoun Fields (Ones that can accept %user%, etc.)
+        assigned_to => \&_contact_pronoun,
+        cc          => \&_contact_pronoun,
+        commenter   => \&_contact_pronoun,
+        qa_contact  => \&_contact_pronoun,
+        reporter    => \&_contact_pronoun,
+        'setters.login_name' => \&_contact_pronoun,
+        'requestees.login_name' => \&_contact_pronoun,
+
+        # Date Fields that accept the 1d, 1w, 1m, 1y, etc. format.
+        creation_ts => \&_datetime_translate,
+        deadline    => \&_date_translate,
+        delta_ts    => \&_datetime_translate,
+    };
+    foreach my $field (Bugzilla->active_custom_fields) {
+        if ($field->type == FIELD_TYPE_DATETIME) {
+            $map->{$field->name} = \&_datetime_translate;
+        } elsif ($field->type == FIELD_TYPE_DATE) {
+            $map->{$field->name} = \&_date_translate;
+        }
+    }
+    return $map;
 };
 
 # Information about fields that represent "users", used by _user_nonchanged.
@@ -2083,22 +2094,29 @@ sub _word_terms {
 #####################################
 
 sub _timestamp_translate {
-    my ($self, $args) = @_;
+    my ($self, $ignore_time, $args) = @_;
     my $value = $args->{value};
     my $dbh = Bugzilla->dbh;
 
     return if $value !~ /^(?:[\+\-]?\d+[hdwmy]s?|now)$/i;
 
-    # By default, the time is appended to the date, which we don't want
-    # for deadlines.
     $value = SqlifyDate($value);
-    if ($args->{field} eq 'deadline') {
+    # By default, the time is appended to the date, which we don't always want.
+    if ($ignore_time) {
         ($value) = split(/\s/, $value);
     }
     $args->{value} = $value;
     $args->{quoted} = $dbh->quote($value);
 }
 
+sub _datetime_translate {
+    return shift->_timestamp_translate(0, @_);
+}
+
+sub _date_translate {
+    return shift->_timestamp_translate(1, @_);
+}
+
 sub SqlifyDate {
     my ($str) = @_;
     my $fmt = "%Y-%m-%d %H:%M:%S";
index 92474d5533fa12bc678fd463e2b6028b7f436339..0ddd3059dac93fe84ce9c3351b9c8f7aadd91a58 100644 (file)
@@ -31,6 +31,7 @@ use constant SUB_WHITELIST => (
     'Bugzilla::Flag'     => qr/^(?:(force_)?retarget|force_cleanup)$/,
     'Bugzilla::FlagType' => qr/^sqlify_criteria$/,
     'Bugzilla::JobQueue' => qr/(?:^work_once|subprocess_worker)$/,
+    'Bugzilla::Search'   => qr/^SPECIAL_PARSING$/,
 );
 
 # These modules do not need to be documented, generally because they