@@ -, +, @@ --- Koha/AtomicUpdater.pm | 19 ++++++++++++++++ installer/install.pl | 1 + t/db_dependent/Koha/AtomicUpdater.t | 35 ++++++++++++++++++++++++++++- 3 files changed, 54 insertions(+), 1 deletion(-) --- 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 @@ -364,6 +364,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 @@ -30,7 +30,7 @@ use Koha::AtomicUpdater; use t::lib::TestBuilder; -plan tests => 8; +plan tests => 9; my $schema = Koha::Database->new->schema; $schema->storage->txn_begin; @@ -271,6 +271,39 @@ subtest "Apply single atomicupdate from file" => sub { }; +subtest 'Mark all atomicupdates as installed (for fresh installs), but do not execute them' => sub { + + plan tests => 3; + + my $test_file1 = create_file({ + filepath => 'atomicupdate/', + filename => 'Bug_00001-First-update.pl', + content => '$ENV{ATOMICUPDATE_TESTS_3}++;', + + }); + + my $test_file2 = create_file({ + filepath => 'atomicupdate/', + filename => 'Bug_00002-Second-update.pl', + content => '$ENV{ATOMICUPDATE_TESTS_3}++;', + }); + + my $atomicUpdater = Koha::AtomicUpdater->new({ + scriptDir => $test_file1->dirname(), + }); + + $atomicUpdater->addAllAtomicUpdates; + my $atomicUpdate = $atomicUpdater->find('Bug-00001'); + my $atomicUpdate2 = $atomicUpdater->find('Bug-00002'); + + 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."); + + $test_file1->remove; + $test_file2->remove; +}; + $test_file->remove; $schema->storage->txn_rollback; --