diff --git a/app/Http/Controllers/InvoiceController.php b/app/Http/Controllers/InvoiceController.php index bf887607c1..78dab90a5a 100644 --- a/app/Http/Controllers/InvoiceController.php +++ b/app/Http/Controllers/InvoiceController.php @@ -795,7 +795,11 @@ class InvoiceController extends BaseController $file_path = $invoice->service()->getInvoicePdf($contact); - return response()->download($file_path, basename($file_path), ['Cache-Control:' => 'no-cache']); + return response()->streamDownload(function () use ($file_path) { + echo file_get_contents($file_path); + }, basename($file_path), ['Cache-Control:' => 'no-cache']); + + //return response()->download(Storage::url($file_path), basename($file_path), ['Cache-Control:' => 'no-cache']); } /** @@ -844,12 +848,15 @@ class InvoiceController extends BaseController */ public function deliveryNote(ShowInvoiceRequest $request, Invoice $invoice) { - $file_path = $invoice->service()->getInvoiceDeliveryNote($invoice, $invoice->invitations->first()->contact); + $file = $invoice->service()->getInvoiceDeliveryNote($invoice, $invoice->invitations->first()->contact); try { - $file = public_path("storage/{$file_path}"); - return response()->download($file, basename($file), ['Cache-Control:' => 'no-cache']); + return response()->streamDownload(function () use ($file) { + echo file_get_contents($file); + }, basename($file), ['Cache-Control:' => 'no-cache']); + + // return response()->download($file, basename($file), ['Cache-Control:' => 'no-cache']); } catch (\Exception $e) { return response(['message' => 'Oops, something went wrong. Make sure you have symlink to storage/ in public/ directory.'], 500); } diff --git a/app/Jobs/Entity/CreateEntityPdf.php b/app/Jobs/Entity/CreateEntityPdf.php index 6fd777da27..a4d7a5fcec 100644 --- a/app/Jobs/Entity/CreateEntityPdf.php +++ b/app/Jobs/Entity/CreateEntityPdf.php @@ -30,6 +30,7 @@ use App\Utils\HostedPDF\NinjaPdf; use App\Utils\HtmlEngine; use App\Utils\Ninja; use App\Utils\PhantomJS\Phantom; +use App\Utils\TempFile; use App\Utils\Traits\MakesHash; use App\Utils\Traits\MakesInvoiceHtml; use App\Utils\Traits\NumberFormatter; @@ -187,22 +188,23 @@ class CreateEntityPdf implements ShouldQueue } - if ($pdf) { + // if ($pdf) { - try{ + // try{ - Storage::disk($this->disk)->put($file_path, $pdf); + // // Storage::disk($this->disk)->put($file_path, $pdf); - } - catch(\Exception $e) - { + // } + // catch(\Exception $e) + // { - throw new FilePermissionsFailure('Could not write the PDF, permission issues!'); + // throw new FilePermissionsFailure('Could not write the PDF, permission issues!'); - } - } + // } + // } + // // nlog("entity says path = {$file_path}"); + return TempFile::filePath($pdf, $this->entity->numberFormatter().'.pdf'); - return $file_path; } public function failed($e) diff --git a/app/Jobs/Util/UnlinkFile.php b/app/Jobs/Util/UnlinkFile.php index 70461add3b..a7f5f02cb4 100644 --- a/app/Jobs/Util/UnlinkFile.php +++ b/app/Jobs/Util/UnlinkFile.php @@ -39,8 +39,6 @@ class UnlinkFile implements ShouldQueue */ public function handle() { - // nlog("deleting"); - // nlog($this->file_path); Storage::disk($this->disk)->delete($this->file_path); } } diff --git a/app/Services/Invoice/GenerateDeliveryNote.php b/app/Services/Invoice/GenerateDeliveryNote.php index 3974071217..157a49ca49 100644 --- a/app/Services/Invoice/GenerateDeliveryNote.php +++ b/app/Services/Invoice/GenerateDeliveryNote.php @@ -59,7 +59,7 @@ class GenerateDeliveryNote ? $this->invoice->design_id : $this->decodePrimaryKey($this->invoice->client->getSetting('invoice_design_id')); - $file_path = sprintf('%s%s_delivery_note.pdf', $this->invoice->client->invoice_filepath(), $this->invoice->number); + $filename = sprintf('%s_delivery_note.pdf', $this->invoice->number); if (config('ninja.phantomjs_pdf_generation') || config('ninja.pdf_generator') == 'phantom') { return (new Phantom)->generate($this->invoice->invitations->first()); @@ -91,8 +91,6 @@ class GenerateDeliveryNote ->design($template) ->build(); - // Storage::makeDirectory($this->invoice->client->invoice_filepath(), 0775); - if(config('ninja.invoiceninja_hosted_pdf_generation') || config('ninja.pdf_generator') == 'hosted_ninja'){ $pdf = (new NinjaPdf())->build($maker->getCompiledHTML(true)); } @@ -104,12 +102,8 @@ class GenerateDeliveryNote info($maker->getCompiledHTML()); } - Storage::disk($this->disk)->put($file_path, $pdf); - - /* Copy from remote disk to local when using cloud file storage. */ - if(config('filesystems.default') == 's3') - return TempFile::path(Storage::disk($this->disk)->url($file_path)); - - return $file_path; + return TempFile::filePath($pdf, $filename); + // Storage::disk($this->disk)->put($file_path, $pdf); + // return $file_path; } } diff --git a/app/Services/Invoice/GetInvoicePdf.php b/app/Services/Invoice/GetInvoicePdf.php index 96917d16f2..60d48d25e5 100644 --- a/app/Services/Invoice/GetInvoicePdf.php +++ b/app/Services/Invoice/GetInvoicePdf.php @@ -35,24 +35,26 @@ class GetInvoicePdf extends AbstractService $invitation = $this->invoice->invitations->where('client_contact_id', $this->contact->id)->first(); - $path = $this->invoice->client->invoice_filepath(); + // $path = $this->invoice->client->invoice_filepath(); - $file_path = $path.$this->invoice->numberFormatter().'.pdf'; + // $file_path = $path.$this->invoice->numberFormatter().'.pdf'; - $disk = config('filesystems.default'); + // $disk = config('filesystems.default'); - $file = Storage::disk($disk)->exists($file_path); + // $file = Storage::disk($disk)->exists($file_path); - if (! $file) { - $file_path = CreateEntityPdf::dispatchNow($invitation); - } + // if (! $file) { + return CreateEntityPdf::dispatchNow($invitation); + // } + // return TempFile::filePath($pdf, $file_path); + // return $file_path; /* Copy from remote disk to local when using cloud file storage. */ - if(config('filesystems.default') == 's3') - return TempFile::path(Storage::disk($disk)->url($file_path)); + // if(config('filesystems.default') == 's3') + // return TempFile::path(Storage::disk($disk)->url($file_path)); - // return Storage::disk($disk)->url($file_path); - return Storage::disk($disk)->path($file_path); + // // return Storage::disk($disk)->url($file_path); + // return Storage::disk($disk)->path($file_path); } }