From f71f6a77a2df8e7d9db765b8a4991459b2224434 Mon Sep 17 00:00:00 2001 From: Matthias Meusburger Date: Mon, 13 Jan 2020 16:26:30 +0100 Subject: [PATCH] Bug 21520: (QA follow-up): Updatedatabase Signed-off-by: Jonathan Druart --- installer/data/mysql/atomicupdate/bug_21520.perl | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/installer/data/mysql/atomicupdate/bug_21520.perl b/installer/data/mysql/atomicupdate/bug_21520.perl index 6b5a56e797..ccf3178164 100644 --- a/installer/data/mysql/atomicupdate/bug_21520.perl +++ b/installer/data/mysql/atomicupdate/bug_21520.perl @@ -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 ); -- 2.11.0