Bug 11309: avoid creating duplicate numbering patterns during upgrade to 3.14.x
authorNuño López Ansótegui <nunyo@masmedios.com>
Tue, 26 Nov 2013 17:38:43 +0000 (18:38 +0100)
committerGalen Charlton <gmc@esilibrary.com>
Mon, 5 May 2014 03:38:44 +0000 (03:38 +0000)
To test:

1/ Install Koha 3.12
2/ Create some subscriptions. Ensure you have at least two
   subscriptions with the same numbering pattern, with one of the
   keys everyX/addX/whenmorethanX/settoX set to NULL
3/ Remember this numbering pattern.
4/ Upgrade to 3.14
5/ Run updatedatabase.pl
6/ The numbering pattern is duplicated

Now repeat steps 1 to 4, then apply the patch and run
updatedatabase.pl. Numbering pattern should not be duplicated.

Signed-off-by: Julian Maurice <julian.maurice@biblibre.com>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
installer/data/mysql/updatedatabase.pl

index a210e4b..eb0a2c6 100755 (executable)
@@ -7470,11 +7470,13 @@ if ( CheckVersion($DBversion) ) {
     |);
     my $check_numberpatterns_sth = $dbh->prepare(qq|
         SELECT * FROM subscription_numberpatterns
-        WHERE add1 = ? AND add2 = ? AND add3 = ?
-          AND every1 = ? AND every2 = ? AND every3 = ?
-          AND whenmorethan1 = ? AND whenmorethan2 = ? AND whenmorethan3 = ?
-          AND setto1 = ? AND setto2 = ? AND setto3 = ?
-          AND numberingmethod = ?
+        WHERE (add1 = ? OR (add1 IS NULL AND ? IS NULL)) AND (add2 = ? OR (add2 IS NULL AND ? IS NULL))
+        AND (add3 = ? OR (add3 IS NULL AND ? IS NULL)) AND (every1 = ? OR (every1 IS NULL AND ? IS NULL))
+        AND (every2 = ? OR (every2 IS NULL AND ? IS NULL)) AND (every3 = ? OR (every3 IS NULL AND ? IS NULL))
+        AND (whenmorethan1 = ? OR (whenmorethan1 IS NULL AND ? IS NULL)) AND (whenmorethan2 = ? OR (whenmorethan2 IS NULL AND ? IS NULL))
+        AND (whenmorethan3 = ? OR (whenmorethan3 IS NULL AND ? IS NULL)) AND (setto1 = ? OR (setto1 IS NULL AND ? IS NULL))
+        AND (setto2 = ? OR (setto2 IS NULL AND ? IS NULL)) AND (setto3 = ? OR (setto3 IS NULL AND ? IS NULL))
+        AND (numberingmethod = ? OR (numberingmethod IS NULL AND ? IS NULL))
         LIMIT 1
     |);
     my $update_subscription_sth = $dbh->prepare(qq|
@@ -7487,11 +7489,11 @@ if ( CheckVersion($DBversion) ) {
     my $i = 1;
     while(my $sub = $sth->fetchrow_hashref) {
         $check_numberpatterns_sth->execute(
-            $sub->{add1}, $sub->{add2}, $sub->{add3},
-            $sub->{every1}, $sub->{every2}, $sub->{every3},
-            $sub->{whenmorethan1}, $sub->{whenmorethan2}, $sub->{whenmorethan3},
-            $sub->{setto1}, $sub->{setto2}, $sub->{setto3},
-            $sub->{numberingmethod}
+            $sub->{add1}, $sub->{add1}, $sub->{add2}, $sub->{add2}, $sub->{add3}, $sub->{add3},
+            $sub->{every1}, $sub->{every1}, $sub->{every2}, $sub->{every2}, $sub->{every3}, $sub->{every3},
+            $sub->{whenmorethan1}, $sub->{whenmorethan1}, $sub->{whenmorethan2}, $sub->{whenmorethan2},
+            $sub->{whenmorethan3}, $sub->{whenmorethan3}, $sub->{setto1}, $sub->{setto1}, $sub->{setto2},
+            $sub->{setto2}, $sub->{setto3}, $sub->{setto3}, $sub->{numberingmethod}, $sub->{numberingmethod}
         );
         my $p = $check_numberpatterns_sth->fetchrow_hashref;
         if (defined $p) {