X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/mfinanz.git/blobdiff_plain/b181d7ab6dc3d043be9f27c4209c230c14c90991..52f5223a1dcf:/SL/Helper/CreatePDF.pm?ds=sidebyside diff --git a/SL/Helper/CreatePDF.pm b/SL/Helper/CreatePDF.pm index 8254c9657..6a570fa92 100644 --- a/SL/Helper/CreatePDF.pm +++ b/SL/Helper/CreatePDF.pm @@ -13,11 +13,11 @@ use List::MoreUtils qw(uniq); use List::Util qw(first); use String::ShellQuote (); -use SL::Form; use SL::Common; use SL::DB::Language; use SL::DB::Printer; use SL::MoreCommon; +use SL::System::Process; use SL::Template; use SL::Template::LaTeX; @@ -40,15 +40,22 @@ sub create_pdf { sub create_parsed_file { my ($class, %params) = @_; - my $userspath = $::lx_office_conf{paths}->{userspath}; + my $keep_temp_files = $::lx_office_conf{debug} && $::lx_office_conf{debug}->{keep_temp_files}; + my $userspath = SL::System::Process::exe_dir() . "/" . $::lx_office_conf{paths}->{userspath}; + my $temp_dir = File::Temp->newdir( + "kivitendo-print-XXXXXX", + DIR => $userspath, + CLEANUP => !$keep_temp_files, + ); + my $vars = $params{variables} || {}; my $form = Form->new(''); $form->{$_} = $vars->{$_} for keys %{$vars}; $form->{format} = lc($params{format} || 'pdf'); - $form->{cwd} = getcwd(); + $form->{cwd} = SL::System::Process::exe_dir(); $form->{templates} = $::instance_conf->get_templates; $form->{IN} = $params{template}; - $form->{tmpdir} = $form->{cwd} . '/' . $userspath; + $form->{tmpdir} = $temp_dir->dirname; my $tmpdir = $form->{tmpdir}; my ($suffix) = $params{template} =~ m{\.(.+)}; @@ -56,7 +63,7 @@ sub create_parsed_file { 'kivitendo-printXXXXXX', SUFFIX => ".${suffix}", DIR => $form->{tmpdir}, - UNLINK => $::lx_office_conf{debug} && $::lx_office_conf{debug}->{keep_temp_files}, + UNLINK => !$keep_temp_files, ); $form->{tmpfile} = $tmpfile; @@ -88,7 +95,7 @@ sub create_parsed_file { my ($volume, $directory, $file_name) = File::Spec->splitpath($form->{tmpfile}); my $full_file_name = File::Spec->catfile($tmpdir, $file_name); if (($params{return} || 'content') eq 'file_name') { - my $new_name = File::Spec->catfile($tmpdir, 'keep-' . $form->{tmpfile}); + my $new_name = File::Spec->catfile($userspath, 'keep-' . $form->{tmpfile}); rename $full_file_name, $new_name; $form->cleanup; @@ -145,7 +152,7 @@ sub merge_pdfs { 'kivitendo-printXXXXXX', SUFFIX => '.pdf', DIR => $::lx_office_conf{paths}->{userspath}, - UNLINK => $::lx_office_conf{debug} && $::lx_office_conf{debug}->{keep_temp_files}, + UNLINK => ($::lx_office_conf{debug} && $::lx_office_conf{debug}->{keep_temp_files})? 0 : 1, ); close $temp_fh; @@ -164,7 +171,7 @@ sub merge_pdfs { 'kivitendo-contentXXXXXX', SUFFIX => '.pdf', DIR => $::lx_office_conf{paths}->{userspath}, - UNLINK => $::lx_office_conf{debug} && $::lx_office_conf{debug}->{keep_temp_files}, + UNLINK => ($::lx_office_conf{debug} && $::lx_office_conf{debug}->{keep_temp_files})? 0 : 1, ); binmode $temp_fh; print $temp_fh $params{inp_content};