## Summary - Fixes misleading “queued / running in background” message when Review Pack generation request reuses an existing ready pack (fingerprint dedupe). - Improves resilience of Filament/Livewire interactions by ensuring the Livewire intercept shim applies after Livewire initializes. - Aligns Review Pack operation notifications with Ops-UX patterns (queued + completed notifications) and removes the old ReviewPackStatusNotification. ## Key Changes - Review Pack generate action now: - Shows queued toast only when a new pack is actually created/queued. - Shows a “Review pack already available” success notification with a link when dedupe returns an existing pack. ## Tests - `vendor/bin/sail artisan test --compact tests/Feature/ReviewPack/ReviewPackGenerationTest.php` - `vendor/bin/sail artisan test --compact tests/Feature/ReviewPack/ReviewPackResourceTest.php` - `vendor/bin/sail artisan test --compact tests/Feature/LivewireInterceptShimTest.php` ## Notes - No global search behavior changes for ReviewPacks (still excluded). - Destructive actions remain confirmation-gated (`->requiresConfirmation()`). Co-authored-by: Ahmed Darrazi <ahmed.darrazi@live.de> Reviewed-on: #133
78 lines
1.9 KiB
PHP
78 lines
1.9 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use App\Models\ReviewPack;
|
|
use Illuminate\Console\Command;
|
|
use Illuminate\Support\Facades\Storage;
|
|
|
|
class PruneReviewPacksCommand extends Command
|
|
{
|
|
/**
|
|
* @var string
|
|
*/
|
|
protected $signature = 'tenantpilot:review-pack:prune {--hard-delete : Hard-delete expired packs past grace period}';
|
|
|
|
/**
|
|
* @var string
|
|
*/
|
|
protected $description = 'Expire review packs past retention and optionally hard-delete expired rows past grace period';
|
|
|
|
public function handle(): int
|
|
{
|
|
$expired = $this->expireReadyPacks();
|
|
$hardDeleted = 0;
|
|
|
|
if ($this->option('hard-delete')) {
|
|
$hardDeleted = $this->hardDeleteExpiredPacks();
|
|
}
|
|
|
|
$this->info("{$expired} pack(s) expired, {$hardDeleted} pack(s) hard-deleted.");
|
|
|
|
return self::SUCCESS;
|
|
}
|
|
|
|
/**
|
|
* Transition ready packs past retention to expired and delete their files.
|
|
*/
|
|
private function expireReadyPacks(): int
|
|
{
|
|
$packs = ReviewPack::query()
|
|
->ready()
|
|
->pastRetention()
|
|
->get();
|
|
|
|
$disk = Storage::disk('exports');
|
|
$count = 0;
|
|
|
|
foreach ($packs as $pack) {
|
|
/** @var ReviewPack $pack */
|
|
if ($pack->file_path && $disk->exists($pack->file_path)) {
|
|
$disk->delete($pack->file_path);
|
|
}
|
|
|
|
$pack->update(['status' => ReviewPack::STATUS_EXPIRED]);
|
|
$count++;
|
|
}
|
|
|
|
return $count;
|
|
}
|
|
|
|
/**
|
|
* Hard-delete expired packs that are past the grace period.
|
|
*/
|
|
private function hardDeleteExpiredPacks(): int
|
|
{
|
|
$graceDays = (int) config('tenantpilot.review_pack.hard_delete_grace_days', 30);
|
|
|
|
$cutoff = now()->subDays($graceDays);
|
|
|
|
return ReviewPack::query()
|
|
->expired()
|
|
->where('updated_at', '<', $cutoff)
|
|
->delete();
|
|
}
|
|
}
|