40 lines
1.3 KiB
PHP
40 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands\Whmcs;
|
|
|
|
use App\Integrations\Whmcs\Extractors\OrderExtractor;
|
|
use App\Jobs\Whmcs\SyncOrderJob;
|
|
use App\Integrations\Whmcs\Support\SyncReport;
|
|
use Illuminate\Console\Command;
|
|
|
|
class SyncOrdersCommand extends Command
|
|
{
|
|
protected $signature = 'whmcs:sync-orders {--sync : Run each record inline instead of queueing it} {--missing-only : Only records not yet synced (new, or order without customer)}';
|
|
|
|
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');
|
|
$missingOnly = (bool) $this->option('missing-only');
|
|
$total = $extractor->extract($missingOnly)->count();
|
|
|
|
$bar = $this->output->createProgressBar($total);
|
|
$bar->start();
|
|
|
|
foreach ($extractor->extract($missingOnly) 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.");
|
|
|
|
app(SyncReport::class)->finish($this);
|
|
|
|
return Command::SUCCESS;
|
|
}
|
|
}
|