PR CI / flow (pull_request) Successful in 4s
PR CI / ledger (pull_request) Successful in 4s
PR CI / test (stable) (pull_request) Successful in 35s
PR CI / test (lowest) (pull_request) Successful in 40s
PR CI / security (pull_request) Successful in 51s
PR CI / pr-ci (pull_request) Successful in 1s
PR CI / release-automerge (pull_request) Successful in 4s
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;
|
|
}
|
|
}
|