where(fn ($q) => $q->whereNull('outcome')->orWhere('outcome', '!=', Lead::WON)) ->where('folder', '!=', Lead::SPAM)->where('created_at', '<', now()->subDays(max(1, (int) config('manager.leads.keep_days', 365)))); $spam = Lead::query()->where('folder', Lead::SPAM)->where('created_at', '<', now()->subDays(max(1, (int) config('manager.leads.keep_spam_days', 30)))); $blocks = LeadBlock::query()->whereNotNull('expires_at')->where('expires_at', '<', now()); $counts = ['requests' => $old->count(), 'spam' => $spam->count(), 'blocks' => $blocks->count()]; if (! $this->option('dry-run')) { $old->delete(); $spam->delete(); $blocks->delete(); } $this->components->info(($this->option('dry-run') ? 'Would remove' : 'Removed')." {$counts['requests']} requests, {$counts['spam']} spam, {$counts['blocks']} blocks."); return self::SUCCESS; } }