Primo commit
This commit is contained in:
24
app/Console/Commands/AuditCleanup.php
Normal file
24
app/Console/Commands/AuditCleanup.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user