isConfigured()) { $this->error('Umami-API nicht konfiguriert: UMAMI_API_URL, UMAMI_API_USERNAME und UMAMI_API_PASSWORD setzen.'); return self::FAILURE; } $metric = (string) $this->option('metric'); if (! in_array($metric, self::METRICS, true)) { $this->error('Unbekannte Rangliste. Möglich: '.implode(', ', self::METRICS).'.'); return self::INVALID; } $to = $this->option('to') !== null ? Carbon::parse((string) $this->option('to'))->endOfDay() : Carbon::now(); $from = $this->option('from') !== null ? Carbon::parse((string) $this->option('from'))->startOfDay() : $to->copy()->subDays(30); $sites = (array) $this->option('site') ?: UmamiClient::BRANDS; $filters = filled($this->option('path')) ? ['path' => 'c.'.$this->option('path')] : []; $limit = max(1, min(500, (int) $this->option('limit'))); $result = []; try { foreach ($sites as $site) { $websiteId = $umami->websiteId((string) $site); if ($websiteId === null) { $this->warn("Keine Umami-Website für „{$site}“ in config/domains.php."); continue; } $result[$site] = [ 'stats' => $umami->stats($websiteId, $from, $to, $filters), $metric => $umami->metrics($websiteId, $metric, $from, $to, $filters, $limit), ]; } } catch (UmamiUnavailable $e) { $this->error($e->getMessage()); return self::FAILURE; } if ($this->option('json')) { $this->line((string) json_encode([ 'from' => $from->toIso8601String(), 'to' => $to->toIso8601String(), 'filters' => $filters, 'sites' => $result, ], JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES)); return self::SUCCESS; } $this->info(sprintf('Umami — %s bis %s%s', $from->format('d.m.Y'), $to->format('d.m.Y'), $filters === [] ? '' : ', Pfad enthält „'.$this->option('path').'“')); foreach ($result as $site => $data) { $this->newLine(); $this->line("{$site}"); $this->table( ['Aufrufe', 'Besucher', 'Besuche', 'Absprünge'], [[$data['stats']['pageviews'], $data['stats']['visitors'], $data['stats']['visits'], $data['stats']['bounces']]], ); $this->table( [ucfirst($metric), 'Anzahl'], array_map(static fn (array $row): array => [$row['x'], $row['y']], $data[$metric]), ); } return self::SUCCESS; } }