2024-07-02 22:55:37 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Form\Actions;
|
|
|
|
|
|
|
|
use App\Form\Models\Participant;
|
|
|
|
use App\Prevention\Mails\PreventionRememberMail;
|
2024-07-04 23:54:37 +02:00
|
|
|
use App\Prevention\PreventionSettings;
|
2024-07-02 22:55:37 +02:00
|
|
|
use Illuminate\Support\Facades\Mail;
|
|
|
|
use Lorisleiva\Actions\Concerns\AsAction;
|
|
|
|
|
|
|
|
class PreventionRememberAction
|
|
|
|
{
|
|
|
|
use AsAction;
|
|
|
|
|
|
|
|
public string $commandSignature = 'prevention:remember';
|
|
|
|
|
|
|
|
public function handle(): void
|
|
|
|
{
|
|
|
|
$query = Participant::whereHas('form', fn ($form) => $form->where('needs_prevention', true))
|
|
|
|
->where(
|
|
|
|
fn ($q) => $q
|
|
|
|
->where('last_remembered_at', '<=', now()->subWeeks(2))
|
|
|
|
->orWhereNull('last_remembered_at')
|
|
|
|
);
|
|
|
|
foreach ($query->get() as $participant) {
|
2024-07-10 00:52:05 +02:00
|
|
|
if ($participant->getFields()->getMailRecipient() === null || count($participant->preventions()) === 0) {
|
|
|
|
continue;
|
2024-07-02 22:55:37 +02:00
|
|
|
}
|
|
|
|
|
2024-07-08 22:39:11 +02:00
|
|
|
$body = app(PreventionSettings::class)->refresh()->formmail
|
2024-07-06 15:08:13 +02:00
|
|
|
->placeholder('formname', $participant->form->name)
|
|
|
|
->append($participant->form->prevention_text);
|
2024-07-04 23:54:37 +02:00
|
|
|
|
|
|
|
Mail::send(new PreventionRememberMail($participant, $body));
|
2024-07-02 22:55:37 +02:00
|
|
|
|
|
|
|
$participant->update(['last_remembered_at' => now()]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|