use SL::Helper::CreatePDF qw();
use SL::Helper::Flash;
use SL::Locale::String;
+use SL::System::Process;
use SL::Template::LaTeX;
use Rose::Object::MakeMethods::Generic
sub action_create_pdf {
my ($self, %params) = @_;
+ my $keep_temp_files = $::lx_office_conf{debug} && $::lx_office_conf{debug}->{keep_temp_files};
+ my $temp_dir = File::Temp->newdir(
+ "kivitendo-print-XXXXXX",
+ DIR => SL::System::Process::exe_dir() . "/" . $::lx_office_conf{paths}->{userspath},
+ CLEANUP => !$keep_temp_files,
+ );
+
my $base_name = $self->requirement_spec->type->template_file_name || 'requirement_spec';
- my @pictures = $self->prepare_pictures_for_printing;
- my %result = SL::Template::LaTeX->parse_and_create_pdf("${base_name}.tex", SELF => $self, rspec => $self->requirement_spec);
+ my @pictures = $self->prepare_pictures_for_printing($temp_dir->dirname);
+ my %result = SL::Template::LaTeX->parse_and_create_pdf("${base_name}.tex", SELF => $self, rspec => $self->requirement_spec, userspath => $temp_dir->dirname);
unlink @pictures unless ($::lx_office_conf{debug} || {})->{keep_temp_files};
}
sub prepare_pictures_for_printing {
- my ($self) = @_;
+ my ($self, $userspath) = @_;
my @files;
- my $userspath = File::Spec->rel2abs($::lx_office_conf{paths}->{userspath});
- my $target = "${userspath}/kivitendo-print-requirement-spec-picture-" . Common::unique_id() . '-';
+ $userspath ||= SL::System::Process::exe_dir() . "/" . $::lx_office_conf{paths}->{userspath};
+ my $target = "${userspath}/kivitendo-print-requirement-spec-picture-" . Common::unique_id() . '-';
foreach my $picture (map { @{ $_->pictures } } @{ $self->requirement_spec->text_blocks }) {
my $output_file_name = $target . $picture->id . '.' . $picture->get_default_file_name_extension;
use Cwd;
use Encode;
use File::Copy;
+use File::Temp ();
use IO::File;
use Math::BigInt;
use POSIX qw(strftime);
local (*IN, *OUT);
- my $defaults = SL::DB::Default->get;
- my $userspath = $::lx_office_conf{paths}->{userspath};
+ my $defaults = SL::DB::Default->get;
- $self->{"cwd"} = getcwd();
- $self->{"tmpdir"} = $self->{cwd} . "/${userspath}";
+ my $keep_temp_files = $::lx_office_conf{debug} && $::lx_office_conf{debug}->{keep_temp_files};
+ $self->{cwd} = getcwd();
+ my $temp_dir = File::Temp->newdir(
+ "kivitendo-print-XXXXXX",
+ DIR => $self->{cwd} . "/" . $::lx_office_conf{paths}->{userspath},
+ CLEANUP => !$keep_temp_files,
+ );
+
+ my $userspath = File::Spec->abs2rel($temp_dir->dirname);
+ $self->{tmpdir} = $temp_dir->dirname;
my $ext_for_format;
# OUT is used for the media, screen, printer, email
# for postscript we store a copy in a temporary file
- my $keep_temp_files = $::lx_office_conf{debug} && $::lx_office_conf{debug}->{keep_temp_files};
my ($temp_fh, $suffix);
$suffix = $self->{IN};
use SL::DB::Language;
use SL::DB::Printer;
use SL::MoreCommon;
+use SL::System::Process;
use SL::Template;
use SL::Template::LaTeX;
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{\.(.+)};
'kivitendo-printXXXXXX',
SUFFIX => ".${suffix}",
DIR => $form->{tmpdir},
- UNLINK => ($::lx_office_conf{debug} && $::lx_office_conf{debug}->{keep_temp_files})? 0 : 1,
+ UNLINK => !$keep_temp_files,
);
$form->{tmpfile} = $tmpfile;
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;
my $exe_dir = SL::System::Process::exe_dir();
$templates_path = $exe_dir . '/' . $templates_path unless $templates_path =~ m{^/};
- return join(':', grep({ $_ } ('.', $exe_dir . '/texmf', $templates_path, $ENV{TEXINPUTS})), '');
+ return join(':', grep({ $_ } ('.', $exe_dir . '/texmf', $exe_dir . '/users', $templates_path, $ENV{TEXINPUTS})), '');
}
sub convert_to_postscript {
sub parse_and_create_pdf {
my ($class, $template_file_name, %params) = @_;
+ my $userspath = delete($params{userspath}) || $::lx_office_conf{paths}->{userspath};
my $keep_temp = $::lx_office_conf{debug} && $::lx_office_conf{debug}->{keep_temp_files};
my ($tex_fh, $tex_file_name) = File::Temp::tempfile(
'kivitendo-printXXXXXX',
SUFFIX => '.tex',
- DIR => $::lx_office_conf{paths}->{userspath},
+ DIR => $userspath,
UNLINK => $keep_temp ? 0 : 1,,
);
my $local_form = Form->new('');
$local_form->{cwd} = $old_wd;
$local_form->{IN} = $template_file_name;
- $local_form->{tmpdir} = $::lx_office_conf{paths}->{userspath};
+ $local_form->{tmpdir} = $userspath;
$local_form->{tmpfile} = $tex_file_name;
$local_form->{templates} = SL::DB::Default->get->templates;
my $error;
eval {
- my $template = SL::Template::LaTeX->new(file_name => $template_file_name, form => $local_form);
+ my $template = SL::Template::LaTeX->new(file_name => $template_file_name, form => $local_form, userspath => $userspath);
my $result = $template->parse($tex_fh) && $template->convert_to_pdf;
die $template->{error} unless $result;