deletePireps(setting('pireps.delete_rejected_hours'), PirepState::REJECTED); $this->deletePireps(setting('pireps.delete_cancelled_hours'), PirepState::CANCELLED); } /** * Look for and delete PIREPs which match the criteria * * @param int $expire_time_hours The time in hours to look for PIREPs * @param int $state The PirepState enum value */ protected function deletePireps(int $expire_time_hours, int $state) { $dt = Carbon::now('UTC')->subHours($expire_time_hours); $pireps = Pirep::where('created_at', '<', $dt)->where(['state' => $state])->get(); /** @var PirepService $pirepSvc */ $pirepSvc = app(PirepService::class); /** @var Pirep $pirep */ foreach ($pireps as $pirep) { Log::info('Cron: Deleting PIREP id='.$pirep->id.', state='.PirepState::label($state)); $pirepSvc->delete($pirep); } } }