- 134-tool registry with programmatic SEO (unique titles/H1/descriptions, JSON-LD graphs, sitemap index, canonical 301 enforcement via required filter) - DB-backed job queue (SKIP LOCKED) with drivers: Ffmpeg, Images (GD), Pdf (qpdf/gs/poppler), Youtube (thumbnails), Qr (server-side PNG) - Security: SSRF guard, MIME validation, rate limits, API-key auth, bcrypt admin login, security headers - Admin panel: dashboard, tools/categories/guides CRUD, SEO audit, analytics, job inspector with retry, system health, feature flags - Docker deployment (nginx + web/api FPM pools + scalable workers), PHPUnit suite (19 tests / 1139 assertions), PWA manifest + service worker
59 lines
2.0 KiB
PHP
59 lines
2.0 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Commands;
|
|
|
|
use App\Libraries\Pipeline;
|
|
use App\Models\JobModel;
|
|
use CodeIgniter\CLI\BaseCommand;
|
|
use CodeIgniter\CLI\CLI;
|
|
|
|
/**
|
|
* Retention reaper — deletes expired input/output files and their rows.
|
|
* Schedule every few minutes (cron / scheduler container):
|
|
*
|
|
* php spark media:cleanup
|
|
*/
|
|
final class MediaCleanup extends BaseCommand
|
|
{
|
|
protected $group = 'Toolvana';
|
|
protected $name = 'media:cleanup';
|
|
protected $description = 'Delete expired uploads, outputs and job rows per retention policy.';
|
|
protected $usage = 'media:cleanup';
|
|
|
|
public function run(array $params): void
|
|
{
|
|
$jobs = model(JobModel::class);
|
|
$deleted = 0;
|
|
$freed = 0;
|
|
|
|
foreach ([...$jobs->findExpired(), ...$jobs->findOldFailed()] as $job) {
|
|
foreach (['input_file' => Pipeline::incomingDir(), 'output_file' => Pipeline::storageDir()] as $field => $dir) {
|
|
if (! empty($job[$field])) {
|
|
$path = rtrim((string) $dir, '/') . '/' . basename((string) $job[$field]);
|
|
if (is_file($path)) {
|
|
$freed += (int) @filesize($path);
|
|
@unlink($path);
|
|
}
|
|
}
|
|
}
|
|
$jobs->delete($job['id']);
|
|
++$deleted;
|
|
}
|
|
|
|
// orphaned files with no row (worker crash leftovers)
|
|
$cutoff = time() - max(2, config('Site')->retentionHours) * 3600 - 600;
|
|
foreach ([Pipeline::incomingDir(), Pipeline::storageDir()] as $dir) {
|
|
foreach (glob(rtrim($dir, '/') . '/*') ?: [] as $file) {
|
|
if (is_file($file) && filemtime($file) < $cutoff) {
|
|
$freed += (int) @filesize($file);
|
|
@unlink($file);
|
|
}
|
|
}
|
|
}
|
|
|
|
CLI::write("Cleanup: {$deleted} job row(s) removed, " . number_format($freed / 1048576, 1) . ' MB freed.', 'yellow');
|
|
}
|
|
}
|