From: Bernd Bleßmann Date: Mon, 8 Mar 2021 12:22:55 +0000 (+0100) Subject: Auftrags-Controller: auch bei E-Mail erzeugtes Dokument im WebDAV/DMS speichern X-Git-Tag: kivitendo-mebil_0.1-0~9^2~459 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=5c0d66f1bac1c81ba16077a27f17508bc8bf2375;p=kivitendo-erp.git Auftrags-Controller: auch bei E-Mail erzeugtes Dokument im WebDAV/DMS speichern --- diff --git a/SL/Controller/Order.pm b/SL/Controller/Order.pm index 8d2e972c1..ea92d4be9 100644 --- a/SL/Controller/Order.pm +++ b/SL/Controller/Order.pm @@ -316,36 +316,9 @@ sub action_print { $self->js->flash('info', t8('The PDF has been printed')); } - # copy file to webdav folder - if ($self->order->number && $::instance_conf->get_webdav_documents) { - my $webdav = SL::Webdav->new( - type => $self->type, - number => $self->order->number, - ); - my $webdav_file = SL::Webdav::File->new( - webdav => $webdav, - filename => $pdf_filename, - ); - eval { - $webdav_file->store(data => \$pdf); - 1; - } or do { - $self->js->flash('error', t8('Storing PDF to webdav folder failed: #1', $@)); - } - } - if ($self->order->number && $::instance_conf->get_doc_storage) { - eval { - SL::File->save(object_id => $self->order->id, - object_type => $self->type, - mime_type => 'application/pdf', - source => 'created', - file_type => 'document', - file_name => $pdf_filename, - file_contents => $pdf); - 1; - } or do { - $self->js->flash('error', t8('Storing PDF in storage backend failed: #1', $@)); - } + my @warnings = store_pdf_to_webdav_and_filemanegement($self->order, $pdf, $pdf_filename); + if (scalar @warnings) { + $self->js->flash('warning', $_) for @warnings; } $self->save_history('PRINTED'); @@ -448,6 +421,11 @@ sub action_send_email { return $self->js->flash('error', t8('Conversion to PDF failed: #1', $errors[0]))->render($self); } + my @warnings = store_pdf_to_webdav_and_filemanegement($self->order, $pdf, $::form->{attachment_filename}); + if (scalar @warnings) { + flash_later('warning', $_) for @warnings; + } + my $sfile = SL::SessionFile::Random->new(mode => "w"); $sfile->fh->print($pdf); $sfile->fh->close; @@ -2140,6 +2118,46 @@ sub save_history { )->save; } +sub store_pdf_to_webdav_and_filemanegement { + my($order, $content, $filename) = @_; + + my @errors; + + # copy file to webdav folder + if ($order->number && $::instance_conf->get_webdav_documents) { + my $webdav = SL::Webdav->new( + type => $order->type, + number => $order->number, + ); + my $webdav_file = SL::Webdav::File->new( + webdav => $webdav, + filename => $filename, + ); + eval { + $webdav_file->store(data => \$content); + 1; + } or do { + push @errors, t8('Storing PDF to webdav folder failed: #1', $@); + }; + } + if ($order->id && $::instance_conf->get_doc_storage) { + eval { + SL::File->save(object_id => $order->id, + object_type => $order->type, + mime_type => 'application/pdf', + source => 'created', + file_type => 'document', + file_name => $filename, + file_contents => $content); + 1; + } or do { + push @errors, t8('Storing PDF in storage backend failed: #1', $@); + }; + } + + return @errors; +} + 1; __END__