]> wagnertech.de Git - mfinanz.git/blobdiff - SL/File/Backend/Webdav.pm
Shopware6: Neue Shopschnittstelle hinzugefügt
[mfinanz.git] / SL / File / Backend / Webdav.pm
index c457080afb02125f9076cb26d53e846b95656cbf..2956e03f9231cc23d568d0f176e6a0d5f64c327a 100644 (file)
@@ -5,12 +5,13 @@ use strict;
 use parent qw(SL::File::Backend);
 use SL::DB::File;
 
 use parent qw(SL::File::Backend);
 use SL::DB::File;
 
-#use SL::Webdav;
+use SL::System::Process;
 use File::Copy;
 use File::Slurp;
 use File::Basename;
 use File::Path qw(make_path);
 use File::MimeInfo::Magic;
 use File::Copy;
 use File::Slurp;
 use File::Basename;
 use File::Path qw(make_path);
 use File::MimeInfo::Magic;
+use File::stat;
 
 #
 # public methods
 
 #
 # public methods
@@ -74,8 +75,7 @@ sub get_mtime {
   $main::lxdebug->message(LXDebug->DEBUG2(), "version=" .$params{version});
   my ($path, undef, undef) = $self->webdav_path($params{dbfile});
   die "No file found in Backend: " . $path unless -f $path;
   $main::lxdebug->message(LXDebug->DEBUG2(), "version=" .$params{version});
   my ($path, undef, undef) = $self->webdav_path($params{dbfile});
   die "No file found in Backend: " . $path unless -f $path;
-  my @st = stat($path);
-  my $dt = DateTime->from_epoch(epoch => $st[9])->clone();
+  my $dt = DateTime->from_epoch(epoch => stat($path)->mtime, time_zone => $::locale->get_local_time_zone()->name)->clone();
   $main::lxdebug->message(LXDebug->DEBUG2(), "dt=" .$dt);
   return $dt;
 }
   $main::lxdebug->message(LXDebug->DEBUG2(), "dt=" .$dt);
   return $dt;
 }
@@ -186,17 +186,18 @@ sub webdav_path {
   }
   $main::lxdebug->message(LXDebug->DEBUG2(), "file_name=" . $dbfile->file_name ." number=".$number);
 
   }
   $main::lxdebug->message(LXDebug->DEBUG2(), "file_name=" . $dbfile->file_name ." number=".$number);
 
+  my @fileparts = split(/_/, $dbfile->file_name);
+  my $number_ext = pop @fileparts;
+  my ($maynumber, $ext) = split(/\./, $number_ext, 2);
+  push @fileparts, $maynumber if $maynumber ne $number;
+
+  my $basename = join('_', @fileparts);
+
   my $path = File::Spec->catdir($self->get_rootdir, "webdav", $::auth->client->{id}, $type, $number);
   if (!-d $path) {
     File::Path::make_path($path, { chmod => 0770 });
   }
   my $path = File::Spec->catdir($self->get_rootdir, "webdav", $::auth->client->{id}, $type, $number);
   if (!-d $path) {
     File::Path::make_path($path, { chmod => 0770 });
   }
-  # simply add the timestring before the last .
-  # fails for .tar.gz but the number extraction algorithm failed for all
-  # '123 Storno zu 456' cases and doubled the name like:
-  # Rechnung_123_Storno_zu_456_202113104 Storno zu 456_20211123_113023
-  # TODO extension should be part of the File Model (filetype)
-  my ($filename, $ext) = split(/\.([^\.]+)$/, $dbfile->file_name);
-  my $fname = $filename . '_' . $dbfile->itime->strftime('%Y%m%d_%H%M%S');
+  my $fname = $basename . '_' . $number . '_' . $dbfile->itime->strftime('%Y%m%d_%H%M%S');
   $fname .= '.' . $ext if $ext;
 
   $main::lxdebug->message(LXDebug->DEBUG2(), "webdav path=" . $path . " filename=" . $fname);
   $fname .= '.' . $ext if $ext;
 
   $main::lxdebug->message(LXDebug->DEBUG2(), "webdav path=" . $path . " filename=" . $fname);
@@ -204,17 +205,7 @@ sub webdav_path {
   return (File::Spec->catfile($path, $fname), $path, $fname);
 }
 
   return (File::Spec->catfile($path, $fname), $path, $fname);
 }
 
-sub get_rootdir {
-  my ($self) = @_;
-
-  #TODO immer noch das alte Problem:
-  #je nachdem von woher der Aufruf kommt ist man in ./users oder .
-  my $rootdir  = POSIX::getcwd();
-  my $basename = basename($rootdir);
-  my $dirname  = dirname($rootdir);
-  $rootdir = $dirname if $basename eq 'users';
-  return $rootdir;
-}
+sub get_rootdir { SL::System::Process::exe_dir() }
 
 sub _get_number_from_model {
   my ($self, $dbfile) = @_;
 
 sub _get_number_from_model {
   my ($self, $dbfile) = @_;
@@ -344,5 +335,3 @@ The synchronization must be tested and a periodical task is needed to synchroniz
 Martin Helmling E<lt>martin.helmling@opendynamic.deE<gt>
 
 =cut
 Martin Helmling E<lt>martin.helmling@opendynamic.deE<gt>
 
 =cut
-
-