diff --git a/api.php b/api.php index 2677605..cec4b1d 100644 --- a/api.php +++ b/api.php @@ -579,12 +579,26 @@ case 'get_config_keys': ]); $imported++; } - } else { +} else { + // CORRECTION : Initialisation des variables manquantes + $stmtCritiques = $pdo->prepare("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)"); + $tmdbApiKey = getTmdbApiKey($pdo); + + foreach ($items as $rowData) { + $title = $rowData['Title'] ?? $rowData['title'] ?? ''; + if (empty($title)) continue; + + $year = $rowData['Year'] ?? $rowData['year'] ?? ''; + $id = makeStableId('critique', $title, $year); + $ratingRaw = $rowData['Rating'] ?? $rowData['rating'] ?? ''; $rating = ($ratingRaw !== '' && $ratingRaw !== null) ? (float)$ratingRaw : null; $review = $rowData['Review'] ?? $rowData['review'] ?? ''; $director = ''; $poster = ''; $streaming = ''; - + if ($tmdbApiKey && !empty($title)) { $tmdbData = fetchTMDBFull($title, $year, $tmdbApiKey, $pdo); if ($tmdbData) { @@ -596,10 +610,11 @@ case 'get_config_keys': } } if (empty($streaming)) $streaming = 'Support physique / Cinéma'; - + $stmtCritiques->execute([$id, $title, $year, $director, $poster, $rating, $review, $streaming]); + $imported++; } - $imported++; + } $pdo->commit(); echo json_encode(["success" => true, "imported" => $imported]); break;