Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision f8138d17

Von Moritz Bunkus vor mehr als 15 Jahren hinzugefügt

  • ID f8138d1721521673da949aeac440011dfe0a22c8
  • Vorgänger d561122a
  • Nachfolger 58265754

Jeden DATEV-Export in ein eigenes, eindeutig benanntes Verzeichnis schreiben, damit sich DATEV-Exporte nicht gegenseitig überschreiben.

Temporäre Verzeichnisse werden beim nächsten Aufruf gelöscht, sofern sie älter als acht Stunden sind.
Fix für Bug 924.

Unterschiede anzeigen:

SL/DATEV.pm
30 30
use SL::DATEV::KNEFile;
31 31

  
32 32
use Data::Dumper;
33
use File::Path;
34
use Time::HiRes qw(gettimeofday);
35

  
36
sub _get_export_path {
37
  $main::lxdebug->enter_sub();
38

  
39
  my ($a, $b) = gettimeofday();
40
  my $path    = get_path_for_download_token("${a}-${b}-${$}");
41

  
42
  mkpath($path) unless (-d $path);
43

  
44
  $main::lxdebug->leave_sub();
45

  
46
  return $path;
47
}
48

  
49
sub get_path_for_download_token {
50
  $main::lxdebug->enter_sub();
51

  
52
  my $token = shift;
53
  my $path;
54

  
55
  if ($token =~ m|^(\d+)-(\d+)-(\d+)$|) {
56
    $path = "${main::userspath}/datev-export-${1}-${2}-${3}";
57
  }
58

  
59
  $main::lxdebug->leave_sub();
60

  
61
  return $path;
62
}
63

  
64
sub get_download_token_for_path {
65
  $main::lxdebug->enter_sub();
66

  
67
  my $path = shift;
68
  my $token;
69

  
70
  if ($path =~ m|.*datev-export-(\d+)-(\d+)-(\d+)/?$|) {
71
    $token = "${1}-${2}-${3}";
72
  }
73

  
74
  $main::lxdebug->leave_sub();
75

  
76
  return $token;
77
}
78

  
79
sub clean_temporary_directories {
80
  $main::lxdebug->enter_sub();
81

  
82
  foreach my $path (glob "${main::userspath}/datev-export-*") {
83
    next unless (-d $path);
84

  
85
    my $mtime = (stat($path))[9];
86
    next if ((time() - $mtime) < 8 * 60 * 60);
87

  
88
    rmtree $path;
89
  }
90

  
91
  $main::lxdebug->leave_sub();
92
}
33 93

  
34 94
sub _fill {
35 95
  $main::lxdebug->enter_sub();
......
109 169
  $main::lxdebug->enter_sub();
110 170

  
111 171
  my ($self, $myconfig, $form) = @_;
112
  my @rc;
172
  my $result;
113 173

  
114 174
  if ($form->{exporttype} == 0) {
115
    @rc = &kne_buchungsexport($myconfig, $form);
175
    $result = kne_buchungsexport($myconfig, $form);
116 176
  } else {
117
    @rc = &kne_stammdatenexport($myconfig, $form);
177
    $result = kne_stammdatenexport($myconfig, $form);
118 178
  }
119 179

  
120 180
  $main::lxdebug->leave_sub();
121 181

  
122
  return @rc;
182
  return $result;
123 183
}
124 184

  
125 185
sub obe_export {
......
560 620

  
561 621
  my @filenames;
562 622

  
563
  my $export_path = $main::userspath . "/";
623
  my $export_path = _get_export_path() . "/";
564 624
  my $filename    = "ED00000";
565 625
  my $evfile      = "EV01";
566 626
  my @ed_versionsets;
......
724 784
  ###
725 785
  $main::lxdebug->leave_sub();
726 786

  
727
  return @filenames;
787
  return { 'download_token' => get_download_token_for_path($export_path), 'filenames' => \@filenames };
728 788
}
729 789

  
730 790
sub kne_stammdatenexport {
......
741 801

  
742 802
  my @filenames;
743 803

  
744
  my $export_path = $main::userspath . "/";
804
  my $export_path = _get_export_path() . "/";
745 805
  my $filename    = "ED00000";
746 806
  my $evfile      = "EV01";
747 807
  my @ed_versionsets;
......
839 899

  
840 900
  $main::lxdebug->leave_sub();
841 901

  
842
  return @filenames;
902
  return { 'download_token' => get_download_token_for_path($export_path), 'filenames' => \@filenames };
843 903
}
844 904

  
845 905
1;
bin/mozilla/datev.pl
331 331

  
332 332
  $auth->assert('datev_export');
333 333

  
334
  DATEV::clean_temporary_directories();
335

  
334 336
  DATEV->save_datev_stamm(\%myconfig, \%$form);
335 337

  
336
  my $link = "datev.pl?action=download";
338
  my $link = "datev.pl?action=download&download_token=";
337 339

  
338 340
  if ($form->{kne}) {
339
    my @filenames = DATEV->kne_export(\%myconfig, \%$form);
340
    if (@filenames) {
341
      print(qq|<br><b>| . $locale->text('KNE-Export erfolgreich!') . qq|</b><br>|);
342
      $link .= "&filenames=" . $form->escape(join(":", @filenames));
343
      print(qq|<br><a href="$link">Download</a>|);
341
    my $result = DATEV->kne_export(\%myconfig, \%$form);
342
    if ($result && @{ $result->{filenames} }) {
343
      $link .= Q($result->{download_token});
344

  
345
      print(qq|<br><b>| . $locale->text('KNE-Export erfolgreich!') . qq|</b><br><br><a href="$link">Download</a>|);
346

  
344 347
    } else {
345 348
      $form->error("KNE-Export schlug fehl.");
346 349
    }
347 350
  } else {
348
    my @filenames = DATEV->obe_export(\%myconfig, \%$form);
349
    if (@filenames) {
350
      print(qq|<br><b>| . $locale->text('OBE-Export erfolgreich!') . qq|</b><br>|);
351
      $link .= "&filenames=" . $form->escape(join(":", @filenames));
352
      print(qq|<br><a href="$link">Download</a>|);
353
    } else {
354
      $form->error("OBE-Export schlug fehl.");
355
    }
351
    # OBE-Export nicht implementiert.
352

  
353
    # my @filenames = DATEV->obe_export(\%myconfig, \%$form);
354
    # if (@filenames) {
355
    #   print(qq|<br><b>| . $locale->text('OBE-Export erfolgreich!') . qq|</b><br>|);
356
    #   $link .= "&filenames=" . $form->escape(join(":", @filenames));
357
    #   print(qq|<br><a href="$link">Download</a>|);
358
    # } else {
359
    #   $form->error("OBE-Export schlug fehl.");
360
    # }
356 361
  }
357 362

  
358 363
  print("</body></html>");
......
366 371
  $auth->assert('datev_export');
367 372

  
368 373
  my $tmp_name = Common->tmpname();
369
  my $zip_name = strftime("lx-office-datev-export-%Y%m%d.zip",
370
                          localtime(time()));
374
  my $zip_name = strftime("lx-office-datev-export-%Y%m%d.zip", localtime(time()));
371 375

  
372 376
  my $cwd = getcwd();
373
  chdir("users") || die("chdir users");
374 377

  
375
  my @filenames = split(/:/, $form->{"filenames"});
376
  map({ s|.*/||; $form->error("Eine der KNE-Exportdateien wurde nicht " .
377
                              "gefunden. Wurde der Export bereits " .
378
                              "durchgef&uuml;hrt?") unless (-f $_); }
379
      @filenames);
378
  my $path = DATEV::get_path_for_download_token($form->{download_token});
379
  if (!$path) {
380
    $form->error($locale->text("Your download does not exist anymore. Please re-run the DATEV export assistant."));
381
  }
382

  
383
  chdir($path) || die("chdir $path");
384

  
385
  my @filenames = glob "*";
386

  
387
  if (!@filenames) {
388
    chdir($cwd);
389
    DATEV::clean_temporary_directories();
390
    $form->error($locale->text("Your download does not exist anymore. Please re-run the DATEV export assistant."));
391
  }
380 392

  
381 393
  my $zip = Archive::Zip->new();
382
  map({ $zip->addFile($_); } @filenames);
394
  map { $zip->addFile($_); } @filenames;
383 395
  $zip->writeToFileNamed($tmp_name);
396

  
384 397
  chdir($cwd);
385 398

  
386 399
  open(IN, $tmp_name) || die("open $tmp_name");
......
393 406

  
394 407
  unlink($tmp_name);
395 408

  
409
  DATEV::clean_temporary_directories();
410

  
396 411
  $lxdebug->leave_sub();
397 412
}

Auch abrufbar als: Unified diff