| 1 | <?php | ||
| 12 | /** | ||
| 13 | * The name and signature of the console command. | ||
| 14 | * | ||
| 15 | * @var string | ||
| 16 | */ | ||
| 17 | protected $signature = 'tickets:autoclose'; | ||
| 18 | |||
| 19 | /** | ||
| 20 | * The console command description. | ||
| 21 | * | ||
| 22 | * @var string | ||
| 23 | */ | ||
| 24 | protected $description = 'Close any ticket that has become inactive.'; | ||
| 25 | |||
| 26 | /** | ||
| 27 | * Execute the console command. | ||
| 28 | * | ||
| 29 | * @return int | ||
| 30 | */ | ||
| 31 | public function handle() | ||
| 32 |     { | ||
| 33 | $tickets = Ticket::query()->where( | ||
| 34 | 'updated_at', | ||
| 35 | '<', | ||
| 36 |             now()->subDays(config('laravel-tickets.autoclose-days')) | ||
| 37 | ); | ||
| 38 | |||
| 39 | $tickets->update([ 'state' => 'CLOSED' ]); | ||
| 40 | $tickets->get()->each(fn(Ticket $ticket) => event(new TicketCloseEvent($ticket))); | ||
|  | |||
| 41 | } | ||
| 42 | } | ||
| 43 |