mirror of
https://codeberg.org/PostERG/xamxam.git
synced 2026-06-25 16:19:19 +02:00
- New fragment endpoint POST/GET /partage/fragments/draft.php: saves all form fields to PHP session, excludes file/csrf/slug fields GET returns JSON for JS hydration on page load rotates both global CSRF and share CSRF tokens in sync - form.php accepts optional $formExtraAttrs and $showAutosaveStatus: allows injecting HTMX attributes and 'Brouillon enregistré' indicator - renderShareLinkForm adds hx-post with change/input debounce trigger, loads autosave-handler.js, hydrate fields from draft on page load - Draft cleared on successful form submission in handleShareLinkSubmission - autosave-handler.js now also updates share_link_token hidden input when rotating CSRF token (partage form uses both csrf_token and share_link_token) - Added .autosave-status CSS to form.css (was admin.css-only) - Updated fragment routing to accept GET requests (needed for draft hydration)
93 lines
2.9 KiB
PHP
93 lines
2.9 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Structured application logger for form submissions.
|
|
*
|
|
* Thin facade over Monolog channel 'app'.
|
|
* Delegates all file I/O — keeps existing public API unchanged.
|
|
*/
|
|
class AppLogger
|
|
{
|
|
public function __construct()
|
|
{
|
|
}
|
|
|
|
/**
|
|
* Log a successful thesis submission.
|
|
*
|
|
* @param string $source 'admin' or 'partage'
|
|
* @param int $thesisId
|
|
* @param string $identifier e.g. "2025-003"
|
|
* @param string $authorName
|
|
* @param array $extras Additional context (e.g. share link slug)
|
|
*/
|
|
public function logSubmission(string $source, int $thesisId, string $identifier, string $authorName, array $extras = []): void
|
|
{
|
|
$this->write(array_merge([
|
|
'source' => $source,
|
|
'action' => 'submit',
|
|
'status' => 'success',
|
|
'thesis_id' => $thesisId,
|
|
'identifier' => $identifier,
|
|
'author' => $authorName,
|
|
], $extras));
|
|
}
|
|
|
|
/**
|
|
* Log a duplicate-submission attempt.
|
|
*
|
|
* @param string $source 'admin' or 'partage'
|
|
* @param string $authorName Author name from the incoming form
|
|
* @param int $existingThesisId ID of the matched existing thesis
|
|
* @param string $existingIdentifier Identifier of the matched thesis (e.g. "2025-003")
|
|
* @param array $extras Additional context (e.g. share_slug)
|
|
*/
|
|
public function logDuplicate(
|
|
string $source,
|
|
string $authorName,
|
|
int $existingThesisId,
|
|
string $existingIdentifier,
|
|
array $extras = []
|
|
): void {
|
|
$this->write(array_merge([
|
|
'source' => $source,
|
|
'action' => 'submit',
|
|
'status' => 'duplicate',
|
|
'author' => $authorName,
|
|
'existing_thesis_id' => $existingThesisId,
|
|
'existing_identifier' => $existingIdentifier,
|
|
], $extras));
|
|
}
|
|
|
|
/**
|
|
* Log a failed thesis submission.
|
|
*
|
|
* @param string $source
|
|
* @param string $errorMessage
|
|
* @param array $extras
|
|
*/
|
|
public function logError(string $source, string $errorMessage, array $extras = []): void
|
|
{
|
|
$this->write(array_merge([
|
|
'source' => $source,
|
|
'action' => 'submit',
|
|
'status' => 'error',
|
|
'error' => $errorMessage,
|
|
], $extras));
|
|
}
|
|
|
|
/**
|
|
* Write a structured log line — delegates to Monolog 'app' channel.
|
|
*/
|
|
private function write(array $entry): void
|
|
{
|
|
$entry['timestamp'] = date('c');
|
|
$entry['ip'] = $_SERVER['REMOTE_ADDR'] ?? 'unknown';
|
|
$entry['user_agent'] = $_SERVER['HTTP_USER_AGENT'] ?? '';
|
|
|
|
$line = json_encode($entry, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
|
|
|
|
Logger::get('app')->info($line);
|
|
}
|
|
}
|