From 0372a9e95e7baf4e5699c372d1ba5550d351998d Mon Sep 17 00:00:00 2001 From: Andrew Isherwood Date: Thu, 8 Nov 2018 14:28:48 +0000 Subject: [PATCH] Bug 21079: (follow-up) Move from Try::Tiny to eval In line with similar examples already in Koha, we now eval the transaction, instead of putting it in a try/catch block. This patch also addressed the other comments made in https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=21079#c10 - AutoCommit & RaiseError are now reset - Don't set the version if the update fails Signed-off-by: Nick Clemens --- .../bug_21079_map_illrequestattributes.perl | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/installer/data/mysql/atomicupdate/bug_21079_map_illrequestattributes.perl b/installer/data/mysql/atomicupdate/bug_21079_map_illrequestattributes.perl index d7145cdc2f..e1b1857738 100644 --- a/installer/data/mysql/atomicupdate/bug_21079_map_illrequestattributes.perl +++ b/installer/data/mysql/atomicupdate/bug_21079_map_illrequestattributes.perl @@ -1,4 +1,3 @@ -use Try::Tiny; $DBversion = 'XXX'; # will be replaced by the RM if( CheckVersion( $DBversion ) ) { @@ -58,9 +57,10 @@ if( CheckVersion( $DBversion ) ) { my $changed_str = join(',', @changed); if (scalar @changed > 0) { + my ($raise_error) = $dbh->{RaiseError}; $dbh->{AutoCommit} = 0; $dbh->{RaiseError} = 1; - try { + eval { my $del = $dbh->do( "DELETE FROM illrequestattributes ". "WHERE illrequest_id IN ($changed_str)" @@ -82,12 +82,18 @@ if( CheckVersion( $DBversion ) ) { } } $dbh->commit; - } catch { - warn "Upgrade to $DBversion failed: $_"; - eval { $dbh->rollback }; }; + + if ($@) { + warn "Upgrade to $DBversion failed: $@\n"; + eval { $dbh->rollback }; + } else { + SetVersion( $DBversion ); + print "Upgrade to $DBversion done (Bug 21079 - Unify metadata schema across backends)\n"; + } + + $dbh->{AutoCommit} = 1; + $dbh->{RaiseError} = $raise_error; } - SetVersion( $DBversion ); - print "Upgrade to $DBversion done (Bug 21079 - Unify metadata schema across backends)\n"; } -- 2.39.5