From 77aaf4748fc2069481031090d4b8f808fe01ff11 Mon Sep 17 00:00:00 2001 From: Rumperuu Date: Mon, 7 Nov 2022 22:33:46 +0000 Subject: [PATCH] Add fortnightly digests, test arg --- .gitignore | 1 + app/Console/Commands/SendDigest.php | 16 +++++++++++++--- app/Console/Kernel.php | 7 +++++++ config/app.php | 2 ++ 4 files changed, 23 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 38e5b25..4aac437 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,4 @@ npm-debug.log yarn-error.log /.idea /.vscode +cron.out diff --git a/app/Console/Commands/SendDigest.php b/app/Console/Commands/SendDigest.php index a6bb509..1c443c3 100644 --- a/app/Console/Commands/SendDigest.php +++ b/app/Console/Commands/SendDigest.php @@ -14,7 +14,7 @@ class SendDigest extends Command * * @var string */ - protected $signature = 'digest:send {--D|daily} {--W|weekly} {--M|monthly}'; + protected $signature = 'digest:send {--T|test} {--D|daily} {--W|weekly} {--F|fortnightly} {--M|monthly}'; /** * The console command description. @@ -30,14 +30,17 @@ class SendDigest extends Command */ public function handle() { - if (!$this->option('daily') && !$this->option('weekly') && !$this->option('monthly')) { + if (!$this->option('daily') && !$this->option('weekly') && !$this->option('fortnightly') && !$this->option('monthly')) { $this->error('No schedule specified.'); return; } + + $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 (config('app.daily_digest_recipients') as $recipient) { + 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'))); } @@ -50,6 +53,13 @@ class SendDigest extends Command } } + if ($this->option('fortnightly')) { + foreach (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 (config('app.monthly_digest_recipients') as $recipient) { Log::debug("Monthly digest email sent to '{$recipient}'."); diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index a751882..84ecb8e 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -28,6 +28,13 @@ class Kernel extends ConsoleKernel Log::error("Weekly email digest send failed"); }); + $schedule->command('digest:send --fortnightly') + ->weeklyOn(5, '00:01') + ->when(function() { return (time() / 604800 % 2); }) + ->onFailure(function() { + Log::error("Fortnightly email digest send failed"); + }); + $schedule->command('digest:send --monthly') ->monthly() ->onFailure(function() { diff --git a/config/app.php b/config/app.php index 99ddef1..f315ac8 100644 --- a/config/app.php +++ b/config/app.php @@ -81,8 +81,10 @@ return [ | */ + 'test_address' => env('TEST_ADDRESS'), 'daily_digest_recipients' => explode(',', env('DAILY_DIGEST_TO')), 'weekly_digest_recipients' => explode(',', env('WEEKLY_DIGEST_TO')), + 'fortnightly_digest_recipients' => explode(',', env('FORTNIGHTLY_DIGEST_TO')), 'monthly_digest_recipients' => explode(',', env('MONTHLY_DIGEST_TO')), /*