]> git.donarmstrong.com Git - debbugs.git/commitdiff
set related packages (bin/src/affects, etc.)
authorDon Armstrong <don@donarmstrong.com>
Wed, 12 Apr 2017 02:47:57 +0000 (19:47 -0700)
committerDon Armstrong <don@donarmstrong.com>
Wed, 12 Apr 2017 02:47:57 +0000 (19:47 -0700)
Debbugs/DB/Load.pm
Debbugs/DB/Result/Bug.pm

index dfc1db9869b0a400d8d3427ad3026d7ee900d319..77423a0017533aef54bc645af602dc9a5cf1e8d4 100644 (file)
@@ -101,6 +101,10 @@ sub load_bug {
                                                      },
                                        queue => {type => HASHREF,
                                                  optional => 1},
+                                      packages => {type => HASHREF,
+                                                   default => sub {return {}},
+                                                   optional => 1,
+                                                  },
                                       });
     my $s = $param{db};
     if (not exists $param{data} and not exists $param{bug}) {
@@ -171,8 +175,33 @@ sub load_bug {
     }
     my $b = $s->resultset('Bug')->update_or_create($bug) or
         die "Unable to update or create bug $bug->{id}";
-     $s->txn_do(sub {
-                  for my $ff (qw(found fixed)) {
+    $s->txn_do(sub {
+                $b->set_related_packages('binpackages',
+                                         [grep {defined $_ and
+                                                  length $_ and $_ !~ /^src:/}
+                                          make_list($data->{package})],
+                                         $param{packages},
+                                        );
+                $b->set_related_packages('srcpackages',
+                                         [grep {defined $_ and
+                                                  $_ =~ /^src:/}
+                                          make_list($data->{package})],
+                                         $param{packages},
+                                        );
+                $b->set_related_packages('affects_binpackages',
+                                         [grep {defined $_ and
+                                                  length $_ and $_ !~ /^src:/}
+                                          make_list($data->{affects})
+                                         ],
+                                         $param{packages},
+                                        );
+                $b->set_related_packages('affects_srcpackages',
+                                         [grep {defined $_ and
+                                                  $_ =~ /^src:/}
+                                          make_list($data->{affects})],
+                                         $param{packages},
+                                        );
+                for my $ff (qw(found fixed)) {
                       my @elements = $s->resultset('BugVer')->search({bug => $data->{bug_num},
                                                                       found  => $ff eq 'found'?1:0,
                                                                      });
index 1e68645d8391ea2aba0d677cb234ecfc386fe4b0..d6e0f3d6e9cdb30910b5913b1a2b9a695be501ae 100644 (file)
@@ -14,6 +14,7 @@ use strict;
 use warnings;
 
 use base 'DBIx::Class::Core';
+use Carp;
 
 =head1 COMPONENTS LOADED
 
@@ -525,5 +526,36 @@ __PACKAGE__->many_to_many(affects_binpackages => 'bug_affects_binpackages','bin_
 __PACKAGE__->many_to_many(affects_srcpackages => 'bug_affects_srcpackages','src_pkg');
 __PACKAGE__->many_to_many(messages => 'bug_messages','message');
 
+sub set_related_packages {
+    my ($self,$relationship,$pkgs,$pkg_cache) = @_;
+
+    my @pkg_ids;
+    if ($relationship =~ /binpackages/) {
+        for my $pkg (@{$pkgs}) {
+            push @pkg_ids,
+              $self->result_source->schema->resultset('BinPkg')->
+              get_bin_pkg_id($pkg);
+        }
+    } elsif ($relationship =~ /srcpackages/) {
+        for my $pkg (@{$pkgs}) {
+            push @pkg_ids,
+              $self->result_source->schema->resultset('SrcPkg')->
+              get_src_pkg_id($pkg);
+        }
+    } else {
+        croak "Unsupported relationship $relationship";
+    }
+    if ($relationship eq 'binpackages') {
+        $self->set_binpackages([map {{id => $_}} @pkg_ids]);
+    } elsif ($relationship eq 'srcpackages') {
+        $self->set_srcpackages([map {{id => $_}} @pkg_ids]);
+    } elsif ($relationship eq 'affects_binpackages') {
+        $self->set_affects_binpackages([map {{id => $_}} @pkg_ids]);
+    } elsif ($relationship eq 'affects_srcpackages') {
+        $self->set_affects_srcpackages([map {{id => $_}} @pkg_ids]);
+    } else {
+        croak "Unsupported relationship $relationship";
+    }
+}
 # You can replace this text with custom code or comments, and it will be preserved on regeneration
 1;