Files
portal-api/app/Console/Commands/Whmcs/SyncOrdersCommand.php
T
2026-09-09 16:56:22 +07:00

37 lines
1.1 KiB
PHP

<?php
namespace App\Console\Commands\Whmcs;
use App\Integrations\Whmcs\Extractors\OrderExtractor;
use App\Jobs\Whmcs\SyncOrderJob;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
class SyncOrdersCommand extends Command
{
protected $signature = 'whmcs:sync-orders {--sync : Run each record inline instead of queueing it}';
protected $description = 'Extract orders from the WHMCS database and upsert them into orders (run before whmcs:sync-invoices)';
public function handle(OrderExtractor $extractor): int
{
$sync = (bool) $this->option('sync');
$total = DB::connection('whmcs')->table('tblorders')->count();
$bar = $this->output->createProgressBar($total);
$bar->start();
foreach ($extractor->extract() as $row) {
$job = new SyncOrderJob((array) $row);
$sync ? dispatch_sync($job) : dispatch($job);
$bar->advance();
}
$bar->finish();
$this->newLine();
$this->info("Dispatched {$total} order(s) for sync.");
return Command::SUCCESS;
}
}