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(); } }