Bug 21520: (QA follow-up): Updatedatabase
authorMatthias Meusburger <matthias.meusburger@biblibre.com>
Mon, 13 Jan 2020 15:26:30 +0000 (16:26 +0100)
committerMartin Renvoize <martin.renvoize@ptfs-europe.com>
Wed, 15 Jan 2020 13:50:17 +0000 (13:50 +0000)
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

installer/data/mysql/atomicupdate/bug_21520.perl

index 6b5a56e..ccf3178 100644 (file)
@@ -2,6 +2,25 @@ $DBversion = 'XXX'; # will be replaced by the RM
 if( CheckVersion( $DBversion ) ) {
     $dbh->do( "ALTER TABLE oai_sets_mappings ADD COLUMN rule_order INT AFTER set_id, ADD COLUMN rule_operator VARCHAR(3) AFTER rule_order" );
     $dbh->do( "UPDATE oai_sets_mappings SET rule_operator='or'" );
+    my $sets = $dbh->selectall_arrayref("SELECT * from oai_sets_mappings ORDER BY set_id", { Slice => {} });
+    my $i = 0;
+    my $previous_set_id;
+    for my $set ( @{$sets}) {
+        my $set_id = $set->{set_id};
+
+        if ($previous_set_id && $previous_set_id != $set_id) {
+            $i = 0;
+        }
+
+        if ($i == 0) {
+            $dbh->do("UPDATE oai_sets_mappings SET rule_operator=NULL WHERE set_id=? LIMIT 1", {}, $set_id);
+        }
+
+        $dbh->do("UPDATE oai_sets_mappings SET rule_order=? WHERE set_id=? AND rule_order IS NULL LIMIT 1", {}, $i, $set_id);
+
+        $i++;
+        $previous_set_id = $set_id;
+    }
 
     # Always end with this (adjust the bug info)
     SetVersion( $DBversion );