From d6f0c5d7cbb1c14e2c2ce5c75d68f800c624a69d Mon Sep 17 00:00:00 2001 From: boban Date: Sun, 26 Oct 2025 20:54:57 +0100 Subject: [PATCH] =?UTF-8?q?Fix:=20Mailbox=20Stats=20=C3=BCber=20Dovecot=20?= =?UTF-8?q?mit=20config/mailpool.php?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Livewire/Ui/System/ServicesCard.php | 153 +++++++++++++++++------- 1 file changed, 112 insertions(+), 41 deletions(-) diff --git a/app/Livewire/Ui/System/ServicesCard.php b/app/Livewire/Ui/System/ServicesCard.php index 15157c0..7925852 100644 --- a/app/Livewire/Ui/System/ServicesCard.php +++ b/app/Livewire/Ui/System/ServicesCard.php @@ -45,60 +45,56 @@ class ServicesCard extends Component public function load(): void { - // 1) Karten aus Config laden $cards = config('woltguard.cards', []); - if (empty($cards)) { - // Config-Clear/-Cache synchron ausführen (kostet ~ms) - try { - Artisan::call('config:clear'); - Artisan::call('config:cache'); - } catch (\Throwable $e) { - // ignoriere – UI soll trotzdem laufen - } - $cards = config('woltguard.cards', []); + // 1) Cache lesen (versionierter Key) + $raw = Cache::get(CacheVer::k('health:services')); + + // 2) Neues Format { ts, rows } → entpacken + if (is_array($raw) && array_key_exists('rows', $raw)) { + $raw = $raw['rows']; } - // 2) Service-Status aus Cache (versionierter Key) - $key = \App\Support\CacheVer::k('health:services'); - $raw = Cache::get($key, []); - // Legacy-Key als Fallback - if (empty($raw)) $raw = Cache::get('health:services', []); + // 3) Fallback: Legacy-Key ODER Settings (DB/Redis) – ebenfalls entpacken + if (empty($raw)) { + $legacy = Cache::get('health:services', []); + if (is_array($legacy) && array_key_exists('rows', $legacy)) { + $raw = $legacy['rows']; + } elseif (!empty($legacy)) { + $raw = $legacy; + } else { + // persistierter Payload aus DB (Settings) + $persist = \App\Support\Setting::get('woltguard.services', []); + $raw = (is_array($persist) && isset($persist['rows']) && is_array($persist['rows'])) + ? $persist['rows'] + : []; + } + } + // Ab hier ist $raw eine Liste von {name, ok} $cached = collect($raw)->keyBy('name'); - $rows = []; - $ok = 0; + $rows = []; + foreach ($cards as $key => $card) { + $isOk = (bool) ($cached->get($key)['ok'] ?? false); - foreach ($cards as $name => $card) { - $isOk = (bool) ($cached->get($name)['ok'] ?? false); - - // 3) Wenn Cache leer → aktiv prüfen + // Nur wenn wirklich gar nichts im Cache ist, aktiv prüfen if ($cached->isEmpty()) { foreach ($card['sources'] as $src) { if ($this->check($src)) { $isOk = true; break; } } } - if ($isOk) $ok++; - $rows[] = [ - 'name' => $name, // <— wichtig, damit der Cache keyBy('name') später klappt - 'label' => $card['label'] ?? $name, - 'hint' => $card['hint'] ?? null, + 'label' => $card['label'], + 'hint' => $card['hint'], 'ok' => $isOk, ]; } - // 4) Wenn wir aktiv geprüft haben (Cache war leer) → Cache auffüllen - if ($cached->isEmpty() && !empty($rows)) { - Cache::put($key, $rows, 600); // 10 Minuten - Cache::forget('health:services'); // Legacy aufräumen - } - - // 5) Kopfzahlen + UI-Daten + // Zähler / Badge / Compact wie vorher… $this->totalCount = count($rows); - $this->okCount = $ok; + $this->okCount = collect($rows)->where('ok', true)->count(); $this->guardOk = $this->totalCount > 0 && $this->okCount === $this->totalCount; [$this->badgeText, $this->badgeClass, $this->badgeIcon] = @@ -106,17 +102,92 @@ class ServicesCard extends Component ? ['alle Dienste OK', 'text-emerald-200 bg-emerald-500/10 border-emerald-400/30', 'ph ph-check-circle'] : ["{$this->okCount}/{$this->totalCount} aktiv", 'text-amber-200 bg-amber-500/10 border-amber-400/30', 'ph ph-warning']; - $this->servicesCompact = collect($rows)->map(fn($r) => [ - 'label' => $r['label'], - 'hint' => $r['hint'], - 'ok' => $r['ok'], - 'dotClass' => $r['ok'] ? 'bg-emerald-400' : 'bg-rose-400', - 'pillText' => $r['ok'] ? 'Online' : 'Offline', - 'pillClass' => $r['ok'] + $this->servicesCompact = collect($rows)->map(fn($row) => [ + 'label' => $row['label'], + 'hint' => $row['hint'], + 'ok' => $row['ok'], + 'dotClass' => $row['ok'] ? 'bg-emerald-400' : 'bg-rose-400', + 'pillText' => $row['ok'] ? 'Online' : 'Offline', + 'pillClass' => $row['ok'] ? 'text-emerald-300 border-emerald-400/30 bg-emerald-500/10' : 'text-rose-300 border-rose-400/30 bg-rose-500/10', ])->all(); } + +// public function load(): void +// { +// // 1) Karten aus Config laden +// $cards = config('woltguard.cards', []); +// +// if (empty($cards)) { +// // Config-Clear/-Cache synchron ausführen (kostet ~ms) +// try { +// Artisan::call('config:clear'); +// Artisan::call('config:cache'); +// } catch (\Throwable $e) { +// // ignoriere – UI soll trotzdem laufen +// } +// $cards = config('woltguard.cards', []); +// } +// +// // 2) Service-Status aus Cache (versionierter Key) +// $key = \App\Support\CacheVer::k('health:services'); +// $raw = Cache::get($key, []); +// // Legacy-Key als Fallback +// if (empty($raw)) $raw = Cache::get('health:services', []); +// +// $cached = collect($raw)->keyBy('name'); +// +// $rows = []; +// $ok = 0; +// +// foreach ($cards as $name => $card) { +// $isOk = (bool) ($cached->get($name)['ok'] ?? false); +// +// // 3) Wenn Cache leer → aktiv prüfen +// if ($cached->isEmpty()) { +// foreach ($card['sources'] as $src) { +// if ($this->check($src)) { $isOk = true; break; } +// } +// } +// +// if ($isOk) $ok++; +// +// $rows[] = [ +// 'name' => $name, // <— wichtig, damit der Cache keyBy('name') später klappt +// 'label' => $card['label'] ?? $name, +// 'hint' => $card['hint'] ?? null, +// 'ok' => $isOk, +// ]; +// } +// +// // 4) Wenn wir aktiv geprüft haben (Cache war leer) → Cache auffüllen +// if ($cached->isEmpty() && !empty($rows)) { +// Cache::put($key, $rows, 600); // 10 Minuten +// Cache::forget('health:services'); // Legacy aufräumen +// } +// +// // 5) Kopfzahlen + UI-Daten +// $this->totalCount = count($rows); +// $this->okCount = $ok; +// $this->guardOk = $this->totalCount > 0 && $this->okCount === $this->totalCount; +// +// [$this->badgeText, $this->badgeClass, $this->badgeIcon] = +// $this->guardOk +// ? ['alle Dienste OK', 'text-emerald-200 bg-emerald-500/10 border-emerald-400/30', 'ph ph-check-circle'] +// : ["{$this->okCount}/{$this->totalCount} aktiv", 'text-amber-200 bg-amber-500/10 border-amber-400/30', 'ph ph-warning']; +// +// $this->servicesCompact = collect($rows)->map(fn($r) => [ +// 'label' => $r['label'], +// 'hint' => $r['hint'], +// 'ok' => $r['ok'], +// 'dotClass' => $r['ok'] ? 'bg-emerald-400' : 'bg-rose-400', +// 'pillText' => $r['ok'] ? 'Online' : 'Offline', +// 'pillClass' => $r['ok'] +// ? 'text-emerald-300 border-emerald-400/30 bg-emerald-500/10' +// : 'text-rose-300 border-rose-400/30 bg-rose-500/10', +// ])->all(); +// } // public function load(): void // {