Files
termanager2/app/Console/Commands/AuditCleanup.php
Francesco Picone 701f479b7f Primo commit
2026-04-05 19:26:04 +02:00

25 lines
689 B
PHP

<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Spatie\Activitylog\Models\Activity;
use App\Models\Setting;
class AuditCleanup extends Command
{
protected $signature = 'audit:cleanup';
protected $description = 'Delete audit log entries older than the configured retention period';
public function handle(): int
{
$retentionDays = Setting::instance()->audit_retention_days ?? 365;
$cutoff = now()->subDays($retentionDays);
$deleted = Activity::where('created_at', '<', $cutoff)->delete();
$this->info("Deleted {$deleted} audit entries older than {$retentionDays} days.");
return self::SUCCESS;
}
}