From 3f58580da6da5acaf1e1dcbb2c5e6b1785e13351 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 --- 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 1d973704d5..81421f5063 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -21721,6 +21721,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 ) { @@ -21764,6 +21773,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) |); $dbh->do(q| -- 2.11.0