phpvms/app/Cron/Hourly/RemoveExpiredLiveFlights.php
2019-07-15 15:51:35 -04:00

34 lines
687 B
PHP

<?php
namespace App\Cron\Hourly;
use App\Contracts\Listener;
use App\Events\CronHourly;
use App\Models\Pirep;
use Carbon\Carbon;
/**
* Remove expired live flights
*/
class RemoveExpiredLiveFlights extends Listener
{
/**
* Remove expired live flights
*
* @param CronHourly $event
*
* @throws \Exception
*/
public function handle(CronHourly $event): void
{
if (setting('acars.live_time') === 0) {
return;
}
$date = Carbon::now()->subHours(setting('acars.live_time'));
Pirep::whereDate('created_at', '<', $date)
->where('state', PirepState::IN_PROGRESS)
->delete();
}
}