X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FFile.pm;h=8675b1870da9e81f453e9bd83f711adb4cb46599;hb=8e51379e94d291d21add91bdbfbfe925433ea6c0;hp=231e0622f8d184aff6c773c885921eeee795a86a;hpb=2bb452ee62e74c2a42113171eeb53de8d09bbbf5;p=kivitendo-erp.git diff --git a/SL/File.pm b/SL/File.pm index 231e0622f..8675b1870 100644 --- a/SL/File.pm +++ b/SL/File.pm @@ -123,11 +123,11 @@ sub delete_all { sub delete { my ($self, %params) = @_; die "no id or dbfile" unless $params{id} || $params{dbfile}; - my $rc = SL::DB->client->with_transaction(\&_delete, $self, %params); - if (!$rc) { - my $err = SL::DB->client->error; - die (ref $err?$$err:$err); - } + my $rc = 0; + eval { + $rc = SL::DB->client->with_transaction(\&_delete, $self, %params); + 1; + } or do { die $@ }; return $rc; } @@ -149,7 +149,7 @@ sub _delete { if ($hist) { if (!$main::auth->assert('import_ar | import_ap', 1)) { - die \'no permission to unimport'; + die 'no permission to unimport'; } my $file = $backend->get_filepath(dbfile => $params{dbfile}); $main::lxdebug->message(LXDebug->DEBUG2(), "del file=" . $file . " to=" . $hist->snumbers); @@ -179,11 +179,11 @@ sub _delete { sub save { my ($self, %params) = @_; - my $obj = SL::DB->client->with_transaction(\&_save, $self, %params); - if (!$obj) { - my $err = SL::DB->client->error; - die (ref $err?$$err:$err); - } + my $obj; + eval { + $obj = SL::DB->client->with_transaction(\&_save, $self, %params); + 1; + } or do { die $@ }; return $obj; } @@ -194,11 +194,11 @@ sub _save { if ($params{id}) { $file = SL::DB::File->new(id => $params{id})->load; - die \'dbfile not exists' unless $file; + die 'dbfile not exists' unless $file; } elsif (!$file) { $main::lxdebug->message(LXDebug->DEBUG2(), "obj_id=" .$params{object_id}); - die \'no object type set' unless $params{object_type}; - die \'no object id set' unless defined($params{object_id}); + die 'no object type set' unless $params{object_type}; + die 'no object id set' unless defined($params{object_id}); $exists = $self->get_all_count(%params); die 'filename still exist' if $exists && $params{fail_if_exists}; @@ -319,13 +319,18 @@ sub _get_backend { my ($self, $backend_name) = @_; my $class = 'SL::File::Backend::' . $backend_name; my $obj = undef; + die $::locale->text('no backend enabled') if $backend_name eq 'None'; eval { eval "require $class"; $obj = $class->new; - die \'backend not enabled' unless $obj->enabled; + die $::locale->text('backend "#1" not enabled',$backend_name) unless $obj->enabled; 1; } or do { - die \'backend class not found'; + if ( $obj ) { + die $@; + } else { + die $::locale->text('backend "#1" not found',$backend_name); + } }; return $obj; } @@ -356,7 +361,7 @@ SL::File - The intermediate Layer for handling files =head1 SYNOPSIS # In a controller or helper ( see SL::Controller::File or SL::Helper::File ) - # you can create, remove, delete etc. a file in a backend independant way + # you can create, remove, delete etc. a file in a backend independent way my $file = SL::File->save( object_id => $self->object_id, @@ -384,7 +389,7 @@ SL::File - The intermediate Layer for handling files =head1 OVERVIEW -The Filemanagemt can handle files in a storage independant way. Internal the File +The Filemanagemt can handle files in a storage independent way. Internal the File use the configured storage backend for the type of file. These backends must be configured in L or an extra database table. @@ -704,4 +709,3 @@ The synchronization is done file_type by file_type. Martin Helmling Emartin.helmling@opendynamic.deE =cut -