25 lines
689 B
PHP
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;
|
|
}
|
|
}
|