Actualiser api.php

This commit is contained in:
2026-06-24 09:24:24 +02:00
parent 000a8b89bd
commit 03735b21fe
+34 -8
View File
@@ -410,12 +410,15 @@ switch ($action) {
$firstName = $rowData['first_name'] ?? ''; $firstName = $rowData['first_name'] ?? '';
$lastName = $rowData['last_name'] ?? ''; $lastName = $rowData['last_name'] ?? '';
$creators = $rowData['creators'] ?? ''; $creators = $rowData['creators'] ?? '';
$director = ''; // 🔥 CORRECTION : Dans ce format CSV, first_name/last_name/creators sont les ACTEURS, pas le réalisateur.
// Bug 4 : dans le format CSV vidéothèque (ex: CLZ/Collectorz), creators et // On laisse $director vide pour que TMDB récupère le vrai réalisateur.
// first_name/last_name contiennent les ACTEURS, pas le réalisateur. $director = '';
// On laisse $director vide pour laisser TMDB trouver le vrai réalisateur. $csvActors = $rowData['ensemble'] ?? $rowData['creators'] ?? '';
// Exception : si ensemble est vide, creators peut servir de fallback acteurs. $actors = '';
unset($firstName, $lastName); // non utilisés volontairement if (!empty($csvActors)) {
$actorsArray = array_map('trim', explode(',', $csvActors));
$actors = implode(', ', array_slice($actorsArray, 0, 4));
}
$ean = $rowData['ean_isbn13'] ?? $rowData['EAN'] ?? ''; $ean = $rowData['ean_isbn13'] ?? $rowData['EAN'] ?? '';
// Bug 1 : EAN peut arriver comme float "7321950374984.0", on normalise en entier string // Bug 1 : EAN peut arriver comme float "7321950374984.0", on normalise en entier string
@@ -493,7 +496,22 @@ switch ($action) {
// INSERT toujours exécuté, EAN présent ou non // INSERT toujours exécuté, EAN présent ou non
try { try {
$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 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)"; // 🔥 CORRECTION : On n'écrase pas le titre et l'année s'ils existent déjà, mais on les met à jour si le CSV change.
// Le réalisateur est forcé à vide au début pour laisser TMDB trouver le vrai réalisateur (car le CSV contient les acteurs).
$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, $title, $year, $director, $poster, $format, $length, $publisher, $ean, $discs, $aspect, $description, $actors]); $stmt->execute([$id, $title, $year, $director, $poster, $format, $length, $publisher, $ean, $discs, $aspect, $description, $actors]);
} catch (\Exception $e) { } catch (\Exception $e) {
@@ -523,7 +541,15 @@ switch ($action) {
$streaming = 'Support physique / Cinéma'; $streaming = 'Support physique / Cinéma';
} }
$sql = "INSERT INTO critiques (id, title, year, director, poster, rating, review, streaming) VALUES (?, ?, ?, ?, ?, ?, ?, ?) ON DUPLICATE KEY UPDATE rating=VALUES(rating), review=IF(VALUES(review)!='',VALUES(review),review), director=IF(VALUES(director)!='',VALUES(director),director), poster=IF(VALUES(poster)!='',VALUES(poster),poster), streaming=IF(VALUES(streaming)!='',VALUES(streaming),streaming)"; $sql = "INSERT INTO critiques (id, title, year, director, poster, rating, review, streaming)
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
ON DUPLICATE KEY UPDATE
title=VALUES(title), year=VALUES(year),
rating=VALUES(rating),
review=IF(VALUES(review)!='',VALUES(review),review),
director=IF(VALUES(director)!='',VALUES(director),director),
poster=IF(VALUES(poster)!='',VALUES(poster),poster),
streaming=IF(VALUES(streaming)!='',VALUES(streaming),streaming)";
$stmt = $pdo->prepare($sql); $stmt = $pdo->prepare($sql);
$stmt->execute([$id, $title, $year, $director, $poster, $rating, $review, $streaming]); $stmt->execute([$id, $title, $year, $director, $poster, $rating, $review, $streaming]);
} }