39 lines
1.2 KiB
PHP
39 lines
1.2 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 Illuminate\Console\Command;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
class SyncOrderItemsCommand extends Command
|
|
{
|
|
protected $signature = 'whmcs:sync-order-items';
|
|
|
|
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
|
|
{
|
|
$total = DB::connection('whmcs')->table('tblhosting')->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} order item(s), skipped {$skipped} (unresolved order).");
|
|
|
|
return Command::SUCCESS;
|
|
}
|
|
}
|