@@ -, +, @@ --- Koha/AtomicUpdater.pm | 19 ++++++++++++++++ installer/install.pl | 1 + t/db_dependent/Koha/AtomicUpdater.t | 45 +++++++++++++++++++++++++++++++++++++ 3 files changed, 65 insertions(+) --- a/Koha/AtomicUpdater.pm +++ a/Koha/AtomicUpdater.pm @@ -130,6 +130,25 @@ sub addAtomicUpdate { return $atomicupdate; } +=head addAllAtomicUpdates + +Gets all pending atomicupdates and marks them added. This is useful for installer +where we want to set all atomicupdates marked as applied to avoid applying them +after installation. + +=cut + +sub addAllAtomicUpdates { + my ($self) = @_; + + my $atomicUpdates = $self->getPendingAtomicUpdates(); + foreach my $key (keys %$atomicUpdates) { + $self->addAtomicUpdate($atomicUpdates->{$key}->unblessed); + } + + return $atomicUpdates; +} + sub removeAtomicUpdate { my ($self, $issueId) = @_; print "Deleting atomicupdate '$issueId'\n" if $self->{verbose} > 2; --- a/installer/install.pl +++ a/installer/install.pl @@ -320,6 +320,7 @@ elsif ( $step && $step == 3 ) { "error" => $error, "$op" => 1, ); + Koha::AtomicUpdater->new->addAllAtomicUpdates(); } elsif ( $op && $op eq 'updatestructure' ) { # --- a/t/db_dependent/Koha/AtomicUpdater.t +++ a/t/db_dependent/Koha/AtomicUpdater.t @@ -326,5 +326,50 @@ sub applySingleAtomicUpdateFromFile { t::lib::TestObjects::ObjectFactory->tearDownTestContext($subtestContext); } +subtest 'Mark all atomicupdates as installed (for fresh installs), but do not' + .' execute them' => \&addAllAtomicUpdates; +sub addAllAtomicUpdates { + my $subtestContext = {}; + eval { + my $files = t::lib::TestObjects::FileFactory->createTestGroup([ + { + filepath => 'atomicupdate/', + filename => 'Bug_00001-First-update.pl', + content => '$ENV{ATOMICUPDATE_TESTS_3}++;', + }, + { + filepath => 'atomicupdate/', + filename => 'Bug_00002-Second-update.pl', + content => '$ENV{ATOMICUPDATE_TESTS_3}++;', + }, + ], + undef, $subtestContext, $testContext); + + my $atomicUpdater = Koha::AtomicUpdater->new({ + scriptDir => $files->{'Bug_00001-First-update.pl'}->dirname(), + }); + + $atomicUpdater->addAllAtomicUpdates; + my $atomicUpdate = $atomicUpdater->find('Bug-00001'); + my $atomicUpdate2 = $atomicUpdater->find('Bug-00002'); + t::lib::TestObjects::AtomicUpdateFactory->addToContext($atomicUpdate, undef, + $subtestContext, $testContext); + t::lib::TestObjects::AtomicUpdateFactory->addToContext($atomicUpdate2, undef, + $subtestContext, $testContext); + + is($atomicUpdate->filename, + "Bug_00001-First-update.pl", + "Bug_00001-First-update.pl added to DB"); + is($atomicUpdate2->filename, + "Bug_00002-Second-update.pl", + "Bug_00002-Second-update.pl added to DB"); + is($ENV{ATOMICUPDATE_TESTS_3}, undef, "However, updates were not executed."); + }; + if ($@) { + ok(0, $@); + } + t::lib::TestObjects::ObjectFactory->tearDownTestContext($subtestContext); +} + t::lib::TestObjects::ObjectFactory->tearDownTestContext($testContext); done_testing; --