From: Moritz Bunkus Date: Wed, 2 Nov 2011 15:34:05 +0000 (+0100) Subject: Exceptions beim Speicher/Löschen von SL::DB-Objekten hochbubblen lassen X-Git-Tag: release-2.7.0beta1~157^2~12 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=17e547071d67a5063e3067b1dd72035c0192bacb;p=kivitendo-erp.git Exceptions beim Speicher/Löschen von SL::DB-Objekten hochbubblen lassen Die R::DB::O::transaction()-Funktion clobbert Exceptions irgendwie. Deshalb diese erneut werfen, sofern sie beim Speichern auftreten, und nicht nur einen Fehler zurückliefern. --- diff --git a/SL/DB/Object.pm b/SL/DB/Object.pm index a80640cad..d1e6cb0aa 100755 --- a/SL/DB/Object.pm +++ b/SL/DB/Object.pm @@ -2,6 +2,7 @@ package SL::DB::Object; use strict; +use English qw(-no_match_vars); use Rose::DB::Object; use List::MoreUtils qw(any); @@ -111,28 +112,40 @@ sub load { sub save { my ($self, @args) = @_; - my $result; + my ($result, $exception); my $worker = sub { SL::DB::Object::Hooks::run_hooks($self, 'before_save'); - $result = $self->SUPER::save(@args); + $exception = $EVAL_ERROR unless eval { + $result = $self->SUPER::save(@args); + 1; + }; SL::DB::Object::Hooks::run_hooks($self, 'after_save', $result); }; $self->db->in_transaction ? $worker->() : $self->db->do_transaction($worker); + + die $exception if $exception; + return $result; } sub delete { my ($self, @args) = @_; - my $result; + my ($result, $exception); my $worker = sub { SL::DB::Object::Hooks::run_hooks($self, 'before_delete'); - $result = $self->SUPER::delete(@args); + $exception = $EVAL_ERROR unless eval { + $result = $self->SUPER::delete(@args); + 1; + }; SL::DB::Object::Hooks::run_hooks($self, 'after_delete', $result); }; $self->db->in_transaction ? $worker->() : $self->db->do_transaction($worker); + + die $exception if $exception; + return $result; }