From 4315a6144753cef3d9a6ed8ccc00f520c4a079fe Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Wed, 1 Feb 2023 11:33:56 -0300 Subject: [PATCH] Bug 20256: (QA follow-up) Make atomicupdate idempotent Without this patch, running the atomicupdate twice crashes on patrons with edit_items permissions: C4::Installer::run_atomic_updates(): DBI Exception: DBD::mysql::db do failed: Duplicate entry '19-9-edit_any_item' for key 'PRIMARY' at /kohadevbox/koha/installer/data/mysql/updatedatabase.pl line 24303 DEV atomic update /kohadevbox/koha/installer/data/mysql/atomicupdate/bug_20256.perl [14:26:41] ERROR - C4::Installer::run_atomic_updates(): DBI Exception: DBD::mysql::db do failed: Duplicate entry '19-9-edit_any_item' for key 'PRIMARY' at /kohadevbox/koha/installer/data/mysql/updatedatabase.pl line 24303 It also aligns this 3yro script with the new structure we've been using. Signed-off-by: Tomas Cohen Arazi --- .../data/mysql/atomicupdate/bug_20256.perl | 19 ----------- .../data/mysql/atomicupdate/bug_20256.pl | 32 +++++++++++++++++++ 2 files changed, 32 insertions(+), 19 deletions(-) delete mode 100644 installer/data/mysql/atomicupdate/bug_20256.perl create mode 100755 installer/data/mysql/atomicupdate/bug_20256.pl diff --git a/installer/data/mysql/atomicupdate/bug_20256.perl b/installer/data/mysql/atomicupdate/bug_20256.perl deleted file mode 100644 index 28049442e7..0000000000 --- a/installer/data/mysql/atomicupdate/bug_20256.perl +++ /dev/null @@ -1,19 +0,0 @@ -$DBversion = 'XXX'; # will be replaced by the RM -if( CheckVersion( $DBversion ) ) { - $dbh->do( "INSERT IGNORE INTO permissions (module_bit, code, description) VALUES ( 9, 'edit_any_item', 'Edit any item reguardless of home library');" ); - - $dbh->do(q{ - INSERT INTO user_permissions ( borrowernumber, module_bit, code ) - SELECT borrowernumber, '9', 'edit_any_item' - FROM user_permissions - WHERE module_bit = '9' - AND code = 'edit_items' - }); - - if ( !column_exists( 'library_groups', 'ft_limit_item_editing' ) ) { - $dbh->do( "ALTER TABLE library_groups ADD COLUMN ft_limit_item_editing tinyint(1) NOT NULL DEFAULT 0 AFTER ft_hide_patron_info" ); - } - - SetVersion( $DBversion ); - print "Upgrade to $DBversion done (Bug 20256 - Add ability to limit editing of items to home library)\n"; -} diff --git a/installer/data/mysql/atomicupdate/bug_20256.pl b/installer/data/mysql/atomicupdate/bug_20256.pl new file mode 100755 index 0000000000..2df9e03d06 --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_20256.pl @@ -0,0 +1,32 @@ +use Modern::Perl; + +return { + bug_number => "20256", + description => "Add ability to limit editing of items to home library", + up => sub { + my ($args) = @_; + my ($dbh, $out) = @$args{qw(dbh out)}; + + $dbh->do(q{ + INSERT IGNORE INTO permissions (module_bit, code, description) VALUES ( 9, 'edit_any_item', 'Edit any item reguardless of home library'); + }); + say $out "Added new permission 'edit_any_item'"; + + $dbh->do(q{ + INSERT IGNORE INTO user_permissions ( borrowernumber, module_bit, code ) + SELECT borrowernumber, '9', 'edit_any_item' + FROM user_permissions + WHERE module_bit = '9' + AND code = 'edit_items' + }); + + if ( !column_exists( 'library_groups', 'ft_limit_item_editing' ) ) { + $dbh->do(q{ + ALTER TABLE library_groups + ADD COLUMN ft_limit_item_editing tinyint(1) NOT NULL DEFAULT 0 AFTER ft_hide_patron_info + }); + + say $out "Added column 'library_groups.ft_limit_item_editing'"; + } + }, +}; -- 2.39.5