71 lines
2.4 KiB
PHP
71 lines
2.4 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands\Whmcs;
|
|
|
|
use App\Integrations\Whmcs\Support\SyncReport;
|
|
use Illuminate\Console\Command;
|
|
|
|
class SyncAllCommand extends Command
|
|
{
|
|
protected $signature = 'whmcs:sync-all {--with-domain-sync : Also run domain:sync before whmcs:sync-domains} {--missing-only : Only sync records not yet synced, leaving existing rows untouched}';
|
|
|
|
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(SyncReport $report): int
|
|
{
|
|
$report->beginBatch();
|
|
|
|
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] : [];
|
|
if ($this->option('missing-only') && $step['command'] !== 'whmcs:sync-products') {
|
|
$arguments['--missing-only'] = true;
|
|
}
|
|
$exitCode = $this->runStep($step['command'], $arguments);
|
|
|
|
if ($exitCode !== self::SUCCESS) {
|
|
$report->finishBatch($this);
|
|
|
|
return $exitCode;
|
|
}
|
|
}
|
|
|
|
$this->info('whmcs:sync-all completed successfully.');
|
|
$report->finishBatch($this);
|
|
|
|
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;
|
|
}
|
|
}
|