Bug 18930: (follow-up) Make DB update idempotent
authorTomas Cohen Arazi <tomascohen@theke.io>
Wed, 6 Mar 2019 13:41:17 +0000 (10:41 -0300)
committerMartin Renvoize <martin.renvoize@ptfs-europe.com>
Mon, 15 Jul 2019 10:27:59 +0000 (11:27 +0100)
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Agustin Moyano <agustinmoyano@theke.io>
Signed-off-by: Josef Moravec <josef.moravec@gmail.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

installer/data/mysql/atomicupdate/bug_18930.perl

index 99533de..92be5bd 100644 (file)
@@ -1,12 +1,15 @@
 $DBversion = 'XXX';  # will be replaced by the RM
 if( CheckVersion( $DBversion ) ) {
-    if ( column_exists( 'refund_lost_item_fee_rules', 'refund' ) ) {
-        $dbh->do("
-            INSERT INTO circulation_rules ( categorycode, branchcode, itemtype, rule_name, rule_value )
-            SELECT NULL, IF(branchcode='*', NULL, branchcode), NULL, 'refund', refund
-            FROM refund_lost_item_fee_rules
-        ");
-        $dbh->do("DROP TABLE refund_lost_item_fee_rules");
+
+    if ( TableExists('refund_lost_item_fee_rules') ) {
+        if ( column_exists( 'refund_lost_item_fee_rules', 'refund' ) ) {
+            $dbh->do("
+                INSERT INTO circulation_rules ( categorycode, branchcode, itemtype, rule_name, rule_value )
+                SELECT NULL, IF(branchcode='*', NULL, branchcode), NULL, 'refund', refund
+                FROM refund_lost_item_fee_rules
+            ");
+            $dbh->do("DROP TABLE refund_lost_item_fee_rules");
+        }
     }
 
     SetVersion( $DBversion );