42 lines
1.4 KiB
PHP
42 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands\Whmcs;
|
|
|
|
use App\Integrations\Whmcs\Extractors\OrderItemExtractor;
|
|
use App\Integrations\Whmcs\Transformers\OrderItemTransformer;
|
|
use App\Integrations\Whmcs\Writers\OrderItemWriter;
|
|
use App\Integrations\Whmcs\Support\SyncReport;
|
|
use Illuminate\Console\Command;
|
|
|
|
class SyncOrderItemsCommand extends Command
|
|
{
|
|
protected $signature = 'whmcs:sync-order-items {--missing-only : Only records not yet synced (new, or order without customer)}';
|
|
|
|
protected $description = 'Extract provisioned services (tblhosting) from WHMCS and upsert them into order_items (run after whmcs:sync-orders)';
|
|
|
|
public function handle(OrderItemExtractor $extractor, OrderItemTransformer $transformer, OrderItemWriter $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} order item(s), skipped {$skipped} (unresolved order).");
|
|
|
|
app(SyncReport::class)->finish($this);
|
|
|
|
return Command::SUCCESS;
|
|
}
|
|
}
|