Files
fewo-stommer/app/Actions/RemindChannelTasks.php
T
2026-10-23 07:14:25 +02:00

34 lines
908 B
PHP

<?php
namespace App\Actions;
use App\Mail\ChannelTasksNotification;
use App\Models\ChannelTask;
use App\Support\Settings;
use Illuminate\Support\Facades\Mail;
/**
* Reminds the landlord once about blocking tasks that are still open after the reminder time.
*/
class RemindChannelTasks
{
public function handle(): int
{
$tasks = ChannelTask::query()
->open()
->whereNull('reminded_at')
->where('created_at', '<=', now()->subMinutes(config('fewo.channels.task_reminder_after_minutes')))
->with('channel')
->get();
if ($tasks->isEmpty()) {
return 0;
}
Mail::to(Settings::notificationRecipients())->send(new ChannelTasksNotification($tasks->all(), reminder: true));
ChannelTask::whereKey($tasks->modelKeys())->update(['reminded_at' => now()]);
return $tasks->count();
}
}