mirror of
https://codeberg.org/PostERG/xamxam.git
synced 2026-05-06 11:09:18 +02:00
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:
1
TODO.md
1
TODO.md
@@ -5,3 +5,4 @@
|
|||||||
- [x] Auto-migrate both test.db and posterg.db on `just serve` via scripts/migrate.sh
|
- [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 wrong `require_once` depth in `public/admin/actions/page.php` (`../../` → `../../../`)
|
||||||
- [x] Fix same path depth bug in `formulaire.php` and `publish.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)
|
||||||
|
|||||||
@@ -168,6 +168,20 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_FILES['csv_file'])) {
|
|||||||
$finalityId = $rowFin ? $rowFin['id'] : null;
|
$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
|
// Skip if identifier already exists
|
||||||
if (!empty($identifier)) {
|
if (!empty($identifier)) {
|
||||||
$stmtCheck = $pdo->prepare("SELECT id FROM theses WHERE 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,
|
orientation_id, ap_program_id, finality_id,
|
||||||
synopsis, context_note, remarks,
|
synopsis, context_note, remarks,
|
||||||
file_size_info, jury_points, baiu_link,
|
file_size_info, jury_points, baiu_link,
|
||||||
|
access_type_id, is_published,
|
||||||
submitted_at
|
submitted_at
|
||||||
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, CURRENT_TIMESTAMP)
|
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 1, CURRENT_TIMESTAMP)
|
||||||
");
|
");
|
||||||
|
|
||||||
$stmt->execute([
|
$stmt->execute([
|
||||||
@@ -204,7 +219,8 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_FILES['csv_file'])) {
|
|||||||
!empty($remarks) ? $remarks : null,
|
!empty($remarks) ? $remarks : null,
|
||||||
!empty($sizeInfo) ? $sizeInfo : null,
|
!empty($sizeInfo) ? $sizeInfo : null,
|
||||||
$juryPoints,
|
$juryPoints,
|
||||||
!empty($baiuLink) ? $baiuLink : null
|
!empty($baiuLink) ? $baiuLink : null,
|
||||||
|
$accessTypeId
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$thesisId = $pdo->lastInsertId();
|
$thesisId = $pdo->lastInsertId();
|
||||||
|
|||||||
Reference in New Issue
Block a user