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

39 lines
1.3 KiB
PHP

<?php
namespace App\Console\Commands\Whmcs;
use App\Integrations\Whmcs\Extractors\CustomerDomainExtractor;
use App\Integrations\Whmcs\Transformers\CustomerDomainTransformer;
use App\Integrations\Whmcs\Writers\CustomerDomainWriter;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
class SyncCustomerDomainsCommand extends Command
{
protected $signature = 'whmcs:sync-domains';
protected $description = 'Extract customer domain registrations (tbldomains) from WHMCS and upsert them into module_domain (run after whmcs:sync-clients, whmcs:sync-orders, domain:sync)';
public function handle(CustomerDomainExtractor $extractor, CustomerDomainTransformer $transformer, CustomerDomainWriter $writer): int
{
$total = DB::connection('whmcs')->table('tbldomains')->count();
$bar = $this->output->createProgressBar($total);
$bar->start();
$skipped = 0;
foreach ($extractor->extract() as $row) {
if (! $writer->write($transformer->transform($row))) {
$skipped++;
}
$bar->advance();
}
$bar->finish();
$this->newLine();
$this->info("Processed {$total} domain(s), skipped {$skipped} (unresolved customer).");
return Command::SUCCESS;
}
}