Files
portal-api/app/Console/Commands/Whmcs/SyncAllCommand.php
T
2026-09-27 11:42:40 +07:00

62 lines
2.0 KiB
PHP

<?php
namespace App\Console\Commands\Whmcs;
use Illuminate\Console\Command;
class SyncAllCommand extends Command
{
protected $signature = 'whmcs:sync-all {--with-domain-sync : Also run domain:sync before whmcs:sync-domains}';
protected $description = 'Run every whmcs:sync-* command in dependency order (clients, products, orders, order-items, invoices, services, domains)';
private const STEPS = [
['command' => 'whmcs:sync-clients', 'forceSync' => true],
['command' => 'whmcs:sync-products', 'forceSync' => false],
['command' => 'whmcs:sync-orders', 'forceSync' => true],
['command' => 'whmcs:sync-order-items', 'forceSync' => false],
['command' => 'whmcs:sync-invoices', 'forceSync' => true],
['command' => 'whmcs:sync-services', 'forceSync' => false],
['command' => 'whmcs:sync-domains', 'forceSync' => false],
];
public function handle(): int
{
if ($this->option('with-domain-sync')) {
$exitCode = $this->runStep('domain:sync', []);
if ($exitCode !== self::SUCCESS) {
return $exitCode;
}
} else {
$this->warn('Skipping domain:sync — whmcs:sync-domains expects it to already be up to date. Pass --with-domain-sync to run it here.');
}
foreach (self::STEPS as $step) {
$arguments = $step['forceSync'] ? ['--sync' => true] : [];
$exitCode = $this->runStep($step['command'], $arguments);
if ($exitCode !== self::SUCCESS) {
return $exitCode;
}
}
$this->info('whmcs:sync-all completed successfully.');
return self::SUCCESS;
}
private function runStep(string $command, array $arguments): int
{
$this->newLine();
$this->info("==> {$command}");
$exitCode = $this->call($command, $arguments);
if ($exitCode !== self::SUCCESS) {
$this->error("{$command} failed with exit code {$exitCode}; stopping.");
}
return $exitCode;
}
}