From 6e04e51d7edf1d031171cf860f6bd4073f9a7dc4 Mon Sep 17 00:00:00 2001 From: Lari Taskula Date: Thu, 13 Apr 2017 11:06:29 +0000 Subject: [PATCH] Bug 14698 - AtomicUpdater - addAllAtomicUpdates This patch adds a new method Koha::AtomicUpdater->addAllAtomicUpdates that marks all pending atomicupdates as applied, but does not execute the database changes in them. This is required for fresh installations to avoid applying same updates after the installation. Binds this feature to web installer. To test: 1. prove t/db_dependent/Koha/AtomicUpdater.t --- Koha/AtomicUpdater.pm | 19 ++++++++++++++++ installer/install.pl | 1 + t/db_dependent/Koha/AtomicUpdater.t | 45 +++++++++++++++++++++++++++++++++++++ 3 files changed, 65 insertions(+) diff --git a/Koha/AtomicUpdater.pm b/Koha/AtomicUpdater.pm index bfb978c..bd3b2e7 100644 --- a/Koha/AtomicUpdater.pm +++ b/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; diff --git a/installer/install.pl b/installer/install.pl index 508496a..f4cc7a7 100755 --- a/installer/install.pl +++ b/installer/install.pl @@ -320,6 +320,7 @@ elsif ( $step && $step == 3 ) { "error" => $error, "$op" => 1, ); + Koha::AtomicUpdater->new->addAllAtomicUpdates(); } elsif ( $op && $op eq 'updatestructure' ) { # diff --git a/t/db_dependent/Koha/AtomicUpdater.t b/t/db_dependent/Koha/AtomicUpdater.t index 3fb16c3..2b922a7 100644 --- a/t/db_dependent/Koha/AtomicUpdater.t +++ b/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; -- 2.7.4