Revision 94ad4ae0
Von Moritz Bunkus vor fast 10 Jahren hinzugefügt
SL/Helper/CreatePDF.pm | ||
---|---|---|
6 | 6 |
use Cwd; |
7 | 7 |
use English qw(-no_match_vars); |
8 | 8 |
use File::Slurp (); |
9 |
use File::Spec (); |
|
9 | 10 |
use File::Temp (); |
10 | 11 |
use List::MoreUtils qw(uniq); |
11 | 12 |
use List::Util qw(first); |
... | ... | |
47 | 48 |
$form->{templates} = $::instance_conf->get_templates; |
48 | 49 |
$form->{IN} = $params{template}; |
49 | 50 |
$form->{tmpdir} = $form->{cwd} . '/' . $userspath; |
51 |
my $tmpdir = $form->{tmpdir}; |
|
50 | 52 |
my ($suffix) = $params{template} =~ m{\.(.+)}; |
51 | 53 |
|
52 | 54 |
my ($temp_fh, $tmpfile) = File::Temp::tempfile( |
53 | 55 |
'kivitendo-printXXXXXX', |
54 | 56 |
SUFFIX => ".${suffix}", |
55 |
DIR => $userspath,
|
|
57 |
DIR => $form->{tmpdir},
|
|
56 | 58 |
UNLINK => ($::lx_office_conf{debug} && $::lx_office_conf{debug}->{keep_temp_files})? 0 : 1, |
57 | 59 |
); |
58 | 60 |
|
... | ... | |
63 | 65 |
source => $form->{IN}, |
64 | 66 |
form => $form, |
65 | 67 |
myconfig => \%::myconfig, |
66 |
userspath => $userspath,
|
|
68 |
userspath => $tmpdir,
|
|
67 | 69 |
); |
68 | 70 |
|
69 | 71 |
my $result = $parser->parse($temp_fh); |
... | ... | |
76 | 78 |
die $parser->get_error; |
77 | 79 |
} |
78 | 80 |
|
81 |
# SL::Template:** modify $form->{tmpfile} by removing its |
|
82 |
# $form->{userspath} prefix. They also store the final file's actual |
|
83 |
# file name in $form->{tmpfile} – but it is now relative to |
|
84 |
# $form->{userspath}. Other modules return the full file name… |
|
85 |
my ($volume, $directory, $file_name) = File::Spec->splitpath($form->{tmpfile}); |
|
86 |
my $full_file_name = File::Spec->catfile($tmpdir, $file_name); |
|
79 | 87 |
if (($params{return} || 'content') eq 'file_name') { |
80 |
my $new_name = $userspath . '/keep-' . $tmpfile;
|
|
81 |
rename $tmpfile, $new_name;
|
|
88 |
my $new_name = File::Spec->catfile($tmpdir, 'keep-' . $form->{tmpfile});
|
|
89 |
rename $full_file_name, $new_name;
|
|
82 | 90 |
|
83 | 91 |
$form->cleanup; |
84 | 92 |
|
85 | 93 |
return $new_name; |
86 | 94 |
} |
87 | 95 |
|
88 |
my $content = File::Slurp::read_file($tmpfile);
|
|
96 |
my $content = File::Slurp::read_file($full_file_name);
|
|
89 | 97 |
|
90 | 98 |
$form->cleanup; |
91 | 99 |
|
Auch abrufbar als: Unified diff
CreatePDF-Helfer: Dateinamen fixen
Die Vorlagen-Parser-Module SL::Template::* erwarten, dass
$form->{tmpdir} den zu parsenden Dateinamen enthält. Sie entfernen dann
das Präfix $self->{userspath} von $form->{tmpdir}, wodurch nur noch der
Dateiname bleibt.
Der Name der finalen Ausgabedatei wird ebenfalls über $form->{tmpdir}
zurückgegeben – ohne jegliche Pfadangabe. Allerdings ist das von Modul
zu Modul unterschiedlich. Manche geben den vollen Namen, manche nur den
Dateinamen (der dann relativ zu $self->{userspath} ist) zurück.