From 502914d29785bf4a4ba6423385979db986c52980 Mon Sep 17 00:00:00 2001 From: "mkanat%bugzilla.org" <> Date: Sat, 9 May 2009 17:47:25 +0000 Subject: Bug 490673: WebServices's datetime_format method was in the wrong module Patch by Max Kanat-Alexander r=wicked, r=ghendricks, a=mkanat --- Bugzilla/WebService.pm | 15 +++++++- Bugzilla/WebService/Bug.pm | 67 +++++++++++++++++++++++------------- Bugzilla/WebService/Server/XMLRPC.pm | 14 +------- 3 files changed, 58 insertions(+), 38 deletions(-) diff --git a/Bugzilla/WebService.pm b/Bugzilla/WebService.pm index ffaf7c4b7..75fcf6bc9 100755 --- a/Bugzilla/WebService.pm +++ b/Bugzilla/WebService.pm @@ -36,11 +36,24 @@ sub login_exempt { sub type { my ($self, $type, $value) = @_; if ($type eq 'dateTime') { - $value = $self->datetime_format($value); + $value = datetime_format($value); } return XMLRPC::Data->type($type)->value($value); } +sub datetime_format { + my ($date_string) = @_; + + my $time = str2time($date_string); + my ($sec, $min, $hour, $mday, $mon, $year) = localtime $time; + # This format string was stolen from SOAP::Utils->format_datetime, + # which doesn't work but which has almost the right format string. + my $iso_datetime = sprintf('%d%02d%02dT%02d:%02d:%02d', + $year + 1900, $mon + 1, $mday, $hour, $min, $sec); + return $iso_datetime; +} + + 1; __END__ diff --git a/Bugzilla/WebService/Bug.pm b/Bugzilla/WebService/Bug.pm index 8ebad41d1..9835a315f 100755 --- a/Bugzilla/WebService/Bug.pm +++ b/Bugzilla/WebService/Bug.pm @@ -201,8 +201,7 @@ sub get_history { foreach my $changeset (@$activity) { my %bug_history; - $bug_history{when} = $self->type('dateTime', - $self->datetime_format($changeset->{when})); + $bug_history{when} = $self->type('dateTime', $changeset->{when}); $bug_history{who} = $self->type('string', $changeset->{who}); $bug_history{changes} = []; foreach my $change (@{ $changeset->{changes} }) { @@ -251,12 +250,27 @@ sub search { $params = _map_fields($params); - # If the user set the 'last_change_time' param (translated into delta_ts - # by the field map), use a custom WHERE to constrain the query to only - # those bugs that have a delta_ts greater than or equal to - # the specified time. + # Do special search types for certain fields. if ( my $bug_when = delete $params->{delta_ts} ) { - $params->{WHERE} = {'delta_ts >= ?' => $bug_when}; + $params->{WHERE}->{'delta_ts >= ?'} = $bug_when; + } + if (my $when = delete $params->{creation_ts}) { + $params->{WHERE}->{'creation_ts >= ?'} = $when; + } + if (my $votes = delete $params->{votes}) { + $params->{WHERE}->{'votes >= ?'} = $votes; + } + if (my $summary = delete $params->{short_desc}) { + my @strings = ref $summary ? @$summary : ($summary); + my @likes = ("short_desc LIKE ?") x @strings; + my $clause = join(' OR ', @likes); + $params->{WHERE}->{"($clause)"} = [map { "\%$_\%" } @strings]; + } + if (my $whiteboard = delete $params->{status_whiteboard}) { + my @strings = ref $whiteboard ? @$whiteboard : ($whiteboard); + my @likes = ("status_whiteboard LIKE ?") x @strings; + my $clause = join(' OR ', @likes); + $params->{WHERE}->{"($clause)"} = [map { "\%$_\%" } @strings]; } my $bugs = Bugzilla::Bug->match($params); @@ -999,10 +1013,11 @@ Allows you to search for bugs based on particular criteria. =item B -Bugs are returned if they match I the criteria you specify -in these parameters. That is, we don't match against -substrings--if a bug is in the "Widgets" product and you ask for bugs in -the "Widg" product, you won't get anything. +Unless otherwise specified in the description of a parameter, bugs are +returned if they match I the criteria you specify in these +parameters. That is, we don't match against substrings--if a bug is in +the "Widgets" product and you ask for bugs in the "Widg" product, you +won't get anything. Criteria are joined in a logical AND. That is, you will be returned bugs that match I of the criteria, not bugs that match I of @@ -1015,9 +1030,6 @@ the "Foo" or "Bar" products, you'd pass: product => ['Foo', 'Bar'] -Fields below only have descriptions if it's not clear what bug field -they match up to, or if they have some special behavior. - Some Bugzillas may treat your arguments case-sensitively, depending on what database system they are using. Most commonly, though, Bugzilla is not case-sensitive with the arguments passed (because MySQL is the @@ -1044,7 +1056,8 @@ don't want this, be sure to also specify the C argument. =item C -C When the bug was created. +C Searches for bugs that were created at this time or later. +May not be an array. =item C @@ -1052,10 +1065,8 @@ C The numeric id of the bug. =item C -C Limit the search to only those bugs which have changed -in some way since the specified time. It includes all bugs changed -between the specified time and the present. Note: only a single -C will accepted, not an array. +C Searches for bugs that were modified at this time or later. +May not be an array. =item C @@ -1104,9 +1115,14 @@ if it has one, which is a separate field above). =item C -C The single-line summary field of a bug. (This isn't very -useful to search on, since we don't do substring matches, only exact -matches.) +C Searches for substrings in the single-line Summary field on +bugs. If you specify an array, then bugs whose summaries match I of the +passed substrings will be returned. + +Note that unlike searching in the Bugzilla UI, substrings are not split +on spaces. So searching for C will match "This is a foo bar" +but not "This foo is a bar". C<['foo', 'bar']>, would, however, match +the second item. =item C @@ -1133,11 +1149,14 @@ C The Version field of a bug. =item C -C How many votes this bug has, total. +C Searches for bugs with this many votes or greater. May not +be an array. =item C -C The "Status Whiteboard" field of a bug. +C Search the "Status Whiteboard" field on bugs for a substring. +Works the same as the C field described above, but searches the +Status Whiteboard field. =back diff --git a/Bugzilla/WebService/Server/XMLRPC.pm b/Bugzilla/WebService/Server/XMLRPC.pm index 5c92532a9..cff429fcb 100644 --- a/Bugzilla/WebService/Server/XMLRPC.pm +++ b/Bugzilla/WebService/Server/XMLRPC.pm @@ -45,18 +45,6 @@ sub make_response { } } -sub datetime_format { - my ($self, $date_string) = @_; - - my $time = str2time($date_string); - my ($sec, $min, $hour, $mday, $mon, $year) = localtime $time; - # This format string was stolen from SOAP::Utils->format_datetime, - # which doesn't work but which has almost the right format string. - my $iso_datetime = sprintf('%d%02d%02dT%02d:%02d:%02d', - $year + 1900, $mon + 1, $mday, $hour, $min, $sec); - return $iso_datetime; -} - sub handle_login { my ($self, $classes, $action, $uri, $method) = @_; my $class = $classes->{$uri}; @@ -220,4 +208,4 @@ to be C, no matter what it contains. nil is implemented by XMLRPC::Lite, in XMLRPC::Deserializer::decode_value. -=end private \ No newline at end of file +=end private -- cgit v1.2.3-24-g4f1b