diff --git a/src/Command/MigrateImportCommand.php b/src/Command/MigrateImportCommand.php new file mode 100644 index 0000000..02baf4c --- /dev/null +++ b/src/Command/MigrateImportCommand.php @@ -0,0 +1,61 @@ +option("source") + ?? $this->choice("Select a source:", self::SOURCES, 0); + + $type = $this->option("type") + ?? $this->choice("Select an import type:", self::TYPES, 0); + + if ($type === "api") { + $credentials = [ + "api_key" => $this->secret("API key:"), + "api_secret" => $this->secret("API secret:"), + ]; + $filePath = null; + } else { + $filePath = $this->option("file") + ?? $this->ask("Path to the export file:"); + $credentials = null; + } + + $spec = new ImportSpec( + source: $source, + type: $type, + filePath: $filePath, + credentials: $credentials, + ); + + RunMigrateImportJob::dispatch($spec); + + $this->info("Import queued."); + } +} diff --git a/src/MigrateImport/ImportSpec.php b/src/MigrateImport/ImportSpec.php new file mode 100644 index 0000000..d5a8016 --- /dev/null +++ b/src/MigrateImport/ImportSpec.php @@ -0,0 +1,14 @@ +source, $spec->type]) { + ["shopify", "export"] => new ShopifyExportImporter(), + // ["shopify", "api"] => new ShopifyApiImporter(), + // ["woocommerce", "export"] => new WooCommerceExportImporter(), + // ["woocommerce", "api"] => new WooCommerceApiImporter(), + default => throw new \InvalidArgumentException( + "No importer available for source \"{$spec->source}\" with type \"{$spec->type}\".", + ), + }; + } +} diff --git a/src/MigrateImport/RunMigrateImportJob.php b/src/MigrateImport/RunMigrateImportJob.php new file mode 100644 index 0000000..16dfb4d --- /dev/null +++ b/src/MigrateImport/RunMigrateImportJob.php @@ -0,0 +1,28 @@ +spec); + $importer->import($this->spec); + } +} diff --git a/src/MigrateImport/Shopify/ShopifyExportImporter.php b/src/MigrateImport/Shopify/ShopifyExportImporter.php new file mode 100644 index 0000000..2b8c864 --- /dev/null +++ b/src/MigrateImport/Shopify/ShopifyExportImporter.php @@ -0,0 +1,13 @@ +app->runningInConsole()) { - $this->commands([AnonymizeCommand::class, ExportCommand::class, ExportCleanupCommand::class, ImportCommand::class]); + $this->commands([AnonymizeCommand::class, ExportCommand::class, ExportCleanupCommand::class, ImportCommand::class, MigrateImportCommand::class]); } } }