From 175838804559e79f365a47aca827a8abb1123d6d Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Fri, 11 Sep 2020 12:51:47 +0100 Subject: [PATCH] Bug 26268: (QA follow-up) Conditionally remove This patch adds conditions to prevent the removal of items.paidfor if it is populated and also adds the removal fo the marc_subfield_structure row if it exists. Signed-off-by: Katrin Fischer Signed-off-by: Martin Renvoize Signed-off-by: Jonathan Druart --- installer/data/mysql/atomicupdate/bug_26268.perl | 56 ++++++++++++++++++------ 1 file changed, 43 insertions(+), 13 deletions(-) rewrite installer/data/mysql/atomicupdate/bug_26268.perl (81%) diff --git a/installer/data/mysql/atomicupdate/bug_26268.perl b/installer/data/mysql/atomicupdate/bug_26268.perl dissimilarity index 81% index a5769225e4..c45dc65ddf 100644 --- a/installer/data/mysql/atomicupdate/bug_26268.perl +++ b/installer/data/mysql/atomicupdate/bug_26268.perl @@ -1,13 +1,43 @@ -$DBversion = 'XXX'; # will be replaced by the RM -if( CheckVersion( $DBversion ) ) { - - if( column_exists( 'items', 'paidfor' ) ) { - $dbh->do(q|ALTER TABLE items DROP COLUMN paidfor|); - } - - if ( column_exists( 'deleteditems', 'paidfor' ) ) { - $dbh->do(q|ALTER TABLE deleteditems DROP COLUMN paidfor|); - } - - NewVersion( $DBversion, 26268, "Remove items.paidfor field"); -} +$DBversion = 'XXX'; # will be replaced by the RM +if ( CheckVersion($DBversion) ) { + + if ( column_exists( 'items', 'paidfor' ) ) { + my ($count) = $dbh->selectrow_array( + qq| + SELECT COUNT(*) + FROM items + WHERE paidfor IS NOT NULL AND paidfor <> "" + | + ); + if ($count) { + warn "Warning - Cannot remove column items.paidfor. At least one value exists"; + } + else { + $dbh->do(q|ALTER TABLE items DROP COLUMN paidfor|); + $dbh->do(q| + DELETE FROM marc_subfield_structure + WHERE tagfield = '952' + AND tagsubfield = 'x' + AND kohafield = 'items.paidfor' + |); + } + } + + if ( column_exists( 'deleteditems', 'paidfor' ) ) { + my ($count) = $dbh->selectrow_array( + qq| + SELECT COUNT(*) + FROM items + WHERE paidfor IS NOT NULL AND paidfor <> "" + | + ); + if ($count) { + warn "Warning - Cannot remove column deleteditems.paidfor. At least one value exists"; + } + else { + $dbh->do(q|ALTER TABLE deleteditems DROP COLUMN paidfor|); + } + } + + NewVersion( $DBversion, 26268, "Remove items.paidfor field" ); +} -- 2.11.4.GIT