Actualiser api.php

This commit is contained in:
2026-06-24 13:11:18 +02:00
parent b4b314321b
commit 581a473394
+6 -16
View File
@@ -429,7 +429,7 @@ switch ($action) {
$imported = 0; $imported = 0;
$debugLog = []; $debugLog = [];
$pdo->beginTransaction(); // 🔥 UNE SEULE transaction $pdo->beginTransaction(); // 🔥 UNE SEULE TRANSACTION
try { try {
foreach ($items as $rowData) { foreach ($items as $rowData) {
$title = $rowData['title'] ?? $rowData['Name'] ?? $rowData['Title'] ?? 'Sans titre'; $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]); $stmt->execute([$id, $title, $year, $director, $poster, $format, $length, $publisher, $ean, $discs, $aspect, $description, $actors]);
} else { } else {
// ── IMPORT DES CRITIQUES ── // Pour les critiques
$ratingRaw = $rowData['Rating'] ?? $rowData['rating'] ?? ''; $ratingRaw = $rowData['Rating'] ?? $rowData['rating'] ?? '';
$rating = ($ratingRaw !== '' && $ratingRaw !== null) ? (float)$ratingRaw : null; $rating = ($ratingRaw !== '' && $ratingRaw !== null) ? (float)$ratingRaw : null;
$review = $rowData['Review'] ?? $rowData['review'] ?? ''; $review = $rowData['Review'] ?? $rowData['review'] ?? '';
$director = ''; $poster = ''; $streaming = ''; $director = ''; $poster = ''; $streaming = '';
if ($tmdbApiKey && !empty($title)) { 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); $tmdbData = fetchTMDBFull($title, $year, $tmdbApiKey, $pdo);
}
if ($tmdbData) { if ($tmdbData) {
$director = $tmdbData['director'] ?? ''; $director = $tmdbData['director'];
$poster = $tmdbData['poster'] ?? ''; $poster = $tmdbData['poster'];
$streaming = $tmdbData['streaming'] ?? ''; $streaming = $tmdbData['streaming'];
if (empty($year) && !empty($tmdbData['year'])) $year = $tmdbData['year']; if (empty($year)) $year = $tmdbData['year'];
// 🔥 Récupération du titre français
if (!empty($tmdbData['title'])) $title = $tmdbData['title']; if (!empty($tmdbData['title'])) $title = $tmdbData['title'];
} }
} }
if (empty($streaming)) $streaming = 'Support physique / Cinéma'; if (empty($streaming)) $streaming = 'Support physique / Cinéma';
$sql = "INSERT INTO critiques (id, title, year, director, poster, rating, review, streaming) $sql = "INSERT INTO critiques (id, title, year, director, poster, rating, review, streaming)