From: Kohei Yoshino Date: Mon, 26 Nov 2018 20:23:51 +0000 (-0500) Subject: Bug 1509308 - Date for cf_last_resolved in history results should be UTC X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=29cdf6d0d423f5a7e3c3e61db8d49970c00d1389;p=thirdparty%2Fbugzilla.git Bug 1509308 - Date for cf_last_resolved in history results should be UTC * Bug 1509308 - Date for cf_last_resolved in history results should be UTC * Add conversion script * oops --- diff --git a/Bugzilla/WebService/Bug.pm b/Bugzilla/WebService/Bug.pm index 5d60885c9..a08777fcc 100644 --- a/Bugzilla/WebService/Bug.pm +++ b/Bugzilla/WebService/Bug.pm @@ -463,6 +463,10 @@ sub history { my $ids = $params->{ids}; defined $ids || ThrowCodeError('param_required', { param => 'ids' }); + my %api_type = ( + %{{ map { $_ => 'double' } Bugzilla::Bug::NUMERIC_COLUMNS() }}, + %{{ map { $_ => 'dateTime' } Bugzilla::Bug::DATE_COLUMNS() }}, + ); my %api_name = reverse %{ Bugzilla::Bug::FIELD_MAP() }; $api_name{'bug_group'} = 'groups'; @@ -482,15 +486,16 @@ sub history { $bug_history{who} = $self->type('email', $changeset->{who}); $bug_history{changes} = []; foreach my $change (@{ $changeset->{changes} }) { - my $api_field = $api_name{$change->{fieldname}} || $change->{fieldname}; + my $field_name = delete $change->{fieldname}; + my $api_field_type = $api_type{$field_name} || 'string'; + my $api_field_name = $api_name{$field_name} || $field_name; my $attach_id = delete $change->{attachid}; if ($attach_id) { $change->{attachment_id} = $self->type('int', $attach_id); } - $change->{removed} = $self->type('string', $change->{removed}); - $change->{added} = $self->type('string', $change->{added}); - $change->{field_name} = $self->type('string', $api_field); - delete $change->{fieldname}; + $change->{removed} = $self->type($api_field_type, $change->{removed}); + $change->{added} = $self->type($api_field_type, $change->{added}); + $change->{field_name} = $self->type('string', $api_field_name); push (@{$bug_history{changes}}, $change); } diff --git a/Bugzilla/WebService/Server/JSONRPC.pm b/Bugzilla/WebService/Server/JSONRPC.pm index 093167048..bcea337f6 100644 --- a/Bugzilla/WebService/Server/JSONRPC.pm +++ b/Bugzilla/WebService/Server/JSONRPC.pm @@ -231,9 +231,9 @@ sub type { } sub datetime_format_outbound { - my $self = shift; + my ($self, $value) = @_; # YUI expects ISO8601 in UTC time; including TZ specifier - return $self->SUPER::datetime_format_outbound(@_) . 'Z'; + return $value ? $self->SUPER::datetime_format_outbound($value) . 'Z' : ''; } sub handle_login { diff --git a/extensions/LastResolved/bin/bug-1509308.pl b/extensions/LastResolved/bin/bug-1509308.pl new file mode 100644 index 000000000..91dd5c781 --- /dev/null +++ b/extensions/LastResolved/bin/bug-1509308.pl @@ -0,0 +1,33 @@ +#!/usr/bin/perl +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# This Source Code Form is "Incompatible With Secondary Licenses", as +# defined by the Mozilla Public License, v. 2.0. + +use 5.10.1; +use strict; +use warnings; +use lib qw(. lib local/lib/perl5); + +use Bugzilla; +use Bugzilla::Field; + +my $dbh = Bugzilla->dbh; +my $resolved_activity = $dbh->selectall_arrayref( + 'SELECT id, bug_id, bug_when FROM bugs_activity WHERE fieldid = ? ORDER BY bug_when', + undef, get_field_id('cf_last_resolved')); +my %last_resolved; + +foreach my $activity (@$resolved_activity) { + my ($id, $bug_id, $added) = @$activity; + my $removed = $last_resolved{$bug_id} || ''; + + # Copy the `bug_when` column to `added` so it will be UTC instead of PST + $dbh->do('UPDATE bugs_activity SET added = ?, removed = ? WHERE id = ?', + undef, $added, $removed, $id); + + # Cache the timestamp as a bug can be resolved multiple times + $last_resolved{$bug_id} = $added; +}