From f3bd7157279fabeefa7c82d417926f69a6ee3449 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 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 --- 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 6ef6576..3670a2c 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -11469,13 +11469,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 ); @@ -11487,12 +11493,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, @@ -11514,12 +11523,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.1.4