From a514bfe98db2b47b95c28f999e769e9d170a0eb8 Mon Sep 17 00:00:00 2001 From: "sosuke.iwabuchi" Date: Thu, 20 Jul 2023 16:41:05 +0900 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E4=BB=98=E3=83=95=E3=82=A1=E3=82=A4?= =?UTF-8?q?=E3=83=AB=E5=AD=98=E5=9C=A8=E3=81=97=E3=81=AA=E3=81=84=E5=A0=B4?= =?UTF-8?q?=E5=90=88=E3=81=AB=E3=80=81=E3=83=A1=E3=83=BC=E3=83=AB=E3=82=B8?= =?UTF-8?q?=E3=83=A7=E3=83=96=E3=82=92=E7=B5=82=E4=BA=86=E3=81=95=E3=81=9B?= =?UTF-8?q?=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB=E7=B5=82=E4=BA=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Email/BaseEmailer.php | 11 ++++++++++ app/Exceptions/TempFileNotExistsException.php | 21 +++++++++++++++++++ app/Jobs/Email/SimpleEmail.php | 9 +++++++- 3 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 app/Exceptions/TempFileNotExistsException.php diff --git a/app/Email/BaseEmailer.php b/app/Email/BaseEmailer.php index 0f0e315..326b40d 100644 --- a/app/Email/BaseEmailer.php +++ b/app/Email/BaseEmailer.php @@ -3,6 +3,7 @@ namespace App\Email; use App\Exceptions\AppCommonException; +use App\Exceptions\TempFileNotExistsException; use App\Models\Email; use App\Models\EmailAttachment; use App\Models\User; @@ -82,7 +83,17 @@ abstract class BaseEmailer extends Mailable if ($this->__attachments !== null) { $count = $this->__attachments->count(); foreach ($this->__attachments as $attachment) { + + + $filepath = $attachment->filepath; + + + if (!file_exists($filepath)) { + $e = new TempFileNotExistsException(); + throw $e->setFilepath($filepath); + } + $as = $attachment->send_filename; $mime = $attachment->mime; $this->attach($filepath, [ diff --git a/app/Exceptions/TempFileNotExistsException.php b/app/Exceptions/TempFileNotExistsException.php new file mode 100644 index 0000000..d02f389 --- /dev/null +++ b/app/Exceptions/TempFileNotExistsException.php @@ -0,0 +1,21 @@ +filepath = $filepath; + return $this; + } + + public function getFilepath(): string + { + return $this->filepath; + } +} diff --git a/app/Jobs/Email/SimpleEmail.php b/app/Jobs/Email/SimpleEmail.php index 580a36f..13be367 100644 --- a/app/Jobs/Email/SimpleEmail.php +++ b/app/Jobs/Email/SimpleEmail.php @@ -4,8 +4,10 @@ namespace App\Jobs\Email; use App\Codes\QueueName; use App\Email\Sender; +use App\Exceptions\TempFileNotExistsException; use App\Jobs\BaseJob; use App\Models\Email; +use Illuminate\Support\Facades\Log; class SimpleEmail extends BaseJob { @@ -29,6 +31,11 @@ class SimpleEmail extends BaseJob */ public function handle() { - Sender::send($this->emailId); + try { + Sender::send($this->emailId); + } catch (TempFileNotExistsException $e) { + // 一時ファイルが存在しないため、処理終了 + Log::warning(sprintf("ファイル存在しないため、メール送信処理スキップ :%s", $e->getFilepath())); + } } }