| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- #!/usr/bin/env php
- <?php
- declare(strict_types=1);
- use App\App\Bootstrap;
- use App\Storage\FileSystem;
- require dirname(__DIR__) . '/src/autoload.php';
- Bootstrap::init(false);
- $app = Bootstrap::config('app');
- $draftDir = rtrim((string) $app['storage']['drafts'], '/');
- $submissionDir = rtrim((string) $app['storage']['submissions'], '/');
- $uploadDir = rtrim((string) $app['storage']['uploads'], '/');
- $draftDays = (int) ($app['retention']['draft_days'] ?? 14);
- $submissionDays = (int) ($app['retention']['submission_days'] ?? 90);
- $now = time();
- $deletedDrafts = 0;
- $deletedSubmissions = 0;
- $draftFiles = glob($draftDir . '/*.json') ?: [];
- foreach ($draftFiles as $file) {
- $raw = file_get_contents($file);
- $data = is_string($raw) ? json_decode($raw, true) : null;
- $updatedAt = strtotime((string) ($data['updated_at'] ?? ''));
- if ($updatedAt > 0 && ($now - $updatedAt) > ($draftDays * 86400)) {
- unlink($file);
- $deletedDrafts++;
- }
- }
- $submissionFiles = glob($submissionDir . '/*.json') ?: [];
- foreach ($submissionFiles as $file) {
- $raw = file_get_contents($file);
- $data = is_string($raw) ? json_decode($raw, true) : null;
- $submittedAt = strtotime((string) ($data['submitted_at'] ?? ''));
- if ($submittedAt > 0 && ($now - $submittedAt) > ($submissionDays * 86400)) {
- $applicationKey = (string) ($data['application_key'] ?? pathinfo($file, PATHINFO_FILENAME));
- unlink($file);
- FileSystem::removeTree($uploadDir . '/' . $applicationKey);
- $deletedSubmissions++;
- }
- }
- $message = sprintf(
- 'Cleanup abgeschlossen: drafts=%d, submissions=%d',
- $deletedDrafts,
- $deletedSubmissions
- );
- Bootstrap::log('cleanup', $message);
- if (PHP_SAPI === 'cli') {
- echo $message . PHP_EOL;
- }
|