delete Serie
This commit is contained in:
@@ -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');
|
||||
|
||||
Reference in New Issue
Block a user