28 lines
809 B
PHP
28 lines
809 B
PHP
<?php
|
|
|
|
namespace IriksIT\Manager\Modules\Audit;
|
|
|
|
use Illuminate\Console\Command;
|
|
use IriksIT\Manager\Models\AuditLog;
|
|
use IriksIT\Manager\Models\AuditSetting;
|
|
|
|
class PruneAuditLog extends Command
|
|
{
|
|
protected $signature = 'manager:audit-prune';
|
|
|
|
protected $description = 'Delete the lines of the audit log and the ended bans that are older than the rules keep them';
|
|
|
|
public function handle(IpBans $bans): int
|
|
{
|
|
$before = now()->subDays(AuditSetting::current()->rules()['keep_days']);
|
|
|
|
$old = AuditLog::query()->where('created_at', '<', $before);
|
|
$lines = $old->count();
|
|
$old->delete();
|
|
|
|
$this->line(sprintf('%d line(s) of the audit log and %d ended ban(s) deleted.', $lines, $bans->forgetExpiredBefore($before)));
|
|
|
|
return self::SUCCESS;
|
|
}
|
|
}
|