Actualiser api.php
This commit is contained in:
@@ -171,7 +171,8 @@ function fetchPhysicalFromUpcitemdb($ean) {
|
|||||||
'length' => ''
|
'length' => ''
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
unction fetchPhysicalFromUpcmdb($ean, $pdo) {
|
|
||||||
|
function fetchPhysicalFromUpcmdb($ean, $pdo) {
|
||||||
$empty = ['title'=>'','publisher'=>'','format'=>'','length'=>'','number_of_discs'=>1,'aspect_ratio'=>'','year'=>''];
|
$empty = ['title'=>'','publisher'=>'','format'=>'','length'=>'','number_of_discs'=>1,'aspect_ratio'=>'','year'=>''];
|
||||||
$apiKey = getUpcmdbApiKey($pdo);
|
$apiKey = getUpcmdbApiKey($pdo);
|
||||||
if (!$apiKey) return $empty;
|
if (!$apiKey) return $empty;
|
||||||
@@ -199,7 +200,6 @@ unction fetchPhysicalFromUpcmdb($ean, $pdo) {
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function fetchPhysicalByEan($ean, $pdo = null) {
|
function fetchPhysicalByEan($ean, $pdo = null) {
|
||||||
$res = fetchPhysicalFromUpcitemdb($ean);
|
$res = fetchPhysicalFromUpcitemdb($ean);
|
||||||
if (!empty($res['title'])) return $res;
|
if (!empty($res['title'])) return $res;
|
||||||
@@ -403,7 +403,8 @@ case 'save_config':
|
|||||||
ORDER BY id DESC
|
ORDER BY id DESC
|
||||||
";
|
";
|
||||||
$result = $pdo->query($sql)->fetchAll();
|
$result = $pdo->query($sql)->fetchAll();
|
||||||
foreach ($result as $row) {
|
// IMPORTANT : Utilisation du pointeur `&` pour que la modification soit effective dans $result
|
||||||
|
foreach ($result as &$row) {
|
||||||
if ($row['rating'] !== null) {
|
if ($row['rating'] !== null) {
|
||||||
$ratingVal = (float)$row['rating'];
|
$ratingVal = (float)$row['rating'];
|
||||||
$row['rating'] = ($ratingVal == floor($ratingVal)) ? (int)$ratingVal : $ratingVal;
|
$row['rating'] = ($ratingVal == floor($ratingVal)) ? (int)$ratingVal : $ratingVal;
|
||||||
@@ -432,24 +433,24 @@ case 'save_config':
|
|||||||
$sql = "INSERT INTO critiques (id, title, year, director, poster, rating, review, streaming) VALUES (?, ?, ?, ?, ?, ?, ?, ?) ON DUPLICATE KEY UPDATE title=VALUES(title), year=VALUES(year), director=VALUES(director), poster=VALUES(poster), rating=VALUES(rating), review=VALUES(review), streaming=VALUES(streaming)";
|
$sql = "INSERT INTO critiques (id, title, year, director, poster, rating, review, streaming) VALUES (?, ?, ?, ?, ?, ?, ?, ?) ON DUPLICATE KEY UPDATE title=VALUES(title), year=VALUES(year), director=VALUES(director), poster=VALUES(poster), rating=VALUES(rating), review=VALUES(review), streaming=VALUES(streaming)";
|
||||||
$stmt = $pdo->prepare($sql);
|
$stmt = $pdo->prepare($sql);
|
||||||
$stmt->execute([$id, $data['title'] ?? '', $data['year'] ?? '', $data['director'] ?? '', $data['poster'] ?? '', $data['rating'] ?? 3.0, $data['review'] ?? '', $streaming]);
|
$stmt->execute([$id, $data['title'] ?? '', $data['year'] ?? '', $data['director'] ?? '', $data['poster'] ?? '', $data['rating'] ?? 3.0, $data['review'] ?? '', $streaming]);
|
||||||
} else {
|
} else {
|
||||||
// ── CORRECTION : Suppression de fetchBluRayPhysicalInfo qui n'existe pas ──
|
// ── CORRECTION : Suppression de fetchBluRayPhysicalInfo qui n'existe pas ──
|
||||||
if (empty($data['poster']) && !empty($data['title'])) {
|
if (empty($data['poster']) && !empty($data['title'])) {
|
||||||
$tmdbData = fetchTmdbPosterAndSynopsis($data['title'], $data['year'] ?? '', $pdo);
|
$tmdbData = fetchTmdbPosterAndSynopsis($data['title'], $data['year'] ?? '', $pdo);
|
||||||
|
|
||||||
if ($tmdbData['poster'] !== 'assets/img/default_physical_media.jpg') {
|
if ($tmdbData['poster'] !== 'assets/img/default_physical_media.jpg') {
|
||||||
$data['poster'] = $tmdbData['poster'];
|
$data['poster'] = $tmdbData['poster'];
|
||||||
}
|
}
|
||||||
if (empty($data['description'])) $data['description'] = $tmdbData['description'];
|
if (empty($data['description'])) $data['description'] = $tmdbData['description'];
|
||||||
if (empty($data['director'])) $data['director'] = $tmdbData['director'];
|
if (empty($data['director'])) $data['director'] = $tmdbData['director'];
|
||||||
if (empty($data['actors'])) $data['actors'] = $tmdbData['actors'];
|
if (empty($data['actors'])) $data['actors'] = $tmdbData['actors'];
|
||||||
if (empty($data['length'])) $data['length'] = $tmdbData['length'];
|
if (empty($data['length'])) $data['length'] = $tmdbData['length'];
|
||||||
if (empty($data['format'])) $data['format'] = detectFormat($data['title'], $data['description'] ?? '');
|
if (empty($data['format'])) $data['format'] = detectFormat($data['title'], $data['description'] ?? '');
|
||||||
}
|
}
|
||||||
|
|
||||||
$sql = "INSERT INTO videotheque (id, title, year, director, poster, format, length, publisher, ean_isbn13, number_of_discs, aspect_ratio, description, actors) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) ON DUPLICATE KEY UPDATE title=VALUES(title), year=VALUES(year), director=IF(VALUES(director)!='', VALUES(director), director), poster=IF(VALUES(poster)!='', VALUES(poster), poster), format=IF(VALUES(format)!='', VALUES(format), format), length=IF(VALUES(length)!='', VALUES(length), length), publisher=IF(VALUES(publisher)!='', VALUES(publisher), publisher), ean_isbn13=IF(VALUES(ean_isbn13)!='', VALUES(ean_isbn13), ean_isbn13), number_of_discs=IF(VALUES(number_of_discs)!=1, VALUES(number_of_discs), number_of_discs), aspect_ratio=IF(VALUES(aspect_ratio)!='', VALUES(aspect_ratio), aspect_ratio), description=IF(VALUES(description)!='', VALUES(description), description), actors=IF(VALUES(actors)!='', VALUES(actors), actors)";
|
$sql = "INSERT INTO videotheque (id, title, year, director, poster, format, length, publisher, ean_isbn13, number_of_discs, aspect_ratio, description, actors) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) ON DUPLICATE KEY UPDATE title=VALUES(title), year=VALUES(year), director=IF(VALUES(director)!='', VALUES(director), director), poster=IF(VALUES(poster)!='', VALUES(poster), poster), format=IF(VALUES(format)!='', VALUES(format), format), length=IF(VALUES(length)!='', VALUES(length), length), publisher=IF(VALUES(publisher)!='', VALUES(publisher), publisher), ean_isbn13=IF(VALUES(ean_isbn13)!='', VALUES(ean_isbn13), ean_isbn13), number_of_discs=IF(VALUES(number_of_discs)!=1, VALUES(number_of_discs), number_of_discs), aspect_ratio=IF(VALUES(aspect_ratio)!='', VALUES(aspect_ratio), aspect_ratio), description=IF(VALUES(description)!='', VALUES(description), description), actors=IF(VALUES(actors)!='', VALUES(actors), actors)";
|
||||||
$stmt = $pdo->prepare($sql);
|
$stmt = $pdo->prepare($sql);
|
||||||
$stmt->execute([$id, $data['title'] ?? '', $data['year'] ?? '', $data['director'] ?? '', $data['poster'] ?? '', $data['format'] ?? '', $data['length'] ?? '', $data['publisher'] ?? '', $data['ean_isbn13'] ?? '', $data['number_of_discs'] ?? 1, $data['aspect_ratio'] ?? '', $data['description'] ?? '', $data['actors'] ?? '']);
|
$stmt->execute([$id, $data['title'] ?? '', $data['year'] ?? '', $data['director'] ?? '', $data['poster'] ?? '', $data['format'] ?? '', $data['length'] ?? '', $data['publisher'] ?? '', $data['ean_isbn13'] ?? '', $data['number_of_discs'] ?? 1, $data['aspect_ratio'] ?? '', $data['description'] ?? '', $data['actors'] ?? '']);
|
||||||
}
|
}
|
||||||
echo json_encode(["success" => true]);
|
echo json_encode(["success" => true]);
|
||||||
break;
|
break;
|
||||||
@@ -553,5 +554,4 @@ case 'import_batch':
|
|||||||
echo json_encode(["success" => false, "error" => $e->getMessage(), "line" => $e->getLine()]);
|
echo json_encode(["success" => false, "error" => $e->getMessage(), "line" => $e->getLine()]);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
?>
|
|
||||||
Reference in New Issue
Block a user