From af06e09caa6f9fd45b2bc397e8309b84ee76860b Mon Sep 17 00:00:00 2001 From: Pontoporeia Date: Tue, 31 Mar 2026 16:17:22 +0200 Subject: [PATCH] fix(import): skip rows with duplicate identifier instead of crashing --- TODO.md | 1 + public/admin/import.php | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/TODO.md b/TODO.md index adebf6b..b538191 100644 --- a/TODO.md +++ b/TODO.md @@ -1,5 +1,6 @@ # TODO ## Fixes +- [x] Fix CSV import UNIQUE constraint crash: skip rows whose identifier already exists in DB - [x] Fix wrong `require_once` depth in `public/admin/actions/page.php` (`../../` → `../../../`) - [x] Fix same path depth bug in `formulaire.php` and `publish.php` diff --git a/public/admin/import.php b/public/admin/import.php index 237ed8f..e6da398 100644 --- a/public/admin/import.php +++ b/public/admin/import.php @@ -168,6 +168,18 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_FILES['csv_file'])) { $finalityId = $rowFin ? $rowFin['id'] : null; } + // Skip if identifier already exists + if (!empty($identifier)) { + $stmtCheck = $pdo->prepare("SELECT id FROM theses WHERE identifier = ?"); + $stmtCheck->execute([$identifier]); + if ($stmtCheck->fetch()) { + $db->rollback(); + $skippedCount++; + $importResults[] = "⚠ Ligne $lineNumber: identifiant \"$identifier\" déjà présent, ignoré."; + continue; + } + } + // Insert thesis $stmt = $pdo->prepare(" INSERT INTO theses (