diff --git a/src/Console/SyncPpskSchedules.php b/src/Console/SyncPpskSchedules.php index d8a6fdf..c97ff03 100644 --- a/src/Console/SyncPpskSchedules.php +++ b/src/Console/SyncPpskSchedules.php @@ -14,16 +14,21 @@ class SyncPpskSchedules extends Command public function handle(UnifiApiClient $unifi): int { - if (! $this->option('force') && ! Setting::get('unifi.ppsk_scheduling.enabled')) { - return self::SUCCESS; - } + // Always run, even when global ppsk_scheduling is disabled — in + // that case the target state for every PPSK is "active" (always + // on). That way disabling the global setting actually restores + // any held PPSKs to active without operators having to do + // anything else, and null-schedule PPSKs always end up active. + // Schedules in the DB are preserved regardless of toggle state, + // so re-enabling resumes the per-PPSK schedule. + $globalEnabled = (bool) Setting::get('unifi.ppsk_scheduling.enabled'); $tz = \App\Support\Timezone::current(); $now = now($tz); $day = $now->dayOfWeek; // 0=Sun … 6=Sat $slot = $now->hour * 2 + ($now->minute >= 30 ? 1 : 0); // 0–47 - $ppsks = UnifiPpsk::whereNotNull('schedule')->get(); + $ppsks = UnifiPpsk::all(); if ($ppsks->isEmpty()) { return self::SUCCESS; @@ -42,7 +47,12 @@ class SyncPpskSchedules extends Command } foreach ($ppsks as $ppsk) { - $shouldBeOn = (bool) ($ppsk->schedule[$day * 48 + $slot] ?? true); + // Default to "always on". Only consult the schedule if + // global scheduling is enabled AND this PPSK has one. + $shouldBeOn = true; + if ($globalEnabled && $ppsk->schedule) { + $shouldBeOn = (bool) ($ppsk->schedule[$day * 48 + $slot] ?? true); + } if ($shouldBeOn && $ppsk->state === 'held') { $this->enablePpsk($ppsk, $unifi, $networksByVlan);