add structured logging for admin/partage form submissions + migration system

- AppLogger: JSON-line logger in storage/logs/form-submissions.log
- Logs submissions (admin + partage) with IP, UA, thesis ID, author
- Logs errors with context (post keys, share slug)
- Migration runner (app/migrations/run.php) handles schema drift
- 001_add_objet_column.sql fixes production DB missing 'objet' column
- ThesisCreateController::getIdentifier() helper for logging
This commit is contained in:
Pontoporeia
2026-04-24 16:55:11 +02:00
parent decb9e2907
commit 4986fa74f4
9 changed files with 344 additions and 10 deletions

View File

@@ -500,11 +500,20 @@ function handleShareLinkSubmission(string $slug): void
require_once APP_ROOT . '/src/Controllers/ThesisCreateController.php';
require_once APP_ROOT . '/src/StudentEmail.php';
require_once APP_ROOT . '/src/AppLogger.php';
$logger = new AppLogger();
$authorName = $_POST['auteurice'] ?? 'unknown';
try {
$ctrl = ThesisCreateController::make();
$thesisId = $ctrl->submit($_POST, $_FILES);
$identifier = $ctrl->getIdentifier($thesisId);
$logger->logSubmission('partage', $thesisId, $identifier, $authorName, [
'share_slug' => $slug,
]);
// Send confirmation e-mail (non-blocking; failure doesn't stop redirect)
$emailSent = StudentEmail::sendConfirmation(Database::getInstance(), $thesisId, $_POST);
@@ -521,6 +530,12 @@ function handleShareLinkSubmission(string $slug): void
header('Location: /partage/thanks?id=' . urlencode((string)$thesisId));
exit();
} catch (Exception $e) {
$logger->logError('partage', $e->getMessage(), [
'share_slug' => $slug,
'author' => $authorName,
'post_keys' => array_keys($_POST),
]);
error_log('Share link submission error: ' . $e->getMessage());
$_SESSION['_flash_error'] = $e->getMessage();