mirror of
https://github.com/ceratic/MediaCollectorLibary.git
synced 2026-05-13 23:56:46 +02:00
i dont know
This commit is contained in:
@@ -41,7 +41,11 @@ class TvShowController extends Controller
|
||||
$totalPages = ceil($totalCount / $perPage);
|
||||
$hasNextPage = $page < $totalPages;
|
||||
$hasPrevPage = $page > 1;
|
||||
|
||||
/*
|
||||
echo '<pre>';
|
||||
print_r($tvshows);
|
||||
die();
|
||||
*/
|
||||
return $this->view->render($response, 'tvshows/index.twig', [
|
||||
'title' => 'TV Shows',
|
||||
'tvshows' => $tvshows,
|
||||
@@ -107,4 +111,67 @@ class TvShowController extends Controller
|
||||
'seasons' => $seasons
|
||||
]);
|
||||
}
|
||||
|
||||
public function delete(Request $request, Response $response, $args)
|
||||
{
|
||||
$tvShowId = (int) $args['id'];
|
||||
|
||||
// Get TV show details to access metadata
|
||||
$stmt = $this->pdo->prepare("
|
||||
SELECT t.*
|
||||
FROM tv_shows t
|
||||
WHERE t.id = :id
|
||||
");
|
||||
$stmt->execute(['id' => $tvShowId]);
|
||||
$tvShow = $stmt->fetch(\PDO::FETCH_ASSOC);
|
||||
|
||||
if (!$tvShow) {
|
||||
return $response->withStatus(404);
|
||||
}
|
||||
|
||||
// Decode metadata to find image paths
|
||||
$metadata = json_decode($tvShow['metadata'], true);
|
||||
|
||||
// Delete associated images
|
||||
$imagesDeleted = [];
|
||||
if (!empty($metadata['local_poster_path'])) {
|
||||
$posterPath = __DIR__ . '/../storage/images/' . $metadata['local_poster_path'];
|
||||
if (file_exists($posterPath)) {
|
||||
unlink($posterPath);
|
||||
$imagesDeleted[] = $metadata['local_poster_path'];
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($metadata['local_backdrop_path'])) {
|
||||
$backdropPath = __DIR__ . '/../storage/images/' . $metadata['local_backdrop_path'];
|
||||
if (file_exists($backdropPath)) {
|
||||
unlink($backdropPath);
|
||||
$imagesDeleted[] = $metadata['local_backdrop_path'];
|
||||
}
|
||||
}
|
||||
|
||||
// Delete actor relationships
|
||||
$stmt = $this->pdo->prepare("
|
||||
DELETE FROM actor_tv_show
|
||||
WHERE tv_show_id = :tv_show_id
|
||||
");
|
||||
$stmt->execute(['tv_show_id' => $tvShowId]);
|
||||
|
||||
// Delete the TV show record
|
||||
$stmt = $this->pdo->prepare("DELETE FROM tv_shows WHERE id = :id");
|
||||
$result = $stmt->execute(['id' => $tvShowId]);
|
||||
|
||||
if ($result) {
|
||||
return $response->withJson([
|
||||
'success' => true,
|
||||
'message' => 'TV show deleted successfully',
|
||||
'images_deleted' => $imagesDeleted
|
||||
]);
|
||||
} else {
|
||||
return $response->withJson([
|
||||
'success' => false,
|
||||
'message' => 'Failed to delete TV show'
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user