mirror of
https://codeberg.org/PostERG/xamxam.git
synced 2026-06-27 00:59:18 +02:00
Error tests, FK violations fix
- ErrorHandler tests: 77 assertions covering FK extraction, normalization, dedup, edge cases. Fix FK table map for child tables. - Fix FK violation: (int)null → 0 in createThesis for orientation/ap/finality/license FK columns. Add FK value logging to updateThesis. - Add CURRENT_ISSUES.md with summary of FK violation, dev debugging, and tag dedup status for next conversation
This commit is contained in:
@@ -1134,6 +1134,39 @@ class Database
|
||||
// TAG MANAGEMENT (admin)
|
||||
// ========================================================================
|
||||
|
||||
/**
|
||||
* Search tags by name prefix. Returns up to 10 matching tags.
|
||||
* If $query is empty, returns the most-used tags (up to 10).
|
||||
*/
|
||||
public function searchTags(string $query = ''): array
|
||||
{
|
||||
$query = trim($query);
|
||||
if ($query === '') {
|
||||
$stmt = $this->pdo->query('
|
||||
SELECT tg.id, tg.name,
|
||||
COUNT(DISTINCT tt.thesis_id) as thesis_count
|
||||
FROM tags tg
|
||||
LEFT JOIN thesis_tags tt ON tg.id = tt.tag_id
|
||||
GROUP BY tg.id
|
||||
ORDER BY thesis_count DESC, tg.name COLLATE NOCASE
|
||||
LIMIT 10
|
||||
');
|
||||
} else {
|
||||
$stmt = $this->pdo->prepare('
|
||||
SELECT tg.id, tg.name,
|
||||
COUNT(DISTINCT tt.thesis_id) as thesis_count
|
||||
FROM tags tg
|
||||
LEFT JOIN thesis_tags tt ON tg.id = tt.tag_id
|
||||
WHERE tg.name LIKE ?
|
||||
GROUP BY tg.id
|
||||
ORDER BY tg.name = ? DESC, thesis_count DESC, tg.name COLLATE NOCASE
|
||||
LIMIT 10
|
||||
');
|
||||
$stmt->execute([$query . '%', $query]);
|
||||
}
|
||||
return $stmt->fetchAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all tags with a count of associated (published) theses.
|
||||
*/
|
||||
@@ -1740,19 +1773,27 @@ class Database
|
||||
updated_at = CURRENT_TIMESTAMP
|
||||
WHERE id = ?
|
||||
');
|
||||
$orientation = ($data['orientation_id'] ?? null) ? (int)$data['orientation_id'] : null;
|
||||
$ap = ($data['ap_program_id'] ?? null) ? (int)$data['ap_program_id'] : null;
|
||||
$finality = ($data['finality_id'] ?? null) ? (int)$data['finality_id'] : null;
|
||||
$license = $data['license_id'] ?? null;
|
||||
$access = $data['access_type_id'] ?? null;
|
||||
|
||||
error_log("[DB:updateThesis] thesis_id=$thesisId orientation=$orientation ap=$ap finality=$finality license=$license access=$access");
|
||||
|
||||
$stmt->execute([
|
||||
$data['title'],
|
||||
!empty($data['subtitle']) ? $data['subtitle'] : null,
|
||||
(int)$data['year'],
|
||||
($data['orientation_id'] ?? null) ? (int)$data['orientation_id'] : null,
|
||||
($data['ap_program_id'] ?? null) ? (int)$data['ap_program_id'] : null,
|
||||
($data['finality_id'] ?? null) ? (int)$data['finality_id'] : null,
|
||||
$orientation,
|
||||
$ap,
|
||||
$finality,
|
||||
$data['synopsis'],
|
||||
!empty($data['context_note']) ? $data['context_note'] : null,
|
||||
!empty($data['baiu_link']) ? $data['baiu_link'] : null,
|
||||
$data['license_id'] ?? null,
|
||||
$license,
|
||||
!empty($data['license_custom']) ? $data['license_custom'] : null,
|
||||
$data['access_type_id'] ?? null,
|
||||
$access,
|
||||
$data['is_published'] ? 1 : 0,
|
||||
!empty($data['remarks']) ? $data['remarks'] : null,
|
||||
isset($data['jury_points']) && $data['jury_points'] !== '' ? (float)$data['jury_points'] : null,
|
||||
@@ -1808,20 +1849,26 @@ class Database
|
||||
$validObjet = ['tfe', 'thèse', 'frart'];
|
||||
$objet = in_array($data['objet'] ?? '', $validObjet, true) ? $data['objet'] : 'tfe';
|
||||
|
||||
$orientation = $data['orientation_id'] ?? null;
|
||||
$ap = $data['ap_program_id'] ?? null;
|
||||
$finality = $data['finality_id'] ?? null;
|
||||
$license = $data['license_id'] ?? null;
|
||||
$access = $data['access_type_id'] ?? 2;
|
||||
|
||||
$stmt->execute([
|
||||
$identifier,
|
||||
$data['title'],
|
||||
!empty($data['subtitle']) ? $data['subtitle'] : null,
|
||||
(int)$data['year'],
|
||||
(int)$data['orientation_id'],
|
||||
(int)$data['ap_program_id'],
|
||||
(int)$data['finality_id'],
|
||||
$orientation ? (int)$orientation : null,
|
||||
$ap ? (int)$ap : null,
|
||||
$finality ? (int)$finality : null,
|
||||
$data['synopsis'],
|
||||
!empty($data['context_note']) ? $data['context_note'] : null,
|
||||
!empty($data['baiu_link']) ? $data['baiu_link'] : null,
|
||||
$data['license_id'] ?? null,
|
||||
$license ? (int)$license : null,
|
||||
!empty($data['license_custom']) ? $data['license_custom'] : null,
|
||||
isset($data['access_type_id']) ? (int)$data['access_type_id'] : 2, // default: Interne
|
||||
$access ? (int)$access : 2, // default: Interne
|
||||
$objet,
|
||||
!empty($data['remarks']) ? $data['remarks'] : null,
|
||||
isset($data['jury_points']) && $data['jury_points'] !== '' ? (float)$data['jury_points'] : null,
|
||||
|
||||
Reference in New Issue
Block a user