X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FDB%2FObject.pm;h=c11fb3f5ae48586b5df75e75f65f557a77787102;hb=064d15bb6c59188be545d75e895689cdfea04ad6;hp=3cf670d55c31d7a29b010082d918c5747af1e748;hpb=4180aaea33e9ff3bb35f3fa6cf91651a6225f7ad;p=kivitendo-erp.git diff --git a/SL/DB/Object.pm b/SL/DB/Object.pm index 3cf670d55..c11fb3f5a 100755 --- a/SL/DB/Object.pm +++ b/SL/DB/Object.pm @@ -14,6 +14,11 @@ use SL::DB::Object::Hooks; use base qw(Rose::DB::Object); +my @rose_reserved_methods = qw( + db dbh delete DESTROY error init_db _init_db insert load meta meta_class + not_found save update import +); + sub new { my $class = shift; my $self = $class->SUPER::new(); @@ -26,7 +31,7 @@ sub new { sub init_db { my $class_or_self = shift; my $class = ref($class_or_self) || $class_or_self; - my $type = $class =~ m/::Auth/ ? 'LXOFFICE_AUTH' : 'LXOFFICE'; + my $type = $class =~ m/::Auth/ ? 'KIVITENDO_AUTH' : 'KIVITENDO'; return SL::DB::create(undef, $type); } @@ -50,6 +55,7 @@ sub assign_attributes { my $pk = ref($self)->meta->primary_key; delete @attributes{$pk->column_names} if $pk; + delete @attributes{@rose_reserved_methods}; return $self->_assign_attributes(%attributes); } @@ -60,9 +66,10 @@ sub _assign_attributes { my %types = map { $_->name => $_->type } ref($self)->meta->columns; - # Special case for *_as_man_days/*_as_man_days_unit: the _unit - # variation must always be called after the non-unit method. - my @man_days_attributes = grep { m/_as_man_days$/ } keys %attributes; + # 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); @@ -133,12 +140,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; }; @@ -155,12 +162,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; };