migration

This commit is contained in:
torsten 2026-10-04 23:15:54 +02:00
parent add615fe9c
commit e3d6272276
37 changed files with 2777 additions and 144 deletions

View file

@ -151,6 +151,45 @@ class Season {
return $stmt->execute($params);
}
/**
* Löscht eine Saison mit allen abhängigen Daten (Tipps, Spiele, Runden,
* Quoten, Zahlungen, manuelle Ausschüttungen). Die aktive Saison kann nicht gelöscht werden.
*
* @param int $id
* @throws \Exception wenn die Saison aktiv ist oder nicht existiert
*/
public static function delete($id) {
$id = (int)$id;
if (!self::findById($id)) {
throw new \Exception('Saison nicht gefunden.');
}
$current = self::getCurrent();
if ($current && (int)$current['id'] === $id) {
throw new \Exception('Die aktive Saison kann nicht gelöscht werden.');
}
$db = Database::getConnection();
$db->beginTransaction();
try {
$statements = [
"DELETE t FROM tipps t JOIN games g ON g.id = t.game_id JOIN rounds r ON r.id = g.round_id WHERE r.season_id = ?",
"DELETE g FROM games g JOIN rounds r ON r.id = g.round_id WHERE r.season_id = ?",
"DELETE FROM rounds WHERE season_id = ?",
"DELETE FROM quotas WHERE season_id = ?",
"DELETE FROM payments WHERE season_id = ?",
"DELETE FROM manual_payouts WHERE season_id = ?",
"DELETE FROM seasons WHERE id = ?",
];
foreach ($statements as $sql) {
$db->prepare($sql)->execute([$id]);
}
$db->commit();
} catch (\Exception $e) {
$db->rollBack();
throw $e;
}
}
/**
* Setzt die aktive Saison in der `settings`-Tabelle.
* Es wird (wie im Legacy-Code) immer die erste Zeile von settings verwendet.