From a4665ffc5fae447a0bedc36630b4ec9eada4be41 Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Tue, 4 Jun 2013 15:21:21 +0200 Subject: [PATCH] =?utf8?q?Perl-Upgrade-Files:=20Nach=20Exception=20Rollbac?= =?utf8?q?k=20&=20bei=20Erfolg=20immer=201=20zur=C3=BCckgeben?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Exceptions sind vorher nach oben gebubblet, da $result undef war. $result // 1 ist nun mal 1, was überhaupt keinen Sinn ergibt -- und dadurch wurde kein Rollback gemacht (geschweige denn die Fehlermeldung wie gewünscht ausgegeben). Resultat war bei Perl-DB-Upgrades der Auth-Datenbank, dass trotz Exception später beim Speichern der Session ein Commit gemacht wurde -- und damit alle Änderungen vor der Exception mit übernommen wurden (sofern es da keinen Datenbankfehler gab sonder nur eine von Perl selber ausgelöste Exception). --- SL/DBUpgrade2.pm | 23 +++++++++++-------- sql/Pg-upgrade2/SKR04-3804-addition.pl | 1 + sql/Pg-upgrade2/USTVA_abstraction.pl | 2 +- sql/Pg-upgrade2/USTVA_at.pl | 2 +- .../fix_acc_trans_ap_taxkey_bug.pl | 2 ++ 5 files changed, 18 insertions(+), 12 deletions(-) diff --git a/SL/DBUpgrade2.pm b/SL/DBUpgrade2.pm index 6de1fd258..5bf31d7e8 100644 --- a/SL/DBUpgrade2.pm +++ b/SL/DBUpgrade2.pm @@ -1,5 +1,6 @@ package SL::DBUpgrade2; +use English qw(-no_match_vars); use IO::File; use List::MoreUtils qw(any); @@ -248,19 +249,21 @@ sub process_perl_script { # setup dbup_ export vars & run script my %dbup_myconfig = map { ($_ => $::form->{$_}) } qw(dbname dbuser dbpasswd dbhost dbport dbconnect); - my $result = SL::DBUpgrade2::Base::execute_script( - file_name => $filename, - tag => $version_or_control->{tag}, - dbh => $dbh, - myconfig => \%dbup_myconfig, - ); + my $result = eval { + SL::DBUpgrade2::Base::execute_script( + file_name => $filename, + tag => $version_or_control->{tag}, + dbh => $dbh, + myconfig => \%dbup_myconfig, + ); + }; - if (1 != ($result // 1)) { - $dbh->rollback(); - } + my $error = $EVAL_ERROR; + + $dbh->rollback if 1 != ($result // -1); if (!defined($result)) { - print $::form->parse_html_template("dbupgrade/error", { file => $filename, error => $@ }); + print $::form->parse_html_template("dbupgrade/error", { file => $filename, error => $error }); ::end_of_request(); } elsif (1 != $result) { unlink("users/nologin") if (2 == $result); diff --git a/sql/Pg-upgrade2/SKR04-3804-addition.pl b/sql/Pg-upgrade2/SKR04-3804-addition.pl index e11d7928e..ce8618f66 100644 --- a/sql/Pg-upgrade2/SKR04-3804-addition.pl +++ b/sql/Pg-upgrade2/SKR04-3804-addition.pl @@ -110,6 +110,7 @@ SQL $sth_query->finish; $sth_insert->finish; + return 1; } # end run sub print_past_booking_warning { diff --git a/sql/Pg-upgrade2/USTVA_abstraction.pl b/sql/Pg-upgrade2/USTVA_abstraction.pl index fc1638cd0..fe64a9224 100644 --- a/sql/Pg-upgrade2/USTVA_abstraction.pl +++ b/sql/Pg-upgrade2/USTVA_abstraction.pl @@ -147,7 +147,7 @@ sub do_copy { sub run { my ($self) = @_; - return $self->create_tables && $self->do_copy; + return $self->create_tables && $self->do_copy ? 1 : undef; } 1; diff --git a/sql/Pg-upgrade2/USTVA_at.pl b/sql/Pg-upgrade2/USTVA_at.pl index 02143aec9..a677c5121 100644 --- a/sql/Pg-upgrade2/USTVA_at.pl +++ b/sql/Pg-upgrade2/USTVA_at.pl @@ -36,7 +36,7 @@ sub run { && $self->do_insert_tax() && $self->do_insert_taxkeys() && $self->do_insert_buchungsgruppen() - ; + ? 1 : 0; } sub clear_tables { diff --git a/sql/Pg-upgrade2/fix_acc_trans_ap_taxkey_bug.pl b/sql/Pg-upgrade2/fix_acc_trans_ap_taxkey_bug.pl index f556ff23a..ec9e7f6af 100644 --- a/sql/Pg-upgrade2/fix_acc_trans_ap_taxkey_bug.pl +++ b/sql/Pg-upgrade2/fix_acc_trans_ap_taxkey_bug.pl @@ -91,6 +91,8 @@ SQL $h_change->finish(); print $::locale->text('Number of entries changed: #1', $num_changed) . "
\n"; + + return 1; } 1; -- 2.20.1