]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 1509308 - Date for cf_last_resolved in history results should be UTC
authorKohei Yoshino <kohei.yoshino@gmail.com>
Mon, 26 Nov 2018 20:23:51 +0000 (15:23 -0500)
committerdklawren <dklawren@users.noreply.github.com>
Mon, 26 Nov 2018 20:23:51 +0000 (15:23 -0500)
* Bug 1509308 - Date for cf_last_resolved in history results should be UTC

* Add conversion script

* oops

Bugzilla/WebService/Bug.pm
Bugzilla/WebService/Server/JSONRPC.pm
extensions/LastResolved/bin/bug-1509308.pl [new file with mode: 0644]

index 5d60885c9d062fa28f18e3e2dfc873d7f06cdbf1..a08777fcca069271496a0f868418183bcca7668f 100644 (file)
@@ -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);
             }
 
index 0931670487557720c91fb9f152b199dd0a636136..bcea337f61c69a0b9d37d81f8827d450aeefa34a 100644 (file)
@@ -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 (file)
index 0000000..91dd5c7
--- /dev/null
@@ -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;
+}