Add fortnightly digests, test arg
This commit is contained in:
parent
bb3f9b343c
commit
77aaf4748f
4 changed files with 23 additions and 3 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -14,3 +14,4 @@ npm-debug.log
|
||||||
yarn-error.log
|
yarn-error.log
|
||||||
/.idea
|
/.idea
|
||||||
/.vscode
|
/.vscode
|
||||||
|
cron.out
|
||||||
|
|
|
@ -14,7 +14,7 @@ class SendDigest extends Command
|
||||||
*
|
*
|
||||||
* @var string
|
* @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.
|
* The console command description.
|
||||||
|
@ -30,14 +30,17 @@ class SendDigest extends Command
|
||||||
*/
|
*/
|
||||||
public function handle()
|
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.');
|
$this->error('No schedule specified.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$test_address = $this->option('test') ? [config('app.test_address')] : null;
|
||||||
|
|
||||||
// These are seperated because I may want to send multiple types
|
// These are seperated because I may want to send multiple types
|
||||||
// of digest in a single commend.
|
// of digest in a single commend.
|
||||||
if ($this->option('daily')) {
|
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}'.");
|
Log::debug("Daily digest email sent to '{$recipient}'.");
|
||||||
Mail::to($recipient)->send(new Digest('daily', config('app.current_trip_id')));
|
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')) {
|
if ($this->option('monthly')) {
|
||||||
foreach (config('app.monthly_digest_recipients') as $recipient) {
|
foreach (config('app.monthly_digest_recipients') as $recipient) {
|
||||||
Log::debug("Monthly digest email sent to '{$recipient}'.");
|
Log::debug("Monthly digest email sent to '{$recipient}'.");
|
||||||
|
|
|
@ -28,6 +28,13 @@ class Kernel extends ConsoleKernel
|
||||||
Log::error("Weekly email digest send failed");
|
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')
|
$schedule->command('digest:send --monthly')
|
||||||
->monthly()
|
->monthly()
|
||||||
->onFailure(function() {
|
->onFailure(function() {
|
||||||
|
|
|
@ -81,8 +81,10 @@ return [
|
||||||
|
|
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
'test_address' => env('TEST_ADDRESS'),
|
||||||
'daily_digest_recipients' => explode(',', env('DAILY_DIGEST_TO')),
|
'daily_digest_recipients' => explode(',', env('DAILY_DIGEST_TO')),
|
||||||
'weekly_digest_recipients' => explode(',', env('WEEKLY_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')),
|
'monthly_digest_recipients' => explode(',', env('MONTHLY_DIGEST_TO')),
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
Loading…
Reference in a new issue