From 877e3225682d4d074f0e5d75e79aa8cc32753068 Mon Sep 17 00:00:00 2001 From: Pontoporeia Date: Tue, 31 Mar 2026 16:37:14 +0200 Subject: [PATCH] fix(import): set is_published=1 and map access_type_id on CSV import MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Imported theses were invisible on the public site because: 1. is_published defaulted to 0 (schema default) — the INSERT never set it, so all imported rows stayed unpublished and were filtered out by v_theses_public (WHERE is_published = 1) and every public DB method. 2. The access column (CSV col 16 'Autorisation') was read into $access but never written to access_type_id — silently dropped. Fix: INSERT now includes is_published = 1 and access_type_id (resolved from access_types.name via ucfirst/strtolower normalisation, defaulting to 1/Libre when the CSV cell is empty or unrecognised). --- TODO.md | 1 + public/admin/import.php | 20 ++++++++++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/TODO.md b/TODO.md index b96a404..a19f76b 100644 --- a/TODO.md +++ b/TODO.md @@ -5,3 +5,4 @@ - [x] Auto-migrate both test.db and posterg.db on `just serve` via scripts/migrate.sh - [x] Fix wrong `require_once` depth in `public/admin/actions/page.php` (`../../` → `../../../`) - [x] Fix same path depth bug in `formulaire.php` and `publish.php` +- [x] Fix CSV import: imported theses not visible on public site (is_published defaulted to 0, access_type_id never set) diff --git a/public/admin/import.php b/public/admin/import.php index e6da398..0cab481 100644 --- a/public/admin/import.php +++ b/public/admin/import.php @@ -168,6 +168,20 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_FILES['csv_file'])) { $finalityId = $rowFin ? $rowFin['id'] : null; } + // Map access type (Autorisation column) + // CSV values are expected to match access_types.name: "Libre", "Interne", "Interdit" + $accessTypeId = null; + if (!empty($access)) { + $stmtAcc = $pdo->prepare("SELECT id FROM access_types WHERE name = ?"); + $stmtAcc->execute([ucfirst(strtolower($access))]); + $rowAcc = $stmtAcc->fetch(); + $accessTypeId = $rowAcc ? $rowAcc['id'] : null; + } + // Default to Libre (id=1) when not specified so imported theses are visible + if ($accessTypeId === null) { + $accessTypeId = 1; + } + // Skip if identifier already exists if (!empty($identifier)) { $stmtCheck = $pdo->prepare("SELECT id FROM theses WHERE identifier = ?"); @@ -187,8 +201,9 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_FILES['csv_file'])) { orientation_id, ap_program_id, finality_id, synopsis, context_note, remarks, file_size_info, jury_points, baiu_link, + access_type_id, is_published, submitted_at - ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, CURRENT_TIMESTAMP) + ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 1, CURRENT_TIMESTAMP) "); $stmt->execute([ @@ -204,7 +219,8 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_FILES['csv_file'])) { !empty($remarks) ? $remarks : null, !empty($sizeInfo) ? $sizeInfo : null, $juryPoints, - !empty($baiuLink) ? $baiuLink : null + !empty($baiuLink) ? $baiuLink : null, + $accessTypeId ]); $thesisId = $pdo->lastInsertId();