From 9d14fd7e7dc33f871b4a0841f85e8f0a347e9df0 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Sven=20Sch=C3=B6ling?= Date: Thu, 27 Oct 2011 16:42:34 +0200 Subject: [PATCH] DB-Fehler in Transaktion nach oben melden --- SL/WH.pm | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/SL/WH.pm b/SL/WH.pm index 833b573b5..bf850fa30 100644 --- a/SL/WH.pm +++ b/SL/WH.pm @@ -59,7 +59,6 @@ sub transfer { my $employee = SL::DB::Manager::Employee->find_by(login => $::form->{login}); my ($now) = selectrow_query($::form, $::form->get_standard_dbh, qq|SELECT current_date|); my @directions = (undef, qw(out in transfer)); - my $db = SL::DB->create(undef, 'LXOFFICE'); # get handle for transaction my $objectify = sub { my ($transfer, $field, $class, @find_by) = @_; @@ -74,10 +73,9 @@ sub transfer { return; }; - $db->begin_work; - eval { - - for my $transfer (@args) { + my $db = SL::DB::Inventory->new->db; + $db->do_transaction(sub{ + while (my $transfer = shift @args) { my ($trans_id) = selectrow_query($::form, $::form->get_standard_dbh, qq|SELECT nextval('id')|); my $part = $objectify->($transfer, 'parts', 'SL::DB::Part'); @@ -133,13 +131,8 @@ sub transfer { )->save; } } - - $db->commit; - - 1; - } or do { - $db->rollback; - die $@; # rethrow + }) or do { + $::form->error("Warehouse transfer error: " . join("\n", (split(/\n/, $db->error))[0..2])); }; $::lxdebug->leave_sub; -- 2.20.1