mirror of
https://codeberg.org/PostERG/xamxam.git
synced 2026-06-25 16:19:19 +02:00
Add thesis status column for two-phase commit lifecycle tracking
This commit is contained in:
@@ -93,13 +93,14 @@ class ThesisCreateController
|
||||
* recapitulatif.php?id=<n>. On validation or DB failure, throws an Exception
|
||||
* (caller must flash the message and redirect back to the form).
|
||||
*
|
||||
* Execution order:
|
||||
* Two-phase execution:
|
||||
* 1. Validate + sanitise POST fields
|
||||
* 2. Find/create author record
|
||||
* 3. INSERT thesis row + link author (inside transaction)
|
||||
* 3. INSERT thesis row (status='draft') + link author (inside transaction)
|
||||
* 4. Link jury, languages, formats, tags (inside transaction)
|
||||
* 5. COMMIT
|
||||
* 5. COMMIT (thesis visible only as draft)
|
||||
* 6. Handle file uploads: cover, thesis files (outside transaction)
|
||||
* 7. UPDATE status to 'active' (confirms file operations succeeded)
|
||||
*
|
||||
* @param array $post Sanitised $_POST array.
|
||||
* @param array $files $_FILES array.
|
||||
@@ -226,6 +227,14 @@ class ThesisCreateController
|
||||
// ── 6. Website URL — stored as thesis_files row ──────────────────────
|
||||
$this->handleWebsiteUrl($thesisId, $post);
|
||||
|
||||
// ── 7. Two-phase commit: mark submission complete ──────────────────
|
||||
// The thesis was committed as status='draft' before file operations.
|
||||
// Now that all files are safely in place, promote to 'active'.
|
||||
// If any file operation had thrown, the draft would remain orphaned
|
||||
// for the periodic cleanup job (just cleanup-drafts).
|
||||
$this->db->setThesisStatus($thesisId, 'active');
|
||||
error_log("[ThesisCreate] ACTIVE — thesis_id=$thesisId | all file operations succeeded");
|
||||
|
||||
return $thesisId;
|
||||
}
|
||||
|
||||
|
||||
@@ -1682,6 +1682,22 @@ class Database
|
||||
Audit::log($this, Audit::actor(), 'UPDATE', 'theses', $thesisId, $old, $new);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the submission lifecycle status of a single thesis.
|
||||
*
|
||||
* Valid statuses: 'draft' (files not yet moved / failed) → 'active' (complete).
|
||||
*/
|
||||
public function setThesisStatus(int $thesisId, string $status): void
|
||||
{
|
||||
require_once __DIR__ . '/Audit.php';
|
||||
$old = $this->fetchRow('theses', $thesisId);
|
||||
$this->pdo->prepare(
|
||||
'UPDATE theses SET status = ?, updated_at = CURRENT_TIMESTAMP WHERE id = ?'
|
||||
)->execute([$status, $thesisId]);
|
||||
$new = $this->fetchRow('theses', $thesisId);
|
||||
Audit::log($this, Audit::actor(), 'UPDATE', 'theses', $thesisId, $old, $new);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the published state for multiple theses at once.
|
||||
* @param int[] $thesisIds
|
||||
@@ -2242,12 +2258,12 @@ class Database
|
||||
baiu_link, license_id, license_custom,
|
||||
access_type_id,
|
||||
objet,
|
||||
is_published,
|
||||
is_published, status,
|
||||
remarks, jury_points,
|
||||
exemplaire_baiu, exemplaire_erg,
|
||||
cc2r,
|
||||
submitted_at
|
||||
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 0, ?, ?, ?, ?, ?, CURRENT_TIMESTAMP)
|
||||
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 0, "draft", ?, ?, ?, ?, ?, CURRENT_TIMESTAMP)
|
||||
');
|
||||
|
||||
$validObjet = ['tfe', 'thèse', 'frart'];
|
||||
|
||||
Reference in New Issue
Block a user