From 7709bd32d1e43fe840755d94e97ae1e036bc7959 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sun, 13 Jun 2021 10:18:07 +1000 Subject: [PATCH] Ensure directories are created prior to PDF generation --- app/Jobs/Company/CompanyExport.php | 6 +++++- app/Jobs/Entity/CreateEntityPdf.php | 3 ++- app/Services/Invoice/GenerateDeliveryNote.php | 3 +++ app/Utils/PhantomJS/Phantom.php | 5 +++-- 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/app/Jobs/Company/CompanyExport.php b/app/Jobs/Company/CompanyExport.php index aca3306f5788..f9447a1357e2 100644 --- a/app/Jobs/Company/CompanyExport.php +++ b/app/Jobs/Company/CompanyExport.php @@ -480,7 +480,11 @@ class CompanyExport implements ShouldQueue $file_name = date('Y-m-d').'_'.str_replace(' ', '_', $this->company->present()->name() . '_' . $this->company->company_key .'.zip'); - Storage::makeDirectory(public_path('storage/backups/'), 0775); + $path = public_path('storage/backups/'); + + if(!Storage::exists($path)) + Storage::makeDirectory($path, 0775); + $zip_path = public_path('storage/backups/'.$file_name); $zip = new \ZipArchive(); diff --git a/app/Jobs/Entity/CreateEntityPdf.php b/app/Jobs/Entity/CreateEntityPdf.php index 7a6456229c97..a4490df40ae6 100644 --- a/app/Jobs/Entity/CreateEntityPdf.php +++ b/app/Jobs/Entity/CreateEntityPdf.php @@ -193,7 +193,8 @@ class CreateEntityPdf implements ShouldQueue try{ - nlog($file_path); + if(!Storage::exists($path)) + Storage::makeDirectory($path, 0775); Storage::disk($this->disk)->put($file_path, $pdf); diff --git a/app/Services/Invoice/GenerateDeliveryNote.php b/app/Services/Invoice/GenerateDeliveryNote.php index e194b6d41d01..c416e5e34a53 100644 --- a/app/Services/Invoice/GenerateDeliveryNote.php +++ b/app/Services/Invoice/GenerateDeliveryNote.php @@ -106,6 +106,9 @@ class GenerateDeliveryNote info($maker->getCompiledHTML()); } + if(!Storage::exists($this->invoice->client->invoice_filepath($invitation))) + Storage::makeDirectory($this->invoice->client->invoice_filepath($invitation), 0775); + Storage::disk($this->disk)->put($file_path, $pdf); return Storage::disk($this->disk)->path($file_path); diff --git a/app/Utils/PhantomJS/Phantom.php b/app/Utils/PhantomJS/Phantom.php index 6a75c1e49f36..90e25917c2c8 100644 --- a/app/Utils/PhantomJS/Phantom.php +++ b/app/Utils/PhantomJS/Phantom.php @@ -90,6 +90,9 @@ class Phantom $this->checkMime($pdf, $invitation, $entity); + if(!Storage::exists($path)) + Storage::makeDirectory($path, 0775); + $instance = Storage::disk(config('filesystems.default'))->put($file_path, $pdf); return $file_path; @@ -118,8 +121,6 @@ class Phantom $finfo = new \finfo(FILEINFO_MIME); -nlog($pdf); - if($finfo->buffer($pdf) != 'application/pdf; charset=binary') { SystemLogger::dispatch(