Rose-Beziehungstypen gefixt
[kivitendo-erp.git] / SL / DB / Object.pm
index 4e6e15c..d176a1f 100755 (executable)
@@ -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);
 
@@ -110,24 +111,46 @@ sub load {
 
 sub save {
   my ($self, @args) = @_;
-  my $worker        = sub {
+
+  my ($result, $exception);
+  my $worker = sub {
     SL::DB::Object::Hooks::run_hooks($self, 'before_save');
-    my $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);
+
+    return $result;
   };
 
-  return $self->db->in_transaction ? $worker->() : $self->db->do_transaction($worker);
+  $self->db->in_transaction ? $worker->() : $self->db->do_transaction($worker);
+
+  die $exception if $exception;
+
+  return $result;
 }
 
 sub delete {
   my ($self, @args) = @_;
-  my $worker        = sub {
+
+  my ($result, $exception);
+  my $worker = sub {
     SL::DB::Object::Hooks::run_hooks($self, 'before_delete');
-    my $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);
+
+    return $result;
   };
 
-  return $self->db->in_transaction ? $worker->() : $self->db->do_transaction($worker);
+  $self->db->in_transaction ? $worker->() : $self->db->do_transaction($worker);
+
+  die $exception if $exception;
+
+  return $result;
 }
 
 1;