Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision dc8ffeaa

Von Moritz Bunkus vor fast 5 Jahren hinzugefügt

  • ID dc8ffeaa1211987d6b3e0a3f1d2c576c82584d37
  • Vorgänger 80eceeda
  • Nachfolger 5ad4d6d7

PDF-Erzeugung: alles in temporärem Unterverzeichnis von users erledigen

Das vermeidet Kollisionen, wenn Dateien mit festem Namen wie
`pdfa.xmp` für PDF/A erzeugt werden müssen.

Unterschiede anzeigen:

SL/Controller/RequirementSpec.pm
23 23
use SL::Helper::CreatePDF qw();
24 24
use SL::Helper::Flash;
25 25
use SL::Locale::String;
26
use SL::System::Process;
26 27
use SL::Template::LaTeX;
27 28

  
28 29
use Rose::Object::MakeMethods::Generic
......
217 218
sub action_create_pdf {
218 219
  my ($self, %params) = @_;
219 220

  
221
  my $keep_temp_files = $::lx_office_conf{debug} && $::lx_office_conf{debug}->{keep_temp_files};
222
  my $temp_dir        = File::Temp->newdir(
223
    "kivitendo-print-XXXXXX",
224
    DIR     => SL::System::Process::exe_dir() . "/" . $::lx_office_conf{paths}->{userspath},
225
    CLEANUP => !$keep_temp_files,
226
  );
227

  
220 228
  my $base_name       = $self->requirement_spec->type->template_file_name || 'requirement_spec';
221
  my @pictures        = $self->prepare_pictures_for_printing;
222
  my %result          = SL::Template::LaTeX->parse_and_create_pdf("${base_name}.tex", SELF => $self, rspec => $self->requirement_spec);
229
  my @pictures        = $self->prepare_pictures_for_printing($temp_dir->dirname);
230
  my %result          = SL::Template::LaTeX->parse_and_create_pdf("${base_name}.tex", SELF => $self, rspec => $self->requirement_spec, userspath => $temp_dir->dirname);
223 231

  
224 232
  unlink @pictures unless ($::lx_office_conf{debug} || {})->{keep_temp_files};
225 233

  
......
599 607
}
600 608

  
601 609
sub prepare_pictures_for_printing {
602
  my ($self) = @_;
610
  my ($self, $userspath) = @_;
603 611

  
604 612
  my @files;
605
  my $userspath = File::Spec->rel2abs($::lx_office_conf{paths}->{userspath});
606
  my $target    =  "${userspath}/kivitendo-print-requirement-spec-picture-" . Common::unique_id() . '-';
613
  $userspath ||= SL::System::Process::exe_dir() . "/" . $::lx_office_conf{paths}->{userspath};
614
  my $target   = "${userspath}/kivitendo-print-requirement-spec-picture-" . Common::unique_id() . '-';
607 615

  
608 616
  foreach my $picture (map { @{ $_->pictures } } @{ $self->requirement_spec->text_blocks }) {
609 617
    my $output_file_name        = $target . $picture->id . '.' . $picture->get_default_file_name_extension;
SL/Form.pm
47 47
use Cwd;
48 48
use Encode;
49 49
use File::Copy;
50
use File::Temp ();
50 51
use IO::File;
51 52
use Math::BigInt;
52 53
use POSIX qw(strftime);
......
909 910

  
910 911
  local (*IN, *OUT);
911 912

  
912
  my $defaults  = SL::DB::Default->get;
913
  my $userspath = $::lx_office_conf{paths}->{userspath};
913
  my $defaults        = SL::DB::Default->get;
914 914

  
915
  $self->{"cwd"} = getcwd();
916
  $self->{"tmpdir"} = $self->{cwd} . "/${userspath}";
915
  my $keep_temp_files = $::lx_office_conf{debug} && $::lx_office_conf{debug}->{keep_temp_files};
916
  $self->{cwd}        = getcwd();
917
  my $temp_dir        = File::Temp->newdir(
918
    "kivitendo-print-XXXXXX",
919
    DIR     => $self->{cwd} . "/" . $::lx_office_conf{paths}->{userspath},
920
    CLEANUP => !$keep_temp_files,
921
  );
922

  
923
  my $userspath   = File::Spec->abs2rel($temp_dir->dirname);
924
  $self->{tmpdir} = $temp_dir->dirname;
917 925

  
918 926
  my $ext_for_format;
919 927

  
......
973 981

  
974 982
  # OUT is used for the media, screen, printer, email
975 983
  # for postscript we store a copy in a temporary file
976
  my $keep_temp_files = $::lx_office_conf{debug} && $::lx_office_conf{debug}->{keep_temp_files};
977 984

  
978 985
  my ($temp_fh, $suffix);
979 986
  $suffix =  $self->{IN};
SL/Helper/CreatePDF.pm
17 17
use SL::DB::Language;
18 18
use SL::DB::Printer;
19 19
use SL::MoreCommon;
20
use SL::System::Process;
20 21
use SL::Template;
21 22
use SL::Template::LaTeX;
22 23

  
......
39 40
sub create_parsed_file {
40 41
  my ($class, %params) = @_;
41 42

  
42
  my $userspath      = $::lx_office_conf{paths}->{userspath};
43
  my $keep_temp_files = $::lx_office_conf{debug} && $::lx_office_conf{debug}->{keep_temp_files};
44
  my $userspath       = SL::System::Process::exe_dir() . "/" . $::lx_office_conf{paths}->{userspath};
45
  my $temp_dir        = File::Temp->newdir(
46
    "kivitendo-print-XXXXXX",
47
    DIR     => $userspath,
48
    CLEANUP => !$keep_temp_files,
49
  );
50

  
43 51
  my $vars           = $params{variables} || {};
44 52
  my $form           = Form->new('');
45 53
  $form->{$_}        = $vars->{$_} for keys %{$vars};
46 54
  $form->{format}    = lc($params{format} || 'pdf');
47
  $form->{cwd}       = getcwd();
55
  $form->{cwd}       = SL::System::Process::exe_dir();
48 56
  $form->{templates} = $::instance_conf->get_templates;
49 57
  $form->{IN}        = $params{template};
50
  $form->{tmpdir}    = $form->{cwd} . '/' . $userspath;
58
  $form->{tmpdir}    = $temp_dir->dirname;
51 59
  my $tmpdir         = $form->{tmpdir};
52 60
  my ($suffix)       = $params{template} =~ m{\.(.+)};
53 61

  
......
55 63
    'kivitendo-printXXXXXX',
56 64
    SUFFIX => ".${suffix}",
57 65
    DIR    => $form->{tmpdir},
58
    UNLINK => ($::lx_office_conf{debug} && $::lx_office_conf{debug}->{keep_temp_files})? 0 : 1,
66
    UNLINK => !$keep_temp_files,
59 67
  );
60 68

  
61 69
  $form->{tmpfile} = $tmpfile;
......
87 95
  my ($volume, $directory, $file_name) = File::Spec->splitpath($form->{tmpfile});
88 96
  my $full_file_name                   = File::Spec->catfile($tmpdir, $file_name);
89 97
  if (($params{return} || 'content') eq 'file_name') {
90
    my $new_name = File::Spec->catfile($tmpdir, 'keep-' . $form->{tmpfile});
98
    my $new_name = File::Spec->catfile($userspath, 'keep-' . $form->{tmpfile});
91 99
    rename $full_file_name, $new_name;
92 100

  
93 101
    $form->cleanup;
SL/Template/LaTeX.pm
530 530
  my $exe_dir     = SL::System::Process::exe_dir();
531 531
  $templates_path = $exe_dir . '/' . $templates_path unless $templates_path =~ m{^/};
532 532

  
533
  return join(':', grep({ $_ } ('.', $exe_dir . '/texmf', $templates_path, $ENV{TEXINPUTS})), '');
533
  return join(':', grep({ $_ } ('.', $exe_dir . '/texmf', $exe_dir . '/users', $templates_path, $ENV{TEXINPUTS})), '');
534 534
}
535 535

  
536 536
sub convert_to_postscript {
......
652 652
sub parse_and_create_pdf {
653 653
  my ($class, $template_file_name, %params) = @_;
654 654

  
655
  my $userspath                = delete($params{userspath}) || $::lx_office_conf{paths}->{userspath};
655 656
  my $keep_temp                = $::lx_office_conf{debug} && $::lx_office_conf{debug}->{keep_temp_files};
656 657
  my ($tex_fh, $tex_file_name) = File::Temp::tempfile(
657 658
    'kivitendo-printXXXXXX',
658 659
    SUFFIX => '.tex',
659
    DIR    => $::lx_office_conf{paths}->{userspath},
660
    DIR    => $userspath,
660 661
    UNLINK => $keep_temp ? 0 : 1,,
661 662
  );
662 663

  
......
665 666
  my $local_form           = Form->new('');
666 667
  $local_form->{cwd}       = $old_wd;
667 668
  $local_form->{IN}        = $template_file_name;
668
  $local_form->{tmpdir}    = $::lx_office_conf{paths}->{userspath};
669
  $local_form->{tmpdir}    = $userspath;
669 670
  $local_form->{tmpfile}   = $tex_file_name;
670 671
  $local_form->{templates} = SL::DB::Default->get->templates;
671 672

  
......
676 677

  
677 678
  my $error;
678 679
  eval {
679
    my $template = SL::Template::LaTeX->new(file_name => $template_file_name, form => $local_form);
680
    my $template = SL::Template::LaTeX->new(file_name => $template_file_name, form => $local_form, userspath => $userspath);
680 681
    my $result   = $template->parse($tex_fh) && $template->convert_to_pdf;
681 682

  
682 683
    die $template->{error} unless $result;

Auch abrufbar als: Unified diff