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:
Pontoporeia
2026-05-19 00:08:05 +02:00
parent a80b2c08bf
commit 6cc0e407f3
38 changed files with 1515 additions and 82 deletions
+35 -12
View File
@@ -36,6 +36,7 @@ class ThesisEditController
public static function create(?Database $db = null): self
{
require_once APP_ROOT . '/src/Database.php';
require_once APP_ROOT . '/src/ErrorHandler.php';
return new self($db ?? Database::getInstance());
}
@@ -192,7 +193,7 @@ class ThesisEditController
try {
// ── 1. Thesis metadata ────────────────────────────────────────────
$this->db->updateThesis($thesisId, [
$meta = [
'title' => trim($post['titre'] ?? ''),
'subtitle' => trim($post['subtitle'] ?? ''),
'year' => intval($post['année'] ?? 0),
@@ -211,7 +212,9 @@ class ThesisEditController
'exemplaire_erg' => !empty($post['exemplaire_erg']),
'cc2r' => !empty($post['cc2r']),
'license_custom' => trim($post['license_custom'] ?? ''),
]);
];
$this->db->updateThesis($thesisId, $meta);
error_log('[ThesisEdit] Step 1 OK — thesis_id=' . $thesisId);
// ── 2. Authors (alphabetically sorted) ─────────────────────────────
$authorsRaw = trim($post['auteurice'] ?? '');
@@ -230,10 +233,12 @@ class ThesisEditController
];
}
$this->db->setThesisAuthors($thesisId, $authorEntries);
error_log('[ThesisEdit] Step 2 OK — authors=' . json_encode($authorNames));
// ── 3. Jury ───────────────────────────────────────────────────────
$juryMembers = $this->collectJuryMembers($post);
$this->db->setThesisJury($thesisId, $juryMembers);
error_log('[ThesisEdit] Step 3 OK — jury=' . count($juryMembers));
// ── 4. Languages ──────────────────────────────────────────────────
$langIds = isset($post['languages']) && is_array($post['languages'])
@@ -248,25 +253,43 @@ class ThesisEditController
}
}
$this->db->setThesisLanguages($thesisId, $langIds);
error_log('[ThesisEdit] Step 4 OK — languages=' . json_encode($langIds));
// ── 5. Formats ────────────────────────────────────────────────────
$this->db->setThesisFormats(
$thesisId,
isset($post['formats']) && is_array($post['formats'])
? $post['formats']
: []
);
$formatIds = isset($post['formats']) && is_array($post['formats'])
? $post['formats']
: [];
$this->db->setThesisFormats($thesisId, $formatIds);
error_log('[ThesisEdit] Step 5 OK — formats=' . json_encode($formatIds));
// ── 6. Tags ───────────────────────────────────────────────────────
$keywordsRaw = trim($post['tag'] ?? '');
$keywords = $keywordsRaw !== ''
? array_map('trim', explode(',', $keywordsRaw))
: [];
$normalizeTag = fn(string $t): string => strtolower(trim(preg_replace('/\s+/', ' ', $t)));
$keywords = [];
if (isset($post['tag']) && is_array($post['tag'])) {
$keywords = array_values(array_unique(array_map(
$normalizeTag,
array_map(fn($t) => (string)$t, $post['tag'])
)));
} else {
$keywordsRaw = trim($post['tag'] ?? '');
if ($keywordsRaw !== '') {
$keywords = array_map($normalizeTag, explode(',', $keywordsRaw));
}
}
$keywords = array_values(array_unique($keywords));
$keywords = array_filter($keywords, fn($t) => $t !== '');
$keywords = array_slice($keywords, 0, 10);
if (count($keywords) < 3) {
throw new Exception('Veuillez indiquer au moins 3 mots-clés.');
}
$this->db->setThesisTags($thesisId, $keywords);
error_log('[ThesisEdit] Step 6 OK — tags=' . json_encode($keywords));
$this->db->commit();
error_log('[ThesisEdit] COMMIT OK — thesis_id=' . $thesisId);
} catch (Exception $e) {
ErrorHandler::log('thesis_edit_tx', $e, ['thesis_id' => $thesisId]);
$this->db->rollback();
throw $e;
}