fix: Verbessere Ermittlung der aktuellen Saison mit Fallback

Co-authored-by: aider (gemini/gemini-2.5-pro) <aider@aider.chat>
This commit is contained in:
torsten 2026-10-03 16:51:01 +02:00
parent 7c71a00095
commit 43346ed1e3

View file

@ -14,18 +14,38 @@ class Season {
public static function getCurrent() {
$db = Database::getConnection();
// Versuche zuerst, eine explizit als aktuell markierte Saison zu finden
$stmt = $db->prepare("SELECT * FROM seasons WHERE is_current = 1 LIMIT 1");
$stmt->execute();
$season = $stmt->fetch();
if ($season) {
return $season;
try {
// 1. Versuch: explizit markierte Saison
$stmt = $db->prepare("SELECT * FROM seasons WHERE is_current = 1 LIMIT 1");
$stmt->execute();
$season = $stmt->fetch();
if ($season) {
return $season;
}
// 2. Versuch: Letzte Saison nach ID
$stmt = $db->prepare("SELECT * FROM seasons ORDER BY id DESC LIMIT 1");
$stmt->execute();
// Gibt die gefundene Saison oder `false` zurück. Die Funktion endet hier, wenn die Abfrage erfolgreich war.
return $stmt->fetch();
} catch (\PDOException $e) {
// Fallback: Wird ausgeführt, wenn die 'seasons'-Tabelle nicht existiert.
// Wir ermitteln die höchste season_id aus der 'rounds'-Tabelle.
$stmt = $db->prepare("SELECT season_id FROM rounds ORDER BY season_id DESC LIMIT 1");
$stmt->execute();
$row = $stmt->fetch();
if ($row) {
// Erstelle ein "Dummy" Season-Objekt für die Kompatibilität
return [
'id' => $row['season_id'],
'name' => 'Saison ' . $row['season_id']
];
}
}
// Fallback: Wenn keine Saison als aktuell markiert ist, nimm die mit der höchsten ID
$stmt = $db->prepare("SELECT * FROM seasons ORDER BY id DESC LIMIT 1");
$stmt->execute();
return $stmt->fetch();
// Wird erreicht, wenn 'seasons' nicht existiert und auch keine Runden gefunden wurden.
return null;
}
}