fix(import): set is_published=1 and map access_type_id on CSV import

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).
This commit is contained in:
Pontoporeia
2026-03-31 16:37:14 +02:00
parent 72d48c49c3
commit 877e322568
2 changed files with 19 additions and 2 deletions

View File

@@ -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();