Implements Spec 118 baseline drift engine improvements: - Resumable, budget-aware evidence capture for baseline capture/compare runs (resume token + UI action) - “Why no findings?” reason-code driven explanations and richer run context panels - Baseline Snapshot resource (list/detail) with fidelity visibility - Retention command + schedule for pruning baseline-purpose PolicyVersions - i18n strings for Baseline Compare landing Verification: - `vendor/bin/sail bin pint --dirty --format agent` - `vendor/bin/sail artisan test --compact --filter=Baseline` (159 passed) Note: - `docs/audits/redaction-audit-2026-03-04.md` left untracked (not part of PR). Co-authored-by: Ahmed Darrazi <ahmed.darrazi@live.de> Reviewed-on: #143
49 lines
1.4 KiB
PHP
49 lines
1.4 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use App\Models\PolicyVersion;
|
|
use App\Support\Baselines\PolicyVersionCapturePurpose;
|
|
use Illuminate\Console\Command;
|
|
|
|
class PruneBaselineEvidencePolicyVersionsCommand extends Command
|
|
{
|
|
/**
|
|
* @var string
|
|
*/
|
|
protected $signature = 'tenantpilot:baseline-evidence:prune {--days= : Number of days to retain baseline evidence policy versions}';
|
|
|
|
/**
|
|
* @var string
|
|
*/
|
|
protected $description = 'Soft-delete baseline-capture/baseline-compare policy versions older than the configured retention window';
|
|
|
|
public function handle(): int
|
|
{
|
|
$days = (int) ($this->option('days') ?: config('tenantpilot.baselines.full_content_capture.retention_days', 90));
|
|
|
|
if ($days < 1) {
|
|
$this->error('Retention days must be at least 1.');
|
|
|
|
return self::FAILURE;
|
|
}
|
|
|
|
$cutoff = now()->subDays($days);
|
|
|
|
$deleted = PolicyVersion::query()
|
|
->whereNull('deleted_at')
|
|
->whereIn('capture_purpose', [
|
|
PolicyVersionCapturePurpose::BaselineCapture->value,
|
|
PolicyVersionCapturePurpose::BaselineCompare->value,
|
|
])
|
|
->where('captured_at', '<', $cutoff)
|
|
->delete();
|
|
|
|
$this->info("Pruned {$deleted} baseline evidence policy version(s) older than {$days} days.");
|
|
|
|
return self::SUCCESS;
|
|
}
|
|
}
|