with(['sites', 'node']) ->when($this->option('account'), fn ($q, $id) => $q->whereKey($id)) ->orderBy('id') ->get() ->filter(fn (HostingAccount $account) => $placeholders->accountNeedsPromotion($account) || $account->sites->contains( fn ($site) => PlaceholderPrimaryDomainService::isPlaceholderDomain($site->domain) )); if ($accounts->isEmpty()) { $this->info('No accounts need placeholder primary repair.'); return self::SUCCESS; } $healed = 0; foreach ($accounts as $account) { $before = $account->primary_domain ?: '(null)'; $this->line(sprintf( '[%d] %s primary=%s sites=%s', $account->id, $account->username, $before, $account->sites->pluck('domain')->implode(', ') ?: '(none)' )); if ($this->option('dry-run')) { continue; } if ($placeholders->healAccount($account)) { $account->refresh(); $this->info(sprintf( ' → healed to primary=%s', $account->primary_domain ?: '(null)' )); $healed++; } } if ($this->option('dry-run')) { $this->warn('Dry run: no changes applied.'); } else { $this->info("Healed {$healed} account(s)."); } return self::SUCCESS; } }