From dd690f19c285087d1df2d6e843185607391e02ba Mon Sep 17 00:00:00 2001 From: Andrew Nugged Date: Wed, 4 May 2022 17:02:28 +0300 Subject: [PATCH] Bug 20447: (QA follow-up) Fix atomic update to be more idempotent Fix atomic update not to add bad ACQ 952k row into marc_subfield_structure when no ACQ present at all --- .../bug_20447-add_holdings_tables.perl | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/installer/data/mysql/atomicupdate/bug_20447-add_holdings_tables.perl b/installer/data/mysql/atomicupdate/bug_20447-add_holdings_tables.perl index 5fed02b80a..d2e48caf8c 100644 --- a/installer/data/mysql/atomicupdate/bug_20447-add_holdings_tables.perl +++ b/installer/data/mysql/atomicupdate/bug_20447-add_holdings_tables.perl @@ -69,16 +69,27 @@ if( CheckVersion( $DBversion ) ) { }); if (C4::Context->preference("marcflavour") eq 'MARC21') { + # items.holding_id in the default framework $dbh->do(q{ INSERT IGNORE INTO `marc_subfield_structure` (`tagfield`, `tagsubfield`, `liblibrarian`, `libopac`, `repeatable`, `mandatory`, `kohafield`, `tab`, `authorised_value`, `authtypecode`, `value_builder`, `isurl`, `hidden`, `frameworkcode`, `seealso`, `link`, `defaultvalue`) VALUES ('952', 'k', 'Holdings record', 'Holdings record', 0, 0, 'items.holding_id', 10, 'holdings', '', '', NULL, -1, '', '', '', NULL); }); + # items.holding_id in the ACQ framework - $dbh->do(q{ - INSERT IGNORE INTO `marc_subfield_structure` (`tagfield`, `tagsubfield`, `liblibrarian`, `libopac`, `repeatable`, `mandatory`, `kohafield`, `tab`, `authorised_value`, `authtypecode`, `value_builder`, `isurl`, `hidden`, `frameworkcode`, `seealso`, `link`, `defaultvalue`) VALUES - ('952', 'k', 'Holdings record', 'Holdings record', 0, 0, 'items.holding_id', 10, 'holdings', '', '', NULL, -1, 'ACQ', '', '', NULL); - }); + # add only if ACQ framework exists: + my $sth = $dbh->prepare("SELECT COUNT(1) FROM `biblio_framework` WHERE frameworkcode = 'ACQ'"); + $sth->execute; + my ($value) = $sth->fetchrow; + if($value == 1) { + $dbh->do(q{ + INSERT IGNORE INTO `marc_subfield_structure` (`tagfield`, `tagsubfield`, `liblibrarian`, `libopac`, `repeatable`, `mandatory`, `kohafield`, `tab`, `authorised_value`, `authtypecode`, `value_builder`, `isurl`, `hidden`, `frameworkcode`, `seealso`, `link`, `defaultvalue`) VALUES + ('952', 'k', 'Holdings record', 'Holdings record', 0, 0, 'items.holding_id', 10, 'holdings', '', '', NULL, -1, 'ACQ', '', '', NULL); + }); + } + else { + + } # Holdings framework $dbh->do(q{ -- 2.37.2