From ea5122cb3e2dd70381bcf64ce4d7e6056687a5cc Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Fri, 22 Sep 2023 10:35:28 +0100 Subject: [PATCH] Bug 34881: Improve idempotency of DBRev --- installer/data/mysql/db_revs/220600015.pl | 54 ++++++++++++----------- 1 file changed, 29 insertions(+), 25 deletions(-) diff --git a/installer/data/mysql/db_revs/220600015.pl b/installer/data/mysql/db_revs/220600015.pl index 89dc2d628bf..19926cd7af4 100755 --- a/installer/data/mysql/db_revs/220600015.pl +++ b/installer/data/mysql/db_revs/220600015.pl @@ -22,31 +22,35 @@ return { say $out "Added new table 'item_bundles'"; - my ($lost_val) = $dbh->selectrow_array( "SELECT MAX(CAST(authorised_value AS SIGNED)) FROM authorised_values WHERE category = 'LOST'", {} ); - $lost_val++; - - $dbh->do(qq{ - INSERT INTO authorised_values (category,authorised_value,lib) VALUES ('LOST',$lost_val,'Missing from bundle') - }); - say $out "Missing from bundle LOST AV added"; - - my ($nfl_val) = $dbh->selectrow_array( "SELECT MAX(CAST(authorised_value AS SIGNED)) FROM authorised_values WHERE category = 'NOT_LOAN'", {} ); - $nfl_val++; - - $dbh->do(qq{ - INSERT INTO authorised_values (category,authorised_value,lib) VALUES ('NOT_LOAN',$nfl_val,'Added to bundle') - }); - say $out "Added to bundle NOT_LOAN AV added"; - - $dbh->do(qq{ - INSERT IGNORE INTO systempreferences( `variable`, `value`, `options`, `explanation`, `type` ) - VALUES - ( 'BundleLostValue', $lost_val, '', 'Sets the LOST AV value that represents "Missing from bundle" as a lost value', 'Free' ), - ( 'BundleNotLoanValue', $nfl_val, '', 'Sets the NOT_LOAN AV value that represents "Added to bundle" as a not for loan value', 'Free') - }); - - say $out "Added new system preference 'BundleLostValue'"; - say $out "Added new system preference 'BundleNotLoanValue'"; + my ($exists) = $dbh->selectrow_array( "SELECT EXISTS(SELECT * FROM authorised_value WHERE lib = 'Missing from bundle'" ); + if ( !$exists ) { + my ($lost_val) = $dbh->selectrow_array( "SELECT MAX(CAST(authorised_value AS SIGNED)) FROM authorised_values WHERE category = 'LOST'", {} ); + $lost_val++; + + $dbh->do(qq{ + INSERT INTO authorised_values (category,authorised_value,lib) VALUES ('LOST',$lost_val,'Missing from bundle') + }); + say $out "Missing from bundle LOST AV added"; + + my ($nfl_val) = $dbh->selectrow_array( "SELECT MAX(CAST(authorised_value AS SIGNED)) FROM authorised_values WHERE category = 'NOT_LOAN'", {} ); + $nfl_val++; + + $dbh->do(qq{ + INSERT INTO authorised_values (category,authorised_value,lib) VALUES ('NOT_LOAN',$nfl_val,'Added to bundle') + }); + say $out "Added to bundle NOT_LOAN AV added"; + + + $dbh->do(qq{ + INSERT IGNORE INTO systempreferences( `variable`, `value`, `options`, `explanation`, `type` ) + VALUES + ( 'BundleLostValue', $lost_val, '', 'Sets the LOST AV value that represents "Missing from bundle" as a lost value', 'Free' ), + ( 'BundleNotLoanValue', $nfl_val, '', 'Sets the NOT_LOAN AV value that represents "Added to bundle" as a not for loan value', 'Free') + }); + + say $out "Added new system preference 'BundleLostValue'"; + say $out "Added new system preference 'BundleNotLoanValue'"; + } if( index_exists( 'return_claims', 'issue_id' ) ) { $dbh->do(q{ -- 2.41.0