diff --git a/app/Http/Controllers/EmailController.php b/app/Http/Controllers/EmailController.php index 8481a0939ad6..885123cf5049 100644 --- a/app/Http/Controllers/EmailController.php +++ b/app/Http/Controllers/EmailController.php @@ -128,7 +128,11 @@ class EmailController extends BaseController 'body' => $body ]; - EmailEntity::dispatchNow($invitation, $invitation->company, $template, $data); + $entity_obj->service()->markSent()->save(); + + //@TODO why is this dispatchNow instead of just dispatch? + //update - changing to dispatch and see if something breaks. + EmailEntity::dispatch($invitation, $invitation->company, $template, $data); } }); diff --git a/app/Jobs/Entity/CreateEntityPdf.php b/app/Jobs/Entity/CreateEntityPdf.php index a21fc5d63c4f..04ca27461698 100644 --- a/app/Jobs/Entity/CreateEntityPdf.php +++ b/app/Jobs/Entity/CreateEntityPdf.php @@ -108,7 +108,6 @@ class CreateEntityPdf implements ShouldQueue $entity_design_id = 'credit_design_id'; } - $file_path = $path.$this->entity->number.'.pdf'; $entity_design_id = $this->entity->design_id ? $this->entity->design_id : $this->decodePrimaryKey($this->entity->client->getSetting($entity_design_id)); @@ -145,10 +144,6 @@ class CreateEntityPdf implements ShouldQueue ->design($template) ->build(); - //todo - move this to the client creation stage so we don't keep hitting this unnecessarily - //nlog("make dir => {$path}"); - //Storage::makeDirectory($path, 0775); - $pdf = null; try { diff --git a/app/Jobs/Entity/EmailEntity.php b/app/Jobs/Entity/EmailEntity.php index bcfcb87ae602..0021aad84b88 100644 --- a/app/Jobs/Entity/EmailEntity.php +++ b/app/Jobs/Entity/EmailEntity.php @@ -110,15 +110,11 @@ class EmailEntity extends BaseMailerJob implements ShouldQueue ) ); } catch (\Exception $e) { -// $this->failed($e); + $this->entityEmailFailed($e->getMessage()); $this->logMailError($e->getMessage(), $this->entity->client); } - // if (count(Mail::failures()) == 0) { - // $this->entityEmailSucceeded(); - // } - /* Mark entity sent */ $this->entity->service()->markSent()->save(); } diff --git a/app/Services/Invoice/GetInvoicePdf.php b/app/Services/Invoice/GetInvoicePdf.php index 838511988b0d..4ea7d6459a7c 100644 --- a/app/Services/Invoice/GetInvoicePdf.php +++ b/app/Services/Invoice/GetInvoicePdf.php @@ -15,6 +15,7 @@ use App\Jobs\Entity\CreateEntityPdf; use App\Models\ClientContact; use App\Models\Invoice; use App\Services\AbstractService; +use App\Utils\TempFile; use Illuminate\Support\Facades\Storage; class GetInvoicePdf extends AbstractService @@ -46,6 +47,10 @@ class GetInvoicePdf extends AbstractService $file_path = CreateEntityPdf::dispatchNow($invitation); } - return Storage::disk($disk)->path($file_path); + + return TempFile::path(Storage::disk($disk)->url($file_path)); + + // return Storage::disk($disk)->url($file_path); + // return Storage::disk($disk)->path($file_path); } } diff --git a/app/Utils/TempFile.php b/app/Utils/TempFile.php index 124b3724630b..1907e49d10c7 100644 --- a/app/Utils/TempFile.php +++ b/app/Utils/TempFile.php @@ -15,7 +15,7 @@ class TempFile { public static function path($url) :string { - $temp_path = tempnam(sys_get_temp_dir(), basename($url)); + $temp_path = @tempnam(sys_get_temp_dir() . '/' . sha1(time()), basename($url)); copy($url, $temp_path); return $temp_path;