From 923e3efa2680a1b2e4360247345ae5c634b9861a Mon Sep 17 00:00:00 2001 From: Thibaud Guillot Date: Wed, 14 Aug 2024 15:55:32 +0200 Subject: [PATCH] Fix upgrade (dry_run missing) If koha was down when the install_plugins script was launched, the dry_run column was not correctly added. This upgrade solves this problem. --- Koha/Plugin/Com/Biblibre/PatronImport.pm | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/Koha/Plugin/Com/Biblibre/PatronImport.pm b/Koha/Plugin/Com/Biblibre/PatronImport.pm index 82d900c..9636350 100644 --- a/Koha/Plugin/Com/Biblibre/PatronImport.pm +++ b/Koha/Plugin/Com/Biblibre/PatronImport.pm @@ -9,7 +9,7 @@ use Mojo::JSON qw(decode_json);; use base qw(Koha::Plugins::Base); -our $VERSION = '2.1'; +our $VERSION = '2.2'; our $metadata = { name => 'Patron import', @@ -519,7 +519,6 @@ sub upgrade { } if ($DBversion < '1.4') { - my $dbh = C4::Context->dbh; my $exclusions_table = $self->get_qualified_table_name('exclusions_rules'); $dbh->do("ALTER TABLE $exclusions_table ADD COLUMN origin ENUM('ext', 'koha') NOT NULL AFTER name;"); } @@ -589,7 +588,7 @@ sub upgrade { "); } - if ( Koha::Plugins::Base::_version_compare($DBversion, '1.91') == -1 ) { + if ( Koha::Plugins::Base::_version_compare($DBversion, '1.91') == -1 ) { my $runs_table = $self->get_qualified_table_name('runs'); $dbh->do("ALTER TABLE $runs_table ADD COLUMN dry_run int(1) COLLATE utf8_unicode_ci NOT NULL DEFAULT 0 AFTER error;"); } @@ -611,6 +610,13 @@ sub upgrade { $dbh->do("ALTER TABLE $import_table ADD COLUMN welcome_message tinyint COLLATE utf8_unicode_ci NULL;"); } + if ($DBversion < '2.2') { + my $runs_table = $self->get_qualified_table_name('runs'); + unless (_column_exists($dbh, $runs_table, 'dry_run')) { + $dbh->do("ALTER TABLE $runs_table ADD COLUMN dry_run int(1) COLLATE utf8_unicode_ci NOT NULL DEFAULT 0 AFTER error;"); + } + } + $self->store_data({'__INSTALLED_VERSION__' => $VERSION}); return 1; @@ -701,4 +707,11 @@ sub _enable_borrowers_logs { C4::Context->set_preference( 'BorrowersLog', $self->{BorrowersLog} ); } +sub _column_exists { + my ($dbh, $table, $column) = @_; + my $sth = $dbh->prepare("SHOW COLUMNS FROM $table LIKE ?"); + $sth->execute($column); + return $sth->fetchrow_arrayref ? 1 : 0; + } + 1;