added Information-Field to TV Shows

This commit is contained in:
2026-02-02 14:46:05 +01:00
parent a78501a6a4
commit a6bd718157
4 changed files with 80 additions and 2 deletions
+34
View File
@@ -154,6 +154,26 @@ function gameHasColumn(string $col): bool {
return in_array($col, gameColumns(), true);
}
function showColumns(): array {
static $cols = null;
if ($cols !== null) return $cols;
$cols = [];
try {
$pdo = getDb();
$stmt = $pdo->query('DESCRIBE shows');
foreach ($stmt as $row) {
if (isset($row['Field'])) $cols[] = $row['Field'];
}
} catch (Throwable $e) {
$cols = [];
}
return $cols;
}
function showHasColumn(string $col): bool {
return in_array($col, showColumns(), true);
}
function getLocalization(int $igdbId, string $lang = 'de'): ?array {
$pdo = getDb();
$stmt = $pdo->prepare('SELECT * FROM igdb_localizations WHERE igdb_id = :id AND lang = :lang LIMIT 1');
@@ -1007,6 +1027,8 @@ try {
$s = strtolower($status);
if ($s==='init') $statusVal = 0; elseif ($s==='progress') $statusVal = 1; elseif ($s==='done') $statusVal = 2;
}
$hasInfo = showHasColumn('information');
$infoSelect = $hasInfo ? 'sh.information AS show_information' : 'NULL AS show_information';
$base = "FROM episodes e
JOIN seasons se ON se.id = e.season_id
JOIN shows sh ON sh.id = se.show_id
@@ -1018,6 +1040,7 @@ try {
sh.poster_path AS poster_path,
sh.id AS show_id,
sh.download_path AS download_path,
".$infoSelect.",
JSON_UNQUOTE(JSON_EXTRACT(sh.json, '$.status')) AS show_status,
sh.cliffhanger AS show_cliffhanger,
sh.json AS show_json,
@@ -1029,6 +1052,7 @@ try {
sh.poster_path AS poster_path,
sh.id AS show_id,
sh.download_path AS download_path,
".$infoSelect.",
sh.cliffhanger AS show_cliffhanger,
sh.json AS show_json,
se.season_number, sh.name AS show_name ".$base;
@@ -1176,6 +1200,8 @@ try {
case 'get_show_episodes': {
$showId = (int)($in['show_id'] ?? 0);
if (!$showId) fail('bad params');
$hasInfo = showHasColumn('information');
$infoSelect = $hasInfo ? 'sh.information AS show_information' : 'NULL AS show_information';
$base = "FROM episodes e
JOIN seasons se ON se.id = e.season_id
JOIN shows sh ON sh.id = se.show_id
@@ -1186,6 +1212,7 @@ try {
sh.poster_path AS poster_path,
sh.id AS show_id,
sh.download_path AS download_path,
".$infoSelect.",
JSON_UNQUOTE(JSON_EXTRACT(sh.json, '$.status')) AS show_status,
sh.cliffhanger AS show_cliffhanger,
sh.json AS show_json,
@@ -1197,6 +1224,7 @@ try {
sh.poster_path AS poster_path,
sh.id AS show_id,
sh.download_path AS download_path,
".$infoSelect.",
sh.cliffhanger AS show_cliffhanger,
sh.json AS show_json,
se.season_number, sh.name AS show_name ".$base.
@@ -1324,9 +1352,15 @@ try {
if (!$showId) fail('bad params');
$fields = [];
$params = [];
$hasInfo = showHasColumn('information');
if (isset($in['resolution'])) { $fields[] = 'resolution = ?'; $params[] = $in['resolution']; }
if (array_key_exists('download_path', $in)) { $fields[] = 'download_path = ?'; $params[] = $in['download_path']; }
if (isset($in['cliffhanger'])) { $fields[] = 'cliffhanger = ?'; $params[] = (int)!!$in['cliffhanger']; }
if (array_key_exists('information', $in)) {
if (!$hasInfo) fail('shows.information column missing');
$fields[] = 'information = ?';
$params[] = $in['information'];
}
if (empty($fields)) fail('no fields');
$sql = 'UPDATE shows SET '.implode(', ', $fields).' WHERE id = ?';
$params[] = $showId;