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