VPS and dedicated server ordering, managed panels, SSO, billing, and launcher integration — forked from hosting infrastructure with server-focused routes and dashboard. Co-authored-by: Cursor <cursoragent@cursor.com>
67 lines
2.2 KiB
PHP
67 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use App\Jobs\ProvisionHostingAccountJob;
|
|
use App\Models\HostingAccount;
|
|
use Illuminate\Console\Command;
|
|
|
|
class ProvisionPendingHostingAccountsCommand extends Command
|
|
{
|
|
protected $signature = 'hosting:provision-pending {--dry-run : Show accounts without dispatching jobs}';
|
|
|
|
protected $description = 'Dispatch provisioning jobs for hosting accounts stuck in pending status';
|
|
|
|
public function handle(): int
|
|
{
|
|
$pendingAccounts = HostingAccount::query()
|
|
->whereIn('status', ['pending', 'failed'])
|
|
->whereNotNull('hosting_node_id')
|
|
->whereNull('provisioned_at')
|
|
->with(['user:id,name,email', 'product:id,name', 'node:id,name'])
|
|
->get();
|
|
|
|
if ($pendingAccounts->isEmpty()) {
|
|
$this->info('No pending hosting accounts found.');
|
|
return self::SUCCESS;
|
|
}
|
|
|
|
$this->info("Found {$pendingAccounts->count()} pending account(s):");
|
|
$this->newLine();
|
|
|
|
foreach ($pendingAccounts as $account) {
|
|
$this->line(" • [{$account->id}] {$account->username} - {$account->user?->name} ({$account->user?->email})");
|
|
$this->line(" Product: {$account->product?->name}, Node: {$account->node?->name}, Status: {$account->status}");
|
|
}
|
|
|
|
$this->newLine();
|
|
|
|
if ($this->option('dry-run')) {
|
|
$this->warn('Dry run mode - no jobs dispatched.');
|
|
return self::SUCCESS;
|
|
}
|
|
|
|
if (! $this->confirm('Dispatch provisioning jobs for these accounts?')) {
|
|
$this->info('Aborted.');
|
|
return self::SUCCESS;
|
|
}
|
|
|
|
$dispatched = 0;
|
|
foreach ($pendingAccounts as $account) {
|
|
// Reset status to pending if it was failed
|
|
if ($account->status === 'failed') {
|
|
$account->update(['status' => 'pending', 'notes' => null]);
|
|
}
|
|
|
|
ProvisionHostingAccountJob::dispatch($account->id);
|
|
$dispatched++;
|
|
$this->info("Dispatched job for account #{$account->id} ({$account->username})");
|
|
}
|
|
|
|
$this->newLine();
|
|
$this->info("Dispatched {$dispatched} provisioning job(s). Check queue worker for progress.");
|
|
|
|
return self::SUCCESS;
|
|
}
|
|
}
|