+sub add_bugs_and_logs {
+ my ($options,$opts,$p,$config,$argv) = @_;
+
+ chdir($config->{spool_dir}) or
+ die "chdir $config->{spool_dir} failed: $!";
+
+ my $verbose = $options->{debug};
+
+ my $initialdir = "db-h";
+
+ if (defined $argv->[0] and $argv->[0] eq "archive") {
+ $initialdir = "archive";
+ }
+ my $s = db_connect($options);
+
+ my %tags;
+ my %severities;
+ my %queue;
+
+ walk_bugs(dirs => [(@{$argv}?@{$argv} : $initialdir)],
+ progress_bar => $p,
+ $verbose?(logging => \*STDERR):(),
+ callback =>
+ sub {
+ my @bugs = @_;
+ my @bugs_to_update;
+ if ($options{quick}) {
+ @bugs_to_update =
+ bugs_to_update($s,@bugs);
+ } else {
+ @bugs_to_update = @bugs;
+ }
+ eval {
+ $s->txn_do(sub {
+ for my $bug (@bugs_to_update) {
+ load_bug(db => $s,
+ bug => $bug,
+ tags => \%tags,
+ severities => \%severities,
+ queue => \%queue);
+ }
+ });
+ };
+ if ($@) {
+ die "failure while trying to load bug: $@";
+ }
+ for my $bug (@bugs) {
+ my $stat = stat(getbugcomponent($bug,'log',$initialdir));
+ if (not defined $stat) {
+ print STDERR "Unable to stat $bug $!\n";
+ next;
+ }
+ if ($options{quick}) {
+ my $rs = $s->resultset('Bug')->
+ search({id=>$bug})->single();
+ return if defined $rs and
+ $stat->mtime <= $rs->last_modified()->epoch();
+ }
+ eval {
+ load_bug_log(db => $s,
+ bug => $bug);
+ };
+ if ($@) {
+ die "failure while trying to load bug log $bug\n$@";
+ }
+ }
+ },
+ bugs_per_call => 50,
+ );
+ handle_load_bug_queue(db=>$s,
+ queue => \%queue,
+ );
+
+}
+