mirror of
https://codeberg.org/PostERG/xamxam.git
synced 2026-05-06 19:19:19 +02:00
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:
124
src/Database.php
124
src/Database.php
@@ -425,51 +425,27 @@ class Database {
|
||||
/**
|
||||
* Get all orientations
|
||||
*/
|
||||
public function getOrientations() {
|
||||
$sql = "SELECT * FROM orientations ORDER BY name";
|
||||
$stmt = $this->pdo->query($sql);
|
||||
public function getAllOrientations(): array {
|
||||
$stmt = $this->pdo->query("SELECT * FROM orientations ORDER BY name");
|
||||
return $stmt->fetchAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* Alias for formulaire compatibility
|
||||
*/
|
||||
public function getAllOrientations() {
|
||||
return $this->getOrientations();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all AP programs
|
||||
*/
|
||||
public function getApPrograms() {
|
||||
$sql = "SELECT * FROM ap_programs ORDER BY name";
|
||||
$stmt = $this->pdo->query($sql);
|
||||
public function getAllAPPrograms(): array {
|
||||
$stmt = $this->pdo->query("SELECT * FROM ap_programs ORDER BY name");
|
||||
return $stmt->fetchAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* Alias for formulaire compatibility
|
||||
*/
|
||||
public function getAllAPPrograms() {
|
||||
return $this->getApPrograms();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all finality types
|
||||
*/
|
||||
public function getFinalityTypes() {
|
||||
$sql = "SELECT * FROM finality_types ORDER BY name";
|
||||
$stmt = $this->pdo->query($sql);
|
||||
public function getAllFinalityTypes(): array {
|
||||
$stmt = $this->pdo->query("SELECT * FROM finality_types ORDER BY name");
|
||||
return $stmt->fetchAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* Alias for formulaire compatibility
|
||||
*/
|
||||
public function getAllFinalityTypes() {
|
||||
return $this->getFinalityTypes();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all keywords used in published theses
|
||||
*/
|
||||
@@ -483,43 +459,22 @@ class Database {
|
||||
return $stmt->fetchAll();
|
||||
}
|
||||
|
||||
/** Backwards-compat alias */
|
||||
public function getUsedKeywords(): array {
|
||||
return $this->getUsedTags();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all format types
|
||||
*/
|
||||
public function getFormatTypes() {
|
||||
$sql = "SELECT * FROM format_types ORDER BY name";
|
||||
$stmt = $this->pdo->query($sql);
|
||||
public function getAllFormatTypes(): array {
|
||||
$stmt = $this->pdo->query("SELECT * FROM format_types ORDER BY name");
|
||||
return $stmt->fetchAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* Alias for formulaire compatibility
|
||||
*/
|
||||
public function getAllFormatTypes() {
|
||||
return $this->getFormatTypes();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all languages
|
||||
*/
|
||||
public function getLanguages() {
|
||||
$sql = "SELECT * FROM languages ORDER BY name";
|
||||
$stmt = $this->pdo->query($sql);
|
||||
public function getAllLanguages(): array {
|
||||
$stmt = $this->pdo->query("SELECT * FROM languages ORDER BY name");
|
||||
return $stmt->fetchAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* Alias for formulaire compatibility
|
||||
*/
|
||||
public function getAllLanguages() {
|
||||
return $this->getLanguages();
|
||||
}
|
||||
|
||||
// ========================================================================
|
||||
// ADMIN LIST METHOD
|
||||
// ========================================================================
|
||||
@@ -649,10 +604,7 @@ class Database {
|
||||
return (int)$this->pdo->lastInsertId();
|
||||
}
|
||||
|
||||
/** Backwards-compat alias */
|
||||
public function findOrCreateKeyword($keyword): ?int {
|
||||
return $this->findOrCreateTag((string)$keyword);
|
||||
}
|
||||
|
||||
|
||||
// ========================================================================
|
||||
// TAG MANAGEMENT (admin)
|
||||
@@ -720,52 +672,7 @@ class Database {
|
||||
/**
|
||||
* Get orientation ID by name
|
||||
*/
|
||||
public function getOrientationId($name) {
|
||||
$stmt = $this->pdo->prepare("SELECT id FROM orientations WHERE name = ?");
|
||||
$stmt->execute([$name]);
|
||||
$result = $stmt->fetch();
|
||||
return $result ? $result['id'] : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get AP program ID by name
|
||||
*/
|
||||
public function getAPProgramId($name) {
|
||||
$stmt = $this->pdo->prepare("SELECT id FROM ap_programs WHERE name = ?");
|
||||
$stmt->execute([$name]);
|
||||
$result = $stmt->fetch();
|
||||
return $result ? $result['id'] : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get finality type ID by name
|
||||
*/
|
||||
public function getFinalityId($name) {
|
||||
$stmt = $this->pdo->prepare("SELECT id FROM finality_types WHERE name = ?");
|
||||
$stmt->execute([$name]);
|
||||
$result = $stmt->fetch();
|
||||
return $result ? $result['id'] : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get language ID by name
|
||||
*/
|
||||
public function getLanguageId($name) {
|
||||
$stmt = $this->pdo->prepare("SELECT id FROM languages WHERE name = ?");
|
||||
$stmt->execute([$name]);
|
||||
$result = $stmt->fetch();
|
||||
return $result ? $result['id'] : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get format type ID by name
|
||||
*/
|
||||
public function getFormatId($name) {
|
||||
$stmt = $this->pdo->prepare("SELECT id FROM format_types WHERE name = ?");
|
||||
$stmt->execute([$name]);
|
||||
$result = $stmt->fetch();
|
||||
return $result ? $result['id'] : null;
|
||||
}
|
||||
|
||||
// ========================================================================
|
||||
// STATIC PAGES METHODS
|
||||
@@ -814,18 +721,11 @@ class Database {
|
||||
/**
|
||||
* Get all license types ordered by name
|
||||
*/
|
||||
public function getLicenseTypes(): array {
|
||||
public function getAllLicenseTypes(): array {
|
||||
$stmt = $this->pdo->query("SELECT * FROM license_types ORDER BY name");
|
||||
return $stmt->fetchAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* Alias for form-loading consistency
|
||||
*/
|
||||
public function getAllLicenseTypes(): array {
|
||||
return $this->getLicenseTypes();
|
||||
}
|
||||
|
||||
// ========================================================================
|
||||
// VISIBILITY METHODS
|
||||
// ========================================================================
|
||||
|
||||
Reference in New Issue
Block a user