refactor(Database): remove dead CRUD helpers and alias proliferation

Remove 5 unused ID-lookup helpers (getOrientationId, getAPProgramId,
getFinalityId, getLanguageId, getFormatId) — forms have always passed
FK ids directly from <select> elements; these methods were never called
outside import.php, which now uses inline PDO queries instead.

Collapse 13 alias methods down to the single canonical name for each:
  getAllOrientations, getAllAPPrograms, getAllFinalityTypes,
  getAllFormatTypes, getAllLanguages, getAllLicenseTypes,
  getUsedTags, findOrCreateTag

The short-name variants (getOrientations, getApPrograms, etc.) and
compat aliases (getUsedKeywords, findOrCreateKeyword, getAllLicenseTypes
delegating to getLicenseTypes) are deleted. All call-sites updated:
  - public/search.php: getOrientations→getAllOrientations, etc.
  - public/admin/import.php: findOrCreateKeyword→findOrCreateTag,
    thesis_keywords→thesis_tags, keyword_id→tag_id (fixes stale table
    reference from pre-migration-001 that bypassed the M2M rename)
  - tests/Unit/DatabaseTest.php: remove alias smoke-test (test 7)

Database.php: 948 → 848 lines (-100).
This commit is contained in:
Pontoporeia
2026-03-28 11:35:23 +01:00
parent b0632b4772
commit 2e277b104e
5 changed files with 42 additions and 143 deletions

View File

@@ -142,7 +142,10 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_FILES['csv_file'])) {
$orientationName = isset($orientationMap[$orientationCode]) ? $orientationMap[$orientationCode] : null;
$orientationId = null;
if ($orientationName) {
$orientationId = $db->getOrientationId($orientationName);
$stmtOr = $pdo->prepare("SELECT id FROM orientations WHERE name = ?");
$stmtOr->execute([$orientationName]);
$rowOr = $stmtOr->fetch();
$orientationId = $rowOr ? $rowOr['id'] : null;
}
// Map AP program
@@ -159,7 +162,10 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_FILES['csv_file'])) {
// Map finality
$finalityId = null;
if (!empty($finalityName)) {
$finalityId = $db->getFinalityId($finalityName);
$stmtFin = $pdo->prepare("SELECT id FROM finality_types WHERE name = ?");
$stmtFin->execute([$finalityName]);
$rowFin = $stmtFin->fetch();
$finalityId = $rowFin ? $rowFin['id'] : null;
}
// Insert thesis
@@ -221,10 +227,10 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_FILES['csv_file'])) {
$keywords = array_slice($keywords, 0, 10); // Max 10
foreach ($keywords as $keyword) {
if (!empty($keyword)) {
$keywordId = $db->findOrCreateKeyword($keyword);
if ($keywordId) {
$stmt = $pdo->prepare("INSERT INTO thesis_keywords (thesis_id, keyword_id) VALUES (?, ?)");
$stmt->execute([$thesisId, $keywordId]);
$tagId = $db->findOrCreateTag($keyword);
if ($tagId) {
$stmtTag = $pdo->prepare("INSERT INTO thesis_tags (thesis_id, tag_id) VALUES (?, ?)");
$stmtTag->execute([$thesisId, $tagId]);
}
}
}
@@ -232,7 +238,10 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_FILES['csv_file'])) {
// Add language
if (!empty($languageRaw)) {
$languageId = $db->getLanguageId(ucfirst(strtolower($languageRaw)));
$stmtLang = $pdo->prepare("SELECT id FROM languages WHERE name = ?");
$stmtLang->execute([ucfirst(strtolower($languageRaw))]);
$rowLang = $stmtLang->fetch();
$languageId = $rowLang ? $rowLang['id'] : null;
if ($languageId) {
$stmt = $pdo->prepare("INSERT INTO thesis_languages (thesis_id, language_id) VALUES (?, ?)");
$stmt->execute([$thesisId, $languageId]);
@@ -244,7 +253,10 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_FILES['csv_file'])) {
$formats = array_map('trim', explode(',', $formatsRaw));
foreach ($formats as $formatName) {
if (!empty($formatName)) {
$formatId = $db->getFormatId(ucfirst(strtolower($formatName)));
$stmtFmt = $pdo->prepare("SELECT id FROM format_types WHERE name = ?");
$stmtFmt->execute([ucfirst(strtolower($formatName))]);
$rowFmt = $stmtFmt->fetch();
$formatId = $rowFmt ? $rowFmt['id'] : null;
if ($formatId) {
$stmt = $pdo->prepare("INSERT INTO thesis_formats (thesis_id, format_id) VALUES (?, ?)");
$stmt->execute([$thesisId, $formatId]);

View File

@@ -43,9 +43,9 @@ try {
}
$years = $db->getAvailableYears();
$orientations = $db->getOrientations();
$apPrograms = $db->getApPrograms();
$keywords = $db->getUsedKeywords();
$orientations = $db->getAllOrientations();
$apPrograms = $db->getAllAPPrograms();
$keywords = $db->getUsedTags();
// Fetch all published theses for the student index (no artificial cap)
$students = $db->getAllPublishedTheses();
} catch (InvalidArgumentException $e) {