Bugzilla – Attachment 102903 Details for
Bug 14698
AtomicUpdater - Keeps track of which updates have been applied to a database
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 14698: AtomicUpdater - Support .perl atomicupdates as defined by skeleton.perl
0005-Bug-14698-AtomicUpdater-Support-.perl-atomicupdates-.patch (text/plain), 5.20 KB, created by
Emmi Takkinen
on 2020-04-14 08:28:41 UTC
(
hide
)
Description:
Bug 14698: AtomicUpdater - Support .perl atomicupdates as defined by skeleton.perl
Filename:
MIME Type:
Creator:
Emmi Takkinen
Created:
2020-04-14 08:28:41 UTC
Size:
5.20 KB
patch
obsolete
>From 53d2208c8a3a44fbabdc02eb0af086bdae050da1 Mon Sep 17 00:00:00 2001 >From: Lari Taskula <lari.taskula@jns.fi> >Date: Fri, 21 Apr 2017 09:54:01 +0000 >Subject: [PATCH 5/5] Bug 14698: AtomicUpdater - Support .perl atomicupdates as > defined by skeleton.perl > >Koha community has introduced a template for developer atomicupdates, as defined >in atomicupdates/skeleton.perl. This patch makes these updates Koha::AtomicUpdater >compatible by redefining CheckVersion and SetVersion, and by passing $dbh into the >file. > >To test: >1. prove t/db_dependent/Koha/AtomicUpdater.t >--- > Koha/AtomicUpdater.pm | 23 ++++++++++ > t/db_dependent/Koha/AtomicUpdater.t | 71 ++++++++++++++++++++++++++++- > 2 files changed, 92 insertions(+), 2 deletions(-) > >diff --git a/Koha/AtomicUpdater.pm b/Koha/AtomicUpdater.pm >index 4e4e040703..4e2aee96cb 100644 >--- a/Koha/AtomicUpdater.pm >+++ b/Koha/AtomicUpdater.pm >@@ -260,6 +260,29 @@ sub applyAtomicUpdate { > my $installer = C4::Installer->new(); > $rv = $installer->load_sql( $self->{scriptDir}.'/'.$filename ) ? 0 : 1; > } elsif ( $filename =~ /\.(perl|pl)$/ ) { >+ # Koha-community uses .perl files for developer atomic updates. These >+ # simplified versions of atomicupdates do not instantiate $dbh, and >+ # subroutines CheckVersion and SetVersion from updatedatabase.pl are >+ # out of scope when executed by the AtomicUpdater. In order to support >+ # community dev atomicupdates, we have to re-define these subroutines >+ # and pass $dbh into the .perl file. >+ # >+ # See atomicupdates/skeleton.perl for default community template. >+ if ($filename =~ /\.perl$/) { >+ our $dbh = C4::Context->dbh; >+ sub SetVersion { return 1; } >+ sub CheckVersion { >+ unless ($_[0] =~ /^XXX$/) { >+ Koha::Exceptions::File->throw( >+ error => 'Atomicupdate is not a dev atomicupdate. Dev' >+ .' updates are identified by CheckVersion("XXX").' >+ ." Given version is $_[0]." >+ ); >+ } >+ return 1; >+ } >+ } >+ > my $fileAndPath = $self->{scriptDir}.'/'.$filename; > $rv = do $fileAndPath; > unless ($rv) { >diff --git a/t/db_dependent/Koha/AtomicUpdater.t b/t/db_dependent/Koha/AtomicUpdater.t >index f877d16deb..03c2d78893 100644 >--- a/t/db_dependent/Koha/AtomicUpdater.t >+++ b/t/db_dependent/Koha/AtomicUpdater.t >@@ -30,7 +30,7 @@ use Koha::AtomicUpdater; > > use t::lib::TestBuilder; > >-plan tests => 9; >+plan tests => 10; > > my $schema = Koha::Database->new->schema; > $schema->storage->txn_begin; >@@ -304,9 +304,76 @@ subtest 'Mark all atomicupdates as installed (for fresh installs), but do not ex > $test_file2->remove; > }; > >-$test_file->remove; > $schema->storage->txn_rollback; > >+subtest 'Support community dev atomicupdates (.perl files, see skeleton.perl)' => sub { >+ >+ plan tests => 4; >+ $schema->storage->txn_begin; >+ >+ my $dev_update = q{ >+ $DBversion = 'XXX'; # will be replaced by the RM >+ if( CheckVersion( $DBversion ) ) { >+ $dbh->do( "SHOW TABLES" ); >+ >+ # Always end with this (adjust the bug info) >+ SetVersion( $DBversion ); >+ $ENV{ATOMICUPDATE_TESTS_VAL}++; >+ print "Upgrade to $DBversion done (Bug XXXXX - description)\n"; >+ } >+ }; >+ >+ my $dev_update_invalid = q{ >+ $DBversion = '16.00.00'; # will be replaced by the RM >+ if( CheckVersion( $DBversion ) ) { >+ $dbh->do( "SHOW TABLES" ); >+ >+ # Always end with this (adjust the bug info) >+ SetVersion( $DBversion ); >+ $ENV{ATOMICUPDATE_TESTS_INV}++; >+ print "Upgrade to $DBversion done (Bug XXXXX - description)\n"; >+ } >+ }; >+ >+ my $test_file1 = create_file({ >+ filepath => 'atomicupdate/', >+ filename => 'Bug_00001-First-update.perl', >+ content => $dev_update, >+ }); >+ >+ my $test_file2 = create_file({ >+ filepath => 'atomicupdate/', >+ filename => 'Bug_00002-Invalid-update.perl', >+ content => $dev_update_invalid, >+ }); >+ >+ my $atomicUpdater = Koha::AtomicUpdater->new({ >+ scriptDir => $test_file->dirname(), >+ }); >+ >+ my $atomicUpdater_invalid = Koha::AtomicUpdater->new({ >+ scriptDir => $test_file->dirname(), >+ }); >+ >+ $atomicUpdater->applyAtomicUpdate( $test_file1->stringify ); >+ >+ $atomicUpdater_invalid->applyAtomicUpdate( $test_file2->stringify ); >+ >+ my $atomicUpdate = $atomicUpdater->find('Bug-00001'); >+ my $atomicUpdate_invalid = $atomicUpdater->find('Bug-00002'); >+ >+ is($atomicUpdate->filename, "Bug_00001-First-update.perl", "Bug_00001-First-update.perl added to DB"); >+ is($atomicUpdate_invalid->filename, "Bug_00002-Invalid-update.perl", "Bug_00002-Invalid-update.perl added to DB"); >+ is($ENV{ATOMICUPDATE_TESTS_VAL}, 1, "First update execution success."); >+ is($ENV{ATOMICUPDATE_TESTS_INV}, undef, "Invalid update execution failed."); >+ >+ $test_file1->remove; >+ $test_file2->remove; >+ $schema->storage->txn_rollback; >+}; >+ >+$test_file->remove; >+ > sub create_file { > my ($file) = @_; > my $tmpdir = File::Spec->tmpdir(); >-- >2.17.1 >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 14698
:
42112
|
42113
|
42385
|
42386
|
42395
|
42398
|
42426
|
42521
|
42523
|
62141
|
64404
|
102899
|
102900
|
102901
|
102902
| 102903