Compare commits
4 Commits
b05d4529b4
...
1ee04edfc9
Author | SHA1 | Date |
---|---|---|
|
1ee04edfc9 | |
|
9a270405c9 | |
|
45f12492b3 | |
|
388c33d102 |
|
@ -6,6 +6,7 @@ use App\Actions\DbMaintainAction;
|
||||||
use App\Form\Actions\PreventionRememberAction;
|
use App\Form\Actions\PreventionRememberAction;
|
||||||
use App\Initialize\InitializeMembers;
|
use App\Initialize\InitializeMembers;
|
||||||
use App\Invoice\Actions\InvoiceSendAction;
|
use App\Invoice\Actions\InvoiceSendAction;
|
||||||
|
use App\Prevention\Actions\YearlyRememberAction;
|
||||||
use Illuminate\Console\Scheduling\Schedule;
|
use Illuminate\Console\Scheduling\Schedule;
|
||||||
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
|
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
|
||||||
|
|
||||||
|
@ -21,6 +22,7 @@ class Kernel extends ConsoleKernel
|
||||||
InitializeMembers::class,
|
InitializeMembers::class,
|
||||||
DbMaintainAction::class,
|
DbMaintainAction::class,
|
||||||
PreventionRememberAction::class,
|
PreventionRememberAction::class,
|
||||||
|
YearlyRememberAction::class,
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -34,6 +36,7 @@ class Kernel extends ConsoleKernel
|
||||||
$schedule->command(InitializeMembers::class)->dailyAt('03:00');
|
$schedule->command(InitializeMembers::class)->dailyAt('03:00');
|
||||||
$schedule->command(PreventionRememberAction::class)->dailyAt('11:00');
|
$schedule->command(PreventionRememberAction::class)->dailyAt('11:00');
|
||||||
$schedule->command(InvoiceSendAction::class)->dailyAt('10:00');
|
$schedule->command(InvoiceSendAction::class)->dailyAt('10:00');
|
||||||
|
$schedule->command(YearlyRememberAction::class)->dailyAt('09:00');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -7,6 +7,7 @@ use App\Prevention\Data\PreventionData;
|
||||||
use App\Prevention\Mails\YearlyMail;
|
use App\Prevention\Mails\YearlyMail;
|
||||||
use App\Prevention\PreventionSettings;
|
use App\Prevention\PreventionSettings;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
|
use Illuminate\Support\Facades\Cache;
|
||||||
use Illuminate\Support\Facades\Mail;
|
use Illuminate\Support\Facades\Mail;
|
||||||
use Lorisleiva\Actions\Concerns\AsAction;
|
use Lorisleiva\Actions\Concerns\AsAction;
|
||||||
|
|
||||||
|
@ -40,7 +41,14 @@ class YearlyRememberAction
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
Mail::send($this->createMail($member, $preventions));
|
Cache::remember(
|
||||||
|
'prevention-' . $member->id,
|
||||||
|
(int) now()->diffInSeconds(now()->addWeeks($settings->freshRememberInterval)),
|
||||||
|
function () use ($member, $preventions) {
|
||||||
|
Mail::send($this->createMail($member, $preventions));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,7 @@ class PreventionSettings extends LocalSettings
|
||||||
public EditorData $formmail;
|
public EditorData $formmail;
|
||||||
public EditorData $yearlymail;
|
public EditorData $yearlymail;
|
||||||
public int $weeks;
|
public int $weeks;
|
||||||
|
public int $freshRememberInterval;
|
||||||
|
|
||||||
public static function group(): string
|
public static function group(): string
|
||||||
{
|
{
|
||||||
|
|
|
@ -119,7 +119,7 @@ return [
|
||||||
|
|
||||||
'options' => [
|
'options' => [
|
||||||
'cluster' => env('REDIS_CLUSTER', 'redis'),
|
'cluster' => env('REDIS_CLUSTER', 'redis'),
|
||||||
'prefix' => env('REDIS_PREFIX', Str::slug(env('APP_NAME', 'laravel'), '_').'_database_'),
|
'prefix' => env('REDIS_PREFIX', Str::slug(env('APP_NAME', 'laravel'), '_') . '_database_'),
|
||||||
],
|
],
|
||||||
|
|
||||||
'default' => [
|
'default' => [
|
||||||
|
|
|
@ -8,5 +8,6 @@ return new class extends SettingsMigration
|
||||||
{
|
{
|
||||||
$this->migrator->add('prevention.yearlymail', ['time' => 1, 'blocks' => [], 'version' => '1.0']);
|
$this->migrator->add('prevention.yearlymail', ['time' => 1, 'blocks' => [], 'version' => '1.0']);
|
||||||
$this->migrator->add('prevention.weeks', 8);
|
$this->migrator->add('prevention.weeks', 8);
|
||||||
|
$this->migrator->add('prevention.freshRememberInterval', 12);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -255,6 +255,18 @@ it('remembers members yearly', function ($date, $shouldSend) {
|
||||||
[fn() => now()->subYears(5)->subDay(), false],
|
[fn() => now()->subYears(5)->subDay(), false],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
it('remembers yearly only once', function () {
|
||||||
|
Mail::fake();
|
||||||
|
createMember(['efz' => now()->subYears(5), 'ps_at' => now(), 'has_vk' => true]);
|
||||||
|
|
||||||
|
YearlyRememberAction::run();
|
||||||
|
YearlyRememberAction::run();
|
||||||
|
YearlyRememberAction::run();
|
||||||
|
|
||||||
|
Mail::assertSentCount(1);
|
||||||
|
Mail::assertSent(YearlyMail::class, fn($mail) => $mail->preventions->first()->expires->isSameDay(now()));
|
||||||
|
});
|
||||||
|
|
||||||
it('testItDoesntRememberParticipantThatHasNoMail', function () {
|
it('testItDoesntRememberParticipantThatHasNoMail', function () {
|
||||||
Mail::fake();
|
Mail::fake();
|
||||||
$form = createForm();
|
$form = createForm();
|
||||||
|
|
Loading…
Reference in New Issue