From 0d660ca22ffa2ee29c0461ae297814de28c73b7b Mon Sep 17 00:00:00 2001 From: Rumperuu Date: Thu, 10 Aug 2023 13:51:08 +0100 Subject: [PATCH] only send digests when trip in progress --- app/Console/Commands/SendDigest.php | 46 ++++++++++++++++------------- 1 file changed, 25 insertions(+), 21 deletions(-) diff --git a/app/Console/Commands/SendDigest.php b/app/Console/Commands/SendDigest.php index 056b4cf..b08d434 100644 --- a/app/Console/Commands/SendDigest.php +++ b/app/Console/Commands/SendDigest.php @@ -41,34 +41,38 @@ class SendDigest extends Command $test_address = $this->option('test') ? [config('app.test_address')] : null; - // These are seperated because I may want to send multiple types - // of digest in a single commend. - if ($this->option('daily')) { - foreach (($test_address ?? config('app.daily_digest_recipients')) as $recipient) { - Log::debug("Daily digest email sent to '{$recipient}'."); - Mail::to($recipient)->send(new Digest('daily', config('app.current_trip_id'))); + if (config('app.current_trip_id')) { + // These are seperated because I may want to send multiple types + // of digest in a single command. + if ($this->option('daily')) { + foreach (($test_address ?? config('app.daily_digest_recipients')) as $recipient) { + Log::debug("Daily digest email sent to '{$recipient}'."); + Mail::to($recipient)->send(new Digest('daily', config('app.current_trip_id'))); + } } - } - if ($this->option('weekly')) { - foreach (($test_address ?? config('app.weekly_digest_recipients')) as $recipient) { - Log::debug("Weekly digest email sent to '{$recipient}'."); - Mail::to($recipient)->send(new Digest('weekly', config('app.current_trip_id'))); + if ($this->option('weekly')) { + foreach (($test_address ?? config('app.weekly_digest_recipients')) as $recipient) { + Log::debug("Weekly digest email sent to '{$recipient}'."); + Mail::to($recipient)->send(new Digest('weekly', config('app.current_trip_id'))); + } } - } - if ($this->option('fortnightly')) { - foreach (($test_address ?? config('app.fortnightly_digest_recipients')) as $recipient) { - Log::debug("Fortnightly digest email sent to '{$recipient}'."); - Mail::to($recipient)->send(new Digest('fortnightly', config('app.current_trip_id'))); + if ($this->option('fortnightly')) { + foreach (($test_address ?? config('app.fortnightly_digest_recipients')) as $recipient) { + Log::debug("Fortnightly digest email sent to '{$recipient}'."); + Mail::to($recipient)->send(new Digest('fortnightly', config('app.current_trip_id'))); + } } - } - if ($this->option('monthly')) { - foreach (($test_address ?? config('app.monthly_digest_recipients')) as $recipient) { - Log::debug("Monthly digest email sent to '{$recipient}'."); - Mail::to($recipient)->send(new Digest('monthly', config('app.current_trip_id'))); + if ($this->option('monthly')) { + foreach (($test_address ?? config('app.monthly_digest_recipients')) as $recipient) { + Log::debug("Monthly digest email sent to '{$recipient}'."); + Mail::to($recipient)->send(new Digest('monthly', config('app.current_trip_id'))); + } } + } else { + Log::debug("No trip currently running, no digests sent."); } } }