From 16beef182ebd1807b73364e03028ca29652d806f Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Wed, 26 Apr 2017 09:16:36 +0300 Subject: [PATCH] Fix login/logout in jobs --- app/Jobs/ImportData.php | 10 +++++++--- app/Jobs/SendInvoiceEmail.php | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/app/Jobs/ImportData.php b/app/Jobs/ImportData.php index 6b9104707e..6f13e93c6a 100644 --- a/app/Jobs/ImportData.php +++ b/app/Jobs/ImportData.php @@ -55,8 +55,10 @@ class ImportData extends Job implements ShouldQueue { $includeSettings = false; - Auth::onceUsingId($this->user->id); - $this->user->account->loadLocalizationSettings(); + if (App::runningInConsole()) { + Auth::onceUsingId($this->user->id); + $this->user->account->loadLocalizationSettings(); + } if ($this->type === IMPORT_JSON) { $includeData = $this->settings['include_data']; @@ -78,6 +80,8 @@ class ImportData extends Job implements ShouldQueue $message = $importService->presentResults($results, $includeSettings); $userMailer->sendMessage($this->user, $subject, $message); - Auth::logout(); + if (App::runningInConsole()) { + Auth::logout(); + } } } diff --git a/app/Jobs/SendInvoiceEmail.php b/app/Jobs/SendInvoiceEmail.php index a9a6931338..04168b609f 100644 --- a/app/Jobs/SendInvoiceEmail.php +++ b/app/Jobs/SendInvoiceEmail.php @@ -63,7 +63,7 @@ class SendInvoiceEmail extends Job implements ShouldQueue { // send email as user if (App::runningInConsole() && $this->userId) { - Auth::loginUsingId($this->userId); + Auth::onceUsingId($this->userId); } $mailer->sendInvoice($this->invoice, $this->reminder, $this->template);