Add fortnightly digests, test arg

This commit is contained in:
Ben Goldsworthy 2022-11-07 22:33:46 +00:00
parent bb3f9b343c
commit 77aaf4748f
4 changed files with 23 additions and 3 deletions

View file

@ -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}'.");