X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FDB%2FObject.pm;h=8b86e97111a9942d2b0e422a30026d9557f571ff;hb=f964437c368c7ebf2a11e61648ccc66d5a2743d8;hp=fc13652132f2cb6f9a9efb806e6efe868aed62e1;hpb=0b89d2ca35a0e0d9d3add90b1289e27bfc87c83c;p=kivitendo-erp.git diff --git a/SL/DB/Object.pm b/SL/DB/Object.pm index fc1365213..8b86e9711 100755 --- a/SL/DB/Object.pm +++ b/SL/DB/Object.pm @@ -60,6 +60,15 @@ sub _assign_attributes { my %types = map { $_->name => $_->type } ref($self)->meta->columns; + # Special case for *_as_man_days / *_as_man_days_string / + # *_as_man_days_unit: the _unit variation must always be called + # after the non-unit methods. + my @man_days_attributes = grep { m/_as_man_days(?:_string)?$/ } keys %attributes; + foreach my $attribute (@man_days_attributes) { + my $value = delete $attributes{$attribute}; + $self->$attribute(defined($value) && ($value eq '') ? undef : $value); + } + while (my ($attribute, $value) = each %attributes) { my $type = lc($types{$attribute} || 'text'); $value = $type eq 'boolean' ? ($value ? 't' : 'f') @@ -125,12 +134,12 @@ sub save { my ($result, $exception); my $worker = sub { - SL::DB::Object::Hooks::run_hooks($self, 'before_save'); $exception = $EVAL_ERROR unless eval { + SL::DB::Object::Hooks::run_hooks($self, 'before_save'); $result = $self->SUPER::save(@args); + SL::DB::Object::Hooks::run_hooks($self, 'after_save', $result); 1; }; - SL::DB::Object::Hooks::run_hooks($self, 'after_save', $result); return $result; }; @@ -147,12 +156,12 @@ sub delete { my ($result, $exception); my $worker = sub { - SL::DB::Object::Hooks::run_hooks($self, 'before_delete'); $exception = $EVAL_ERROR unless eval { + SL::DB::Object::Hooks::run_hooks($self, 'before_delete'); $result = $self->SUPER::delete(@args); + SL::DB::Object::Hooks::run_hooks($self, 'after_delete', $result); 1; }; - SL::DB::Object::Hooks::run_hooks($self, 'after_delete', $result); return $result; };