X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/kivitendo-erp.git/blobdiff_plain/a051b91b24b34b5586761b237b5eda38e8c83f92..c4409bf66a835166b3a50c0de9c5bdedbb5b5c69:/SL/File/Backend/Filesystem.pm diff --git a/SL/File/Backend/Filesystem.pm b/SL/File/Backend/Filesystem.pm index fe8604c0b..70d956e0a 100644 --- a/SL/File/Backend/Filesystem.pm +++ b/SL/File/Backend/Filesystem.pm @@ -78,9 +78,11 @@ sub get_mtime { my ($self, %params) = @_; die "no dbfile" unless $params{dbfile}; die "unknown version" if $params{version} && - ($params{version} < 0 || $params{version} > $params{dbfile}->backend_data) ; - my $path = $self->_filesystem_path($params{dbfile},$params{version}); - die "no file found in backend get_mtime" if !-f $path; + ($params{version} < 0 || $params{version} > $params{dbfile}->backend_data); + my $path = $self->_filesystem_path($params{dbfile}, $params{version}); + + die "No file found at $path. Expected: $params{dbfile}{file_name}, file.id: $params{dbfile}{id}" if !-f $path; + my @st = stat($path); my $dt = DateTime->from_epoch(epoch => $st[9])->clone(); return $dt; @@ -109,6 +111,34 @@ sub enabled { return 1; } +sub sync_from_backend { + my ($self, %params) = @_; + my @query = (file_type => $params{file_type}); + push @query, (file_name => $params{file_name}) if $params{file_name}; + push @query, (mime_type => $params{mime_type}) if $params{mime_type}; + push @query, (source => $params{source}) if $params{source}; + + my $sortby = $params{sort_by} || 'itime DESC,file_name ASC'; + + my @files = @{ SL::DB::Manager::File->get_all(query => [@query], sort_by => $sortby) }; + for (@files) { + $main::lxdebug->message(LXDebug->DEBUG2(), "file id=" . $_->id." version=".$_->backend_data); + my $newversion = $_->backend_data; + for my $version ( reverse 1 .. $_->backend_data ) { + my $path = $self->_filesystem_path($_, $version); + $main::lxdebug->message(LXDebug->DEBUG2(), "path=".$path." exists=".( -f $path?1:0)); + last if -f $path; + $newversion = $version - 1; + } + $main::lxdebug->message(LXDebug->DEBUG2(), "newversion=".$newversion." version=".$_->backend_data); + if ( $newversion < $_->backend_data ) { + $_->backend_data($newversion); + $_->save if $newversion > 0; + $_->delete if $newversion <= 0; + } + } + +} # # internals