46 lines
1.5 KiB
PHP
46 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace Modules\Core\MigrateImport\Jobs;
|
|
|
|
use Illuminate\Bus\Queueable;
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
use Illuminate\Foundation\Bus\Dispatchable;
|
|
use Illuminate\Queue\InteractsWithQueue;
|
|
use Illuminate\Queue\SerializesModels;
|
|
use Illuminate\Support\Facades\Log;
|
|
use Modules\Core\MigrateImport\DTOs\ImportSpec;
|
|
use Modules\Core\MigrateImport\Services\ImporterFactory;
|
|
|
|
class RunMigrateImportJob implements ShouldQueue
|
|
{
|
|
use Dispatchable;
|
|
use InteractsWithQueue;
|
|
use Queueable;
|
|
use SerializesModels;
|
|
|
|
public function __construct(
|
|
public readonly ImportSpec $spec,
|
|
) {
|
|
}
|
|
|
|
/**
|
|
* Just hands off to the right Importer and returns — for Shopify,
|
|
* that importer dispatches a job batch instead of importing inline
|
|
* (see Shopify\ShopifyExportImporter::import()) and this job's own
|
|
* work is done the moment that batch is queued, well before the
|
|
* batch's jobs actually run. The SKU backfill that used to happen
|
|
* right here, after import() returned, now happens in that batch's
|
|
* own then() callback instead — running it here would fire before a
|
|
* single product had actually been imported.
|
|
*/
|
|
public function handle(): void
|
|
{
|
|
Log::info('Import started', ['source' => $this->spec->source, 'type' => $this->spec->type, 'file' => $this->spec->filePath]);
|
|
|
|
$importer = ImporterFactory::make($this->spec);
|
|
$importer->import($this->spec);
|
|
|
|
Log::info('Import job complete', ['source' => $this->spec->source]);
|
|
}
|
|
}
|