X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FFile.pm;h=81bc75597e44cd0ed321ca2e417ca9bbfe3013e1;hb=f3324b5ad66924333bf2a313974f6d4d21932707;hp=5efb403bd52619a24b0b36c9a5b0a7bbc9ef6cc3;hpb=cff4d3332201b41a504878734475f7c9328a15be;p=kivitendo-erp.git diff --git a/SL/File.pm b/SL/File.pm index 5efb403bd..81bc75597 100644 --- a/SL/File.pm +++ b/SL/File.pm @@ -4,12 +4,13 @@ use strict; use parent qw(Rose::Object); -use Clone qw(clone); use SL::File::Backend; use SL::File::Object; use SL::DB::History; +use SL::DB::ShopImage; use SL::DB::File; use SL::Helper::UserPreferences; +use SL::Controller::Helper::ThumbnailCreator qw(file_probe_type); use SL::JSON; use constant RENAME_OK => 0; @@ -47,10 +48,11 @@ sub get_all { object_id => $params{object_id}, object_type => $params{object_type} ); - push @query, (file_name => $params{file_name}) if $params{file_name}; - push @query, (file_type => $params{file_type}) if $params{file_type}; - push @query, (mime_type => $params{mime_type}) if $params{mime_type}; - push @query, (source => $params{source}) if $params{source}; + push @query, (file_name => $params{file_name}) if $params{file_name}; + push @query, (file_type => $params{file_type}) if $params{file_type}; + push @query, (mime_type => $params{mime_type}) if $params{mime_type}; + push @query, (source => $params{source}) if $params{source}; + push @query, (print_variant => $params{print_variant}) if $params{print_variant}; my $sortby = $params{sort_by} || 'itime DESC,file_name ASC'; @@ -61,27 +63,28 @@ sub get_all { sub get_all_versions { my ($self, %params) = @_; my @versionobjs; - my @fileobjs = $self->get_all(%params); + my @fileobjs; if ( $params{dbfile} ) { - push @fileobjs, SL::File::Object->new(dbfile => $params{db_file}, id => $params{dbfile}->id, loaded => 1); + push @fileobjs, SL::File::Object->new(db_file => $params{dbfile}, id => $params{dbfile}->id, loaded => 1); } else { @fileobjs = $self->get_all(%params); } foreach my $fileobj (@fileobjs) { $main::lxdebug->message(LXDebug->DEBUG2(), "obj=" . $fileobj . " id=" . $fileobj->id." versions=".$fileobj->version_count); my $maxversion = $fileobj->version_count; + $fileobj->version($maxversion); push @versionobjs, $fileobj; if ($maxversion > 1) { for my $version (2..$maxversion) { $main::lxdebug->message(LXDebug->DEBUG2(), "clone for version=".($maxversion-$version+1)); eval { - my $clone = clone($fileobj); + my $clone = $fileobj->clone; $clone->version($maxversion-$version+1); $clone->newest(0); $main::lxdebug->message(LXDebug->DEBUG2(), "clone version=".$clone->version." mtime=". $clone->mtime); push @versionobjs, $clone; 1; - } + } or do {$::lxdebug->message(LXDebug::WARN(), "clone for version=".($maxversion-$version+1) . "failed: " . $@)}; } } } @@ -96,10 +99,11 @@ sub get_all_count { object_id => $params{object_id}, object_type => $params{object_type} ); - push @query, (file_name => $params{file_name}) if $params{file_name}; - push @query, (file_type => $params{file_type}) if $params{file_type}; - push @query, (mime_type => $params{mime_type}) if $params{mime_type}; - push @query, (source => $params{source}) if $params{source}; + push @query, (file_name => $params{file_name}) if $params{file_name}; + push @query, (file_type => $params{file_type}) if $params{file_type}; + push @query, (mime_type => $params{mime_type}) if $params{mime_type}; + push @query, (source => $params{source}) if $params{source}; + push @query, (print_variant => $params{print_variant}) if $params{print_variant}; my $cnt = SL::DB::Manager::File->get_all_count(query => [@query]); return $cnt; @@ -160,8 +164,8 @@ sub _delete { } if ($backend->delete(%params)) { my $do_delete = 0; - if ( $params{last} || $params{all_but_notlast} ) { - if ( $backend->get_version_count > 0 ) { + if ( $params{last} || $params{version} || $params{all_but_notlast} ) { + if ( $backend->get_version_count(%params) > 0 ) { $params{dbfile}->mtime(DateTime->now_local); $params{dbfile}->save; } else { @@ -216,7 +220,10 @@ sub _save { mime_type => $params{mime_type}, title => $params{title}, description => $params{description}, + print_variant => $params{print_variant}, ); + $file->itime($params{mtime}) if $params{mtime}; + $params{itime} = $params{mtime} if $params{mtime}; } } else { $exists = 1; @@ -233,13 +240,30 @@ sub _save { # load itime for new file $file->save->load; } - $main::lxdebug->message(LXDebug->DEBUG2(), "backend3=" .$file->backend); + + $file->mtime(DateTime->now_local) unless $params{mtime}; + $file->mtime($params{mtime} ) if $params{mtime}; + my $backend = $self->_get_backend($file->backend); $params{dbfile} = $file; $backend->save(%params); - $file->mtime(DateTime->now_local); $file->save; + #ShopImage + if($file->object_type eq "shop_image"){ + my $image_content = $params{file_contents}; + my $thumbnail = file_probe_type($image_content); + my $shopimage = SL::DB::ShopImage->new(); + $shopimage->assign_attributes( + file_id => $file->id, + thumbnail_content => $thumbnail->{thumbnail_img_content}, + org_file_height => $thumbnail->{file_image_height}, + org_file_width => $thumbnail->{file_image_width}, + thumbnail_content_type => $thumbnail->{thumbnail_img_content_type}, + object_id => $file->object_id, + ); + $shopimage->save; + } if ($params{file_type} eq 'document' && $params{source} ne 'created') { SL::DB::History->new( addition => 'IMPORT', @@ -367,7 +391,7 @@ SL::File - The intermediate Layer for handling files object_id => $self->object_id, object_type => $self->object_type, mime_type => 'application/pdf', - file_type => 'documents', + file_type => 'document', file_contents => 'this is no pdf'); my $file1 = SL::File->get(id => $id); @@ -380,7 +404,7 @@ SL::File - The intermediate Layer for handling files SL::File->rename(id => $id,to => $newname); my $files1 = SL::File->get_all(object_id => $object_id, object_type => $object_type, - file_type => 'images', # may be optional + file_type => 'image', # may be optional source => 'uploaded' # may be optional ); @@ -397,13 +421,13 @@ There are three types of files: =over 2 -=item - documents, +=item - document, which can be generated files (for sales), scanned files or uploaded files (for purchase) for an ERP-object. They can exist in different versions. The versioning is handled implicit. All versions of a file may be deleted by the user if she/he is allowed to do this. -=item - attachments, +=item - attachment, which have additional information for an ERP-objects. They are uploadable. If a filename still exists on a ERP-Object the new uploaded file is a new version of this or it must be renamed by user. @@ -412,7 +436,7 @@ There are generic attachments for a specific document group (like sales_invoices combinide/merged with the document-file in the time of printing. Today only PDF-Attachmnets can be merged with the generated document-PDF. -=item - images, +=item - image, they are like attachments, but they may be have thumbnails for displaying. So the must have an image format like png,jpg. The versioning is like attachments @@ -505,7 +529,7 @@ The Type of the ERP-object like "sales_quotation" for a new file. A clear mappin =item C -The type may be "documents", "attachments" or "images" for a new file. +The type may be "document", "attachment" or "image" for a new file. =item C @@ -610,7 +634,7 @@ The Type of the ERP-object like "sales_quotation". A clear mapping to the class/ =item C -The type may be "documents", "attachments" or "images". This parameter is optional. +The type may be "document", "attachment" or "image". This parameter is optional. =item C