mirror of
https://codeberg.org/PostERG/xamxam.git
synced 2026-05-06 19:19:19 +02:00
ignore *.db files, fix thesis identifier to use max seq instead of count, untrack .db files
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user