Bug 7372: (follow-up) does execute this DB entry twice
authorJonathan Druart <jonathan.druart@biblibre.com>
Thu, 11 Sep 2014 13:22:44 +0000 (15:22 +0200)
committerTomas Cohen Arazi <tomascohen@gmail.com>
Tue, 23 Sep 2014 18:29:58 +0000 (15:29 -0300)
Since this enh has been backported on 3.14, this patch should be applied
on 3.16 and master branch in order to update the updatedb entry.
It should not be executed twice otherwise the process is stuck on this
entry.

http://irc.koha-community.org/koha/2014-09-11#i_1567078
Signed-off-by: Tomas Cohen Arazi <tomascohen@gmail.com>
installer/data/mysql/updatedatabase.pl

index aae80f1..6ea5911 100755 (executable)
@@ -7984,28 +7984,33 @@ if ( CheckVersion($DBversion) ) {
     $dbh->{AutoCommit} = 0;
     $dbh->{RaiseError} = 1;
 
-    my $av_added = $dbh->do(q|
-        INSERT INTO authorised_values(category, authorised_value, lib, lib_opac)
-            SELECT 'ROADTYPE', roadtypeid, road_type, road_type
-            FROM roadtype;
-    |);
-
-    my $rt_deleted = $dbh->do(q|
-        DELETE FROM roadtype
-    |);
+    eval {
+        $dbh->selectcol_arrayref(q|SELECT COUNT(*) FROM roadtype|);
+    };
+    unless ( $@ ) {
+        warn "pas erreur";
+        my $av_added = $dbh->do(q|
+            INSERT INTO authorised_values(category, authorised_value, lib, lib_opac)
+                SELECT 'ROADTYPE', roadtypeid, road_type, road_type
+                FROM roadtype;
+        |);
 
-    if ( $av_added == $rt_deleted or $rt_deleted eq "0E0" ) {
-        $dbh->do(q|
-            DROP TABLE roadtype;
+        my $rt_deleted = $dbh->do(q|
+            DELETE FROM roadtype
         |);
-        $dbh->commit;
-        print "Upgrade to $DBversion done (Bug 7372: Move road types from the roadtype table to the ROADTYPE authorised values)\n";
-        SetVersion($DBversion);
-    } else {
-        print "Upgrade to $DBversion failed (Bug 7372: Move road types from the roadtype table to the ROADTYPE authorised values.\nTransaction aborted because $@\n)";
-        $dbh->rollback;
-    }
 
+        if ( $av_added == $rt_deleted or $rt_deleted eq "0E0" ) {
+            $dbh->do(q|
+                DROP TABLE roadtype;
+            |);
+            $dbh->commit;
+            print "Upgrade to $DBversion done (Bug 7372: Move road types from the roadtype table to the ROADTYPE authorised values)\n";
+            SetVersion($DBversion);
+        } else {
+            print "Upgrade to $DBversion failed (Bug 7372: Move road types from the roadtype table to the ROADTYPE authorised values.\nTransaction aborted because $@\n)";
+            $dbh->rollback;
+        }
+    }
     $dbh->{AutoCommit} = 1;
     $dbh->{RaiseError} = 0;
 }