<?php
 namespace App\Modules\Addon\MigrateWhmcs\Importers; use App\Modules\Addon\MigrateWhmcs\Services\ImportReport; use App\Modules\Addon\MigrateWhmcs\Services\MigrationLedger; use App\Modules\Addon\MigrateWhmcs\Services\WhmcsSourceConnection; use Illuminate\Support\Facades\Log; abstract class AbstractWhmcsImporter { public function __construct( protected MigrationLedger $ledger, protected ImportReport $report, protected bool $dryRun = false, protected ?string $runId = null, ) {} abstract public function sourceType(): string; abstract protected function sourceTable(): string; abstract protected function importRow(object $row): ?int; public function run(): void { $type = $this->sourceType(); WhmcsSourceConnection::table($this->sourceTable()) ->orderBy('id') ->chunk(500, function ($rows) use ($type) { foreach ($rows as $row) { if ($this->ledger->has($type, $row->id)) { $this->report->skipped($type); continue; } if ($this->dryRun) { $this->report->imported($type); continue; } try { $targetId = $this->importRow($row); if ($targetId === null) { $this->report->skipped($type); continue; } $this->ledger->record($type, $row->id, $this->targetType(), $targetId, $this->runId); $this->report->imported($type); } catch (\Throwable $e) { $this->report->failed($type); $this->report->warn($type, "Satır #{$row->id} import hatası: ".$e->getMessage()); Log::error('WHMCS import row failed', [ 'type' => $type, 'source_id' => $row->id, 'error' => $e->getMessage(), ]); } } }); } protected function targetType(): string { return $this->sourceType(); } } 