ignore *.db files, fix thesis identifier to use max seq instead of count, untrack .db files

This commit is contained in:
Pontoporeia
2026-04-24 22:48:01 +02:00
parent 4986fa74f4
commit 54ef24d21f
5 changed files with 19 additions and 39 deletions

View File

@@ -1524,11 +1524,22 @@ class Database {
* number. Must be called inside the same transaction that performs the INSERT so that
* concurrent requests cannot produce duplicate identifiers.
*/
/**
* Generate a unique identifier like "2025-003" for a new thesis.
*
* Uses the actual maximum sequence number for the given year (from
* existing identifiers) rather than the row count, so deletes don't
* cause identifier collisions.
*
* Must be called inside an open transaction.
*/
public function generateThesisIdentifier(int $year): string {
$stmt = $this->pdo->prepare("SELECT COUNT(*) FROM theses WHERE year = ?");
$stmt->execute([$year]);
$count = (int)$stmt->fetchColumn() + 1;
return sprintf("%d-%03d", $year, $count);
$stmt = $this->pdo->prepare(
"SELECT COALESCE(MAX(CAST(SUBSTR(identifier, 6) AS INTEGER)), 0) FROM theses WHERE identifier LIKE ?"
);
$stmt->execute([$year . '-%']);
$maxSeq = (int)$stmt->fetchColumn();
return sprintf("%d-%03d", $year, $maxSeq + 1);
}
/**