Feature: Creating product import resolvers, wiring import job
This commit is contained in:
@@ -42,8 +42,22 @@ class MigrateImportCommand extends Command
|
||||
];
|
||||
$filePath = null;
|
||||
} else {
|
||||
$importsPath = storage_path("app/private/imports");
|
||||
|
||||
$filePath = $this->option("file")
|
||||
?? $this->ask("Path to the export file:");
|
||||
?? $this->resolveImportPath($importsPath, $this->ask("Path to the export file, relative to {$importsPath}:"));
|
||||
|
||||
while (blank($filePath) || ! is_file($filePath)) {
|
||||
if (filled($filePath)) {
|
||||
$this->error("File not found: {$filePath}");
|
||||
}
|
||||
|
||||
$filePath = $this->resolveImportPath(
|
||||
$importsPath,
|
||||
$this->ask("Path to the export file, relative to {$importsPath}:"),
|
||||
);
|
||||
}
|
||||
|
||||
$credentials = null;
|
||||
}
|
||||
|
||||
@@ -58,4 +72,24 @@ class MigrateImportCommand extends Command
|
||||
|
||||
$this->info("Import queued.");
|
||||
}
|
||||
|
||||
// Answers are relative to storage/app/private/imports (e.g. "shopify" or
|
||||
// "shopify/products_export.csv"); absolute paths are used as-is. A
|
||||
// directory answer picks the first CSV file found inside it.
|
||||
private function resolveImportPath(string $importsPath, ?string $answer): ?string
|
||||
{
|
||||
if (blank($answer)) {
|
||||
return $answer;
|
||||
}
|
||||
|
||||
$path = str_starts_with($answer, "/") ? $answer : "{$importsPath}/{$answer}";
|
||||
|
||||
if (is_dir($path)) {
|
||||
$csv = collect(glob("{$path}/*.csv"))->first();
|
||||
|
||||
return $csv ?? $path;
|
||||
}
|
||||
|
||||
return $path;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user