Files
portal-api/app/Console/Commands/Whmcs/SyncCustomerDomainsCommand.php

42 lines
1.5 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 App\Integrations\Whmcs\Support\SyncReport;
use Illuminate\Console\Command;
class SyncCustomerDomainsCommand extends Command
{
protected $signature = 'whmcs:sync-domains {--missing-only : Only records not yet synced (new, or order without customer)}';
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
{
$missingOnly = (bool) $this->option('missing-only');
$total = $extractor->extract($missingOnly)->count();
$bar = $this->output->createProgressBar($total);
$bar->start();
$skipped = 0;
foreach ($extractor->extract($missingOnly) 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).");
app(SyncReport::class)->finish($this);
return Command::SUCCESS;
}
}