]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 1539442 - Fix secbugs event builder to get more than the lastest event
authorIsrael Madueme <purelogiq@gmail.com>
Thu, 28 Mar 2019 14:06:08 +0000 (10:06 -0400)
committerDylan William Hardison <dylan@hardison.net>
Thu, 28 Mar 2019 14:06:08 +0000 (10:06 -0400)
Bugzilla/Report/SecurityRisk.pm

index fa629adb9513469648774f69b60fd900af6792cd..f508390ad05d49cd12c2a24191a10d1e804865f4 100644 (file)
@@ -29,15 +29,14 @@ use List::Util qw(any first sum uniq);
 use Mojo::File qw(tempfile);
 use POSIX qw(ceil);
 use Type::Utils;
-use Types::Standard
-  qw(Num Int Bool Str HashRef ArrayRef CodeRef Maybe Map Dict Enum Optional Object);
+use Types::Standard qw(:types);
 
 my $DateTime = class_type {class => 'DateTime'};
 my $JSONBool = class_type {class => 'JSON::PP::Boolean'};
 
-has 'start_date' => (is => 'ro', required => 1, isa => $DateTime,);
+has 'start_date' => (is => 'ro', required => 1, isa => $DateTime);
 
-has 'end_date' => (is => 'ro', required => 1, isa => $DateTime,);
+has 'end_date' => (is => 'ro', required => 1, isa => $DateTime);
 
 # The teams are loaded from an admin parameter containing JSON, e.g.:
 # {
@@ -299,11 +298,20 @@ sub _build_events {
             AND bug_when >= '$start_date 00:00:00'
         GROUP BY bug_id , bug_when , field.name
     };
-  my $result = Bugzilla->dbh->selectall_hashref($query, 'bug_id');
-  my @events = values %$result;
-  foreach my $event (@events) {
-    $event->{bug_when} = datetime_from($event->{bug_when});
-  }
+  # Don't use selectall_hashref as it only gets the latest event each bug.
+  my $result = Bugzilla->dbh->selectall_arrayref($query);
+  my $type   = ArrayRef [Tuple [Int, Str, Str, Str, Str]];
+  $type->assert_valid($result);
+
+  my @events = map {
+    +{
+      'bug_id'     => $_->[0],
+      'bug_when'   => datetime_from($_->[1]),
+      'field_name' => $_->[2],
+      'removed'    => $_->[3],
+      'added'      => $_->[4],
+    }
+  } @$result;
 
   # We sort by reverse chronological order instead of ORDER BY
   # since values %hash doesn't guareentee any order.
@@ -344,7 +352,7 @@ sub _build_results {
 
       # Undo sec keyword changes
       if ($event->{field_name} eq 'keywords') {
-        my $bug_sec_level = $bug->{sec_level};
+        my $bug_sec_level = $bug->{sec_level} // '';
         if ($event->{added} =~ /\b\Q$bug_sec_level\E\b/) {
 
           # If the currently set sec level was added in this event, remove it.