logs: standardise log filenames to xamxam-{service}-{date}.log

This commit is contained in:
Pontoporeia
2026-08-24 11:34:34 +02:00
parent 7b6d79c133
commit d2cef85966
25 changed files with 442 additions and 83 deletions
+24 -6
View File
@@ -1,31 +1,49 @@
#!/usr/bin/env php
<?php
/**
* cleanup-drafts.php — Delete orphaned draft theses older than 24h.
* cleanup-drafts.php — Delete orphaned draft theses older than a threshold.
*
* Draft theses are created with status='draft' during the two-phase commit
* in ThesisCreateController. If the file phase throws after COMMIT, the
* draft remains orphaned — no files attached, but blocks the identifier.
*
* The eligibility age defaults to 7 days (168 hours) and can be overridden
* with the OLDER_THAN_HOURS environment variable:
* OLDER_THAN_HOURS=24 php scripts/cleanup-drafts.php
*
* Usage:
* php scripts/cleanup-drafts.php # dry-run (list candidates)
* php scripts/cleanup-drafts.php --no-dry-run # actually delete
* php /tmp/cleanup-drafts.php # dry-run (list candidates)
* php /tmp/cleanup-drafts.php --no-dry-run # actually delete
*
* Exit codes: 0 on success, 1 on error.
*/
declare(strict_types=1);
$root = dirname(__DIR__);
define('APP_ROOT', $root . '/app');
// Resolve APP_ROOT robustly. In production the app code is deployed flat under
// /var/www/xamxam/ (src/, storage/, templates/ at the root, no app/ subdir), and
// this script may itself live in /tmp. Always point at /var/www/xamxam in
// non-CLI-SAPI contexts; local dev (cli-server) keeps the app/ subdir layout.
$prodRoot = '/var/www/xamxam';
if (is_dir($prodRoot . '/src') && is_file($prodRoot . '/src/Database.php')) {
define('APP_ROOT', $prodRoot);
} else {
define('APP_ROOT', dirname(__DIR__) . '/app');
}
require_once APP_ROOT . '/src/Database.php';
$dryRun = !in_array('--no-dry-run', $argv, true);
// Eligibility threshold: default 7 days (168h); overridable via env.
$olderThanHours = (int) (getenv('OLDER_THAN_HOURS') ?: 168);
if ($olderThanHours < 1) {
$olderThanHours = 168;
}
try {
$db = new Database();
$result = $db->cleanupOrphanedDrafts(24, $dryRun);
$result = $db->cleanupOrphanedDrafts($olderThanHours, $dryRun);
} catch (Exception $e) {
error_log('[cleanup-drafts] Error: ' . $e->getMessage());
exit(1);