only send digests when trip in progress

This commit is contained in:
Ben Goldsworthy 2023-08-10 13:51:08 +01:00
parent d5d0b426f1
commit 0d660ca22f

View file

@ -41,34 +41,38 @@ class SendDigest extends Command
$test_address = $this->option('test') ? [config('app.test_address')] : null; $test_address = $this->option('test') ? [config('app.test_address')] : null;
// These are seperated because I may want to send multiple types if (config('app.current_trip_id')) {
// of digest in a single commend. // These are seperated because I may want to send multiple types
if ($this->option('daily')) { // of digest in a single command.
foreach (($test_address ?? config('app.daily_digest_recipients')) as $recipient) { if ($this->option('daily')) {
Log::debug("Daily digest email sent to '{$recipient}'."); foreach (($test_address ?? config('app.daily_digest_recipients')) as $recipient) {
Mail::to($recipient)->send(new Digest('daily', config('app.current_trip_id'))); Log::debug("Daily digest email sent to '{$recipient}'.");
Mail::to($recipient)->send(new Digest('daily', config('app.current_trip_id')));
}
} }
}
if ($this->option('weekly')) { if ($this->option('weekly')) {
foreach (($test_address ?? config('app.weekly_digest_recipients')) as $recipient) { foreach (($test_address ?? config('app.weekly_digest_recipients')) as $recipient) {
Log::debug("Weekly digest email sent to '{$recipient}'."); Log::debug("Weekly digest email sent to '{$recipient}'.");
Mail::to($recipient)->send(new Digest('weekly', config('app.current_trip_id'))); Mail::to($recipient)->send(new Digest('weekly', config('app.current_trip_id')));
}
} }
}
if ($this->option('fortnightly')) { if ($this->option('fortnightly')) {
foreach (($test_address ?? config('app.fortnightly_digest_recipients')) as $recipient) { foreach (($test_address ?? config('app.fortnightly_digest_recipients')) as $recipient) {
Log::debug("Fortnightly digest email sent to '{$recipient}'."); Log::debug("Fortnightly digest email sent to '{$recipient}'.");
Mail::to($recipient)->send(new Digest('fortnightly', config('app.current_trip_id'))); Mail::to($recipient)->send(new Digest('fortnightly', config('app.current_trip_id')));
}
} }
}
if ($this->option('monthly')) { if ($this->option('monthly')) {
foreach (($test_address ?? config('app.monthly_digest_recipients')) as $recipient) { foreach (($test_address ?? config('app.monthly_digest_recipients')) as $recipient) {
Log::debug("Monthly digest email sent to '{$recipient}'."); Log::debug("Monthly digest email sent to '{$recipient}'.");
Mail::to($recipient)->send(new Digest('monthly', config('app.current_trip_id'))); Mail::to($recipient)->send(new Digest('monthly', config('app.current_trip_id')));
}
} }
} else {
Log::debug("No trip currently running, no digests sent.");
} }
} }
} }