From 7fadc22cd0ae1327a33a2467aa9c9e972ef058d0 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Thu, 4 Mar 2021 12:42:59 +0000 Subject: [PATCH] Bug 27842: (follow-up) Correct existing serail/subscriptionhistory before deletion Signed-off-by: Tomas Cohen Arazi Signed-off-by: Jonathan Druart (cherry picked from commit f29a41288c67015f28b0fe56c0de531ee247e139) Signed-off-by: Fridolin Somers --- installer/data/mysql/updatedatabase.pl | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index b4d2a27e4a..a4304b2237 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -21703,6 +21703,15 @@ if( CheckVersion( $DBversion ) ) { unless ( foreign_key_exists( 'serial', 'serial_ibfk_1' ) ) { my $serials = $dbh->selectall_arrayref(q| + SELECT serialid FROM serial JOIN subscription USING (subscriptionid) WHERE serial.biblionumber != subscription.biblionumber + |, { Slice => {} }); + if ( @$serials ) { + push @warnings, q|WARNING - The following serials will be updated, they were attached to a different biblionumber than their related subscription: | . join ", ", map { $_->{serialid} } @$serials; + $dbh->do(q| + UPDATE serial JOIN subscription USING (subcriptionid) SET serial.biblionumber = subscription.biblionumber WHERE serial.biblionumber != subscription.biblionumber + |); + } + $serials = $dbh->selectall_arrayref(q| SELECT serialid FROM serial WHERE biblionumber NOT IN (SELECT biblionumber FROM biblio) |, { Slice => {} }); if ( @$serials ) { @@ -21745,6 +21754,9 @@ if( CheckVersion( $DBversion ) ) { |); unless ( foreign_key_exists( 'subscriptionhistory', 'subscription_history_ibfk_1' ) ) { + $dbh->do(q| + UPDATE subscriptionhistory JOIN subscription USING (subcriptionid) SET subscriptionhistory.biblionumber = subscription.biblionumber WHERE subscriptionhistory.biblionumber != subscription.biblionumber + |); $dbh->do(q| DELETE FROM subscriptionhistory WHERE biblionumber NOT IN (SELECT biblionumber FROM biblio) |); -- 2.39.5