delete Serie

This commit is contained in:
2025-11-10 16:08:22 +01:00
parent 74b84d1a4a
commit 2836d8d1b2
+30
View File
@@ -635,6 +635,36 @@ try {
resp(['ok' => true, 'items' => $rows]);
}
case 'delete_show': {
$showId = (int)($in['show_id'] ?? 0);
if (!$showId) fail('bad params');
$pdo->beginTransaction();
try {
// Delete episodes belonging to this show's seasons
try {
$stmt = $pdo->prepare('DELETE e FROM episodes e JOIN seasons s ON s.id = e.season_id WHERE s.show_id = ?');
$stmt->execute([$showId]);
} catch (Throwable $e) {
// Fallback for SQL dialects not supporting multi-table delete
$stmt = $pdo->prepare('DELETE FROM episodes WHERE season_id IN (SELECT id FROM seasons WHERE show_id = ?)');
$stmt->execute([$showId]);
}
// Delete seasons
$stmt = $pdo->prepare('DELETE FROM seasons WHERE show_id = ?');
$stmt->execute([$showId]);
// Delete show
$stmt = $pdo->prepare('DELETE FROM shows WHERE id = ?');
$stmt->execute([$showId]);
$pdo->commit();
resp(['ok' => true]);
} catch (Throwable $e) {
$pdo->rollBack();
if (MM_DEBUG) fail('delete failed: '.$e->getMessage(), 500);
fail('delete failed', 500);
}
}
case 'set_show_meta': {
$showId = (int)($in['show_id'] ?? 0);
if (!$showId) fail('bad params');