Actualiser api.php
This commit is contained in:
@@ -429,7 +429,7 @@ switch ($action) {
|
||||
$imported = 0;
|
||||
$debugLog = [];
|
||||
|
||||
$pdo->beginTransaction(); // 🔥 UNE SEULE transaction
|
||||
$pdo->beginTransaction(); // 🔥 UNE SEULE TRANSACTION
|
||||
try {
|
||||
foreach ($items as $rowData) {
|
||||
$title = $rowData['title'] ?? $rowData['Name'] ?? $rowData['Title'] ?? 'Sans titre';
|
||||
@@ -528,32 +528,22 @@ switch ($action) {
|
||||
$stmt->execute([$id, $title, $year, $director, $poster, $format, $length, $publisher, $ean, $discs, $aspect, $description, $actors]);
|
||||
|
||||
} else {
|
||||
// ── IMPORT DES CRITIQUES ──
|
||||
// Pour les critiques
|
||||
$ratingRaw = $rowData['Rating'] ?? $rowData['rating'] ?? '';
|
||||
$rating = ($ratingRaw !== '' && $ratingRaw !== null) ? (float)$ratingRaw : null;
|
||||
$review = $rowData['Review'] ?? $rowData['review'] ?? '';
|
||||
$director = ''; $poster = ''; $streaming = '';
|
||||
|
||||
if ($tmdbApiKey && !empty($title)) {
|
||||
// 🔥 Nettoyage du titre pour TMDB
|
||||
$tmdbTitle = preg_replace('/\s*[\[\(].*?[\]\)]\s*/', '', $title);
|
||||
$tmdbTitle = trim($tmdbTitle);
|
||||
|
||||
$tmdbData = fetchTMDBFull($tmdbTitle, $year, $tmdbApiKey, $pdo);
|
||||
if (!$tmdbData && $tmdbTitle !== $title) {
|
||||
$tmdbData = fetchTMDBFull($title, $year, $tmdbApiKey, $pdo);
|
||||
}
|
||||
|
||||
if ($tmdbData) {
|
||||
$director = $tmdbData['director'] ?? '';
|
||||
$poster = $tmdbData['poster'] ?? '';
|
||||
$streaming = $tmdbData['streaming'] ?? '';
|
||||
if (empty($year) && !empty($tmdbData['year'])) $year = $tmdbData['year'];
|
||||
// 🔥 Récupération du titre français
|
||||
$director = $tmdbData['director'];
|
||||
$poster = $tmdbData['poster'];
|
||||
$streaming = $tmdbData['streaming'];
|
||||
if (empty($year)) $year = $tmdbData['year'];
|
||||
if (!empty($tmdbData['title'])) $title = $tmdbData['title'];
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($streaming)) $streaming = 'Support physique / Cinéma';
|
||||
|
||||
$sql = "INSERT INTO critiques (id, title, year, director, poster, rating, review, streaming)
|
||||
|
||||
Reference in New Issue
Block a user