Bug 18925: (QA follow-up) Make DB update idempotent

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>

Signed-off-by: Josef Moravec <josef.moravec@gmail.com>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
This commit is contained in:
Tomas Cohen Arazi 2019-03-02 10:14:48 -03:00 committed by Nick Clemens
parent 566bb29766
commit fc92437665
1 changed files with 28 additions and 24 deletions

View File

@ -1,31 +1,35 @@
$DBversion = 'XXX'; # will be replaced by the RM
if( CheckVersion( $DBversion ) ) {
if ( column_exists( 'branch_borrower_circ_rules', 'maxissueqty' ) ) {
$dbh->do("
INSERT INTO circulation_rules ( categorycode, branchcode, itemtype, rule_name, rule_value )
SELECT categorycode, branchcode, NULL, 'patron_maxissueqty', COALESCE( maxissueqty, '' )
FROM branch_borrower_circ_rules
");
$dbh->do("
INSERT INTO circulation_rules ( categorycode, branchcode, itemtype, rule_name, rule_value )
SELECT categorycode, branchcode, NULL, 'patron_maxonsiteissueqty', COALESCE( maxonsiteissueqty, '' )
FROM branch_borrower_circ_rules
");
$dbh->do("DROP TABLE branch_borrower_circ_rules");
if ( TableExists( 'branch_borrower_circ_rules' ) ) {
if ( column_exists( 'branch_borrower_circ_rules', 'maxissueqty' ) ) {
$dbh->do("
INSERT INTO circulation_rules ( categorycode, branchcode, itemtype, rule_name, rule_value )
SELECT categorycode, branchcode, NULL, 'patron_maxissueqty', COALESCE( maxissueqty, '' )
FROM branch_borrower_circ_rules
");
$dbh->do("
INSERT INTO circulation_rules ( categorycode, branchcode, itemtype, rule_name, rule_value )
SELECT categorycode, branchcode, NULL, 'patron_maxonsiteissueqty', COALESCE( maxonsiteissueqty, '' )
FROM branch_borrower_circ_rules
");
$dbh->do("DROP TABLE branch_borrower_circ_rules");
}
}
if ( column_exists( 'default_borrower_circ_rules', 'maxissueqty' ) ) {
$dbh->do("
INSERT INTO circulation_rules ( categorycode, branchcode, itemtype, rule_name, rule_value )
SELECT categorycode, NULL, NULL, 'patron_maxissueqty', COALESCE( maxissueqty, '' )
FROM default_borrower_circ_rules
");
$dbh->do("
INSERT INTO circulation_rules ( categorycode, branchcode, itemtype, rule_name, rule_value )
SELECT categorycode, NULL, NULL, 'patron_maxonsiteissueqty', COALESCE( maxonsiteissueqty, '' )
FROM default_borrower_circ_rules
");
$dbh->do("DROP TABLE default_borrower_circ_rules");
if ( TableExists( 'default_borrower_circ_rules' ) ) {
if ( column_exists( 'default_borrower_circ_rules', 'maxissueqty' ) ) {
$dbh->do("
INSERT INTO circulation_rules ( categorycode, branchcode, itemtype, rule_name, rule_value )
SELECT categorycode, NULL, NULL, 'patron_maxissueqty', COALESCE( maxissueqty, '' )
FROM default_borrower_circ_rules
");
$dbh->do("
INSERT INTO circulation_rules ( categorycode, branchcode, itemtype, rule_name, rule_value )
SELECT categorycode, NULL, NULL, 'patron_maxonsiteissueqty', COALESCE( maxonsiteissueqty, '' )
FROM default_borrower_circ_rules
");
$dbh->do("DROP TABLE default_borrower_circ_rules");
}
}
if ( column_exists( 'default_circ_rules', 'maxissueqty' ) ) {