diff --git a/lib/AmuseWikiFarm/Schema/Result/Site.pm b/lib/AmuseWikiFarm/Schema/Result/Site.pm index d36e2443..9fdb1c67 100644 --- a/lib/AmuseWikiFarm/Schema/Result/Site.pm +++ b/lib/AmuseWikiFarm/Schema/Result/Site.pm @@ -5546,9 +5546,20 @@ sub create_aggregation { } my $aggregation = $self->aggregations->find({ aggregation_uri => $rec{aggregation_uri} }); my @existing_uris; + my $bump_pmh = 1; if ($aggregation) { Dlog_debug { "Updating aggregation with $_" } \%rec; - $aggregation->update(\%rec); + foreach my $k (sort keys %rec) { + $aggregation->$k($rec{$k}); + } + if ($aggregation->is_changed) { + Dlog_debug { "Aggregation was updated $_" } +{ $aggregation->get_dirty_columns }; + $aggregation->update; + } + else { + log_debug { "No changes in the aggregation" }; + $bump_pmh = 0; + } @existing_uris = map { $_->uri } $aggregation->titles; } else { @@ -5574,7 +5585,14 @@ sub create_aggregation { } } Dlog_debug { "Aggregation changed $_" } +{ from => \@existing_uris, to => \@uris }; - $aggregation->bump_oai_pmh_records; + if ($bump_pmh + or join('|', @existing_uris) ne join('|', @uris)) { + Dlog_info { "Bumping OAI PMH records for " . $aggregation->aggregation_uri . " aggregation $_" } \@uris; + $aggregation->bump_oai_pmh_records; + } + else { + log_info { "No OAI-PMH update for aggregation " . $aggregation->aggregation_uri }; + } $guard->commit; $aggregation->discard_changes; return $aggregation; diff --git a/t/aggregations.t b/t/aggregations.t index 7d5f3f89..bbee8ce8 100644 --- a/t/aggregations.t +++ b/t/aggregations.t @@ -8,7 +8,7 @@ BEGIN { }; use Data::Dumper; -use Test::More tests => 203; +use Test::More tests => 204; use AmuseWikiFarm::Schema; use File::Spec::Functions qw/catfile catdir/; use lib catdir(qw/t lib/); @@ -505,6 +505,17 @@ $site->delete; like $agg->aggregation_series->comment_html, qr{valid}; } +{ + my $max = $site->oai_pmh_records->search(undef, { order_by => { -desc => 'datestamp' }, rows => 1 })->first; + diag $max->datestamp; + diag "Reimporting and checking if ts changed"; + DumpFile($autoimport->child('aggregations.yml'), $site->serialize_aggregations); + sleep 2; + $site->process_autoimport_files; + my $newmax = $site->oai_pmh_records->search(undef, { order_by => { -desc => 'datestamp' }, rows => 1 })->first; + is $max->datestamp->epoch, $newmax->datestamp->epoch; +} + sub check_oai_pmh { my ($s, $now, $expect_records, $msg) = @_; sleep 1;