From fc42eeba6a66c02459332e257fdb1364fb257270 Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Mon, 12 Sep 2016 14:20:19 +0000 Subject: [PATCH] Bug 17292 - Use of DBIx in updatedatabase.pl broke upgrade MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit A recent change in the 'subscription' table structure highlighted a problem in a DBRev upgrade (3.23.00.006). As it adds a new column, when upgrading from (say) 3.20.00.000 the code/schema (correctly) expects the subscription.itemtype column to exist. But it is not created until DBRev 16.06.00.025. To reproduce: - Have a clean 3.20.00 DB loaded into kohadevbox - Checkout current master - Run: $ perl installer/data/mysql/updatedatabase.pl => FAIL: The upgrade procedure fails due to missing colum. The solution: rewrite the updatedatabase.pl entry using plain DBI Signed-off-by: Mark Tompsett Signed-off-by: Jonathan Druart Signed-off-by: Brendan Gallagher (cherry picked from commit f11f07a703eca7da2d32c105f8c9f4f46f940b6f) Signed-off-by: Frédéric Demians --- installer/data/mysql/updatedatabase.pl | 36 ++++++++++++++++---------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index 1ccb145b49..ca5e059fc8 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -11466,13 +11466,19 @@ if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) { ADD serialseq_z VARCHAR( 100 ) NULL DEFAULT NULL AFTER serialseq_y "); - my $schema = Koha::Database->new()->schema(); - my @subscriptions = $schema->resultset('Subscription')->all(); + my $sth = $dbh->prepare("SELECT * FROM subscription"); + $sth->execute(); + + my $sth2 = $dbh->prepare("SELECT * FROM subscription_numberpatterns WHERE id = ?"); + + my $sth3 = $dbh->prepare("UPDATE serials SET serialseq_x = ?, serialseq_y = ?, serialseq_z = ? WHERE serialid = ?"); - foreach my $subscription (@subscriptions) { + foreach my $subscription ( $sth->fetchrow_hashref() ) { my $number_pattern = $subscription->numberpattern(); + $sth2->execute( $subscription->{numberpattern} ); + my $number_pattern = $sth2->fetchrow_hashref(); - my $numbering_method = $number_pattern->numberingmethod(); + my $numbering_method = $number_pattern->{numberingmethod}; # Get all the data between the enumeration values, we need # to split each enumeration string based on these values. my @splits = split( /\{[XYZ]\}/, $numbering_method ); @@ -11484,12 +11490,15 @@ if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) { } my @indexes = sort { $indexes{$a} <=> $indexes{$b} } keys(%indexes); - my @serials = - $schema->resultset('Serial') - ->search( { subscriptionid => $subscription->subscriptionid() } ); + my @serials = @{ + $dbh->selectall_arrayref( + "SELECT * FROM serial WHERE subscriptionid = $subscription->{subscriptionid}", + { Slice => {} } + ) + }; foreach my $serial (@serials) { - my $serialseq = $serial->serialseq(); + my $serialseq = $serial->{serialseq}; my %enumeration_data; ## We cannot split on multiple values at once, @@ -11511,12 +11520,11 @@ if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) { $enumeration_data{ $indexes[0] } = $serialseq; } - $serial->update( - { - serialseq_x => $enumeration_data{'X'}, - serialseq_y => $enumeration_data{'Y'}, - serialseq_z => $enumeration_data{'Z'}, - } + $sth3->execute( + $enumeration_data{'X'}, + $enumeration_data{'Y'}, + $enumeration_data{'Z'}, + $serial->{serialid}, ); } } -- 2.39.5