53 lines
1.5 KiB
PHP
53 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use Illuminate\Console\Command;
|
|
use App\Jobs\AssignPairingJob;
|
|
use App\Models\Event;
|
|
use App\Models\Registration;
|
|
|
|
class PairingTick extends Command
|
|
{
|
|
protected $signature = 'pxg:pairing-tick {--event=}';
|
|
protected $description = 'Scan events for confirmed registrations without flights and dispatch pairing jobs.';
|
|
|
|
public function handle(): int
|
|
{
|
|
$eventOpt = $this->option('event');
|
|
|
|
$events = Event::query();
|
|
if ($eventOpt) {
|
|
$events->where('id', (int)$eventOpt);
|
|
} else {
|
|
// default: only events that are active/open (best effort)
|
|
$events->where(function($q){
|
|
$q->whereNull('registration_close_at')
|
|
->orWhere('registration_close_at', '>=', now()->subDays(1));
|
|
});
|
|
}
|
|
|
|
$ids = $events->pluck('id')->all();
|
|
$dispatched = 0;
|
|
|
|
foreach ($ids as $eventId) {
|
|
$pending = Registration::where('event_id', $eventId)
|
|
->where('status', 'CONFIRMED')
|
|
->whereDoesntHave('flightMember')
|
|
->count();
|
|
|
|
if ($pending > 0) {
|
|
dispatch(new AssignPairingJob((int)$eventId));
|
|
$dispatched++;
|
|
$this->info("Dispatched pairing job for event {$eventId} (pending {$pending})");
|
|
}
|
|
}
|
|
|
|
if ($dispatched === 0) {
|
|
$this->line('No events require pairing.');
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
}
|