Skip to content

Commit

Permalink
[import] check if path exists
Browse files Browse the repository at this point in the history
  • Loading branch information
rastislav-chynoransky committed Nov 9, 2024
1 parent 1465aff commit 77f1e6a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
7 changes: 6 additions & 1 deletion app/Import.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,12 @@ public function csvFiles(): Collection

public function files(string $dir = null): Collection
{
$files = $this->storage()->files($dir ?? $this->dir_path);
$dir ??= $this->dir_path;
if (!$this->storage()->exists($dir)) {
return collect();
}

$files = $this->storage()->files($dir);
return collect($files)->map(fn(string $file) => new SplFileInfo($file));
}

Expand Down
5 changes: 5 additions & 0 deletions app/ImportRecord.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ public function iipFiles(): Collection
pathinfo($this->filename, PATHINFO_FILENAME)
);
$disk = config('import.iip_disk');

if (!Storage::disk($disk)->exists($dir)) {
return collect();
}

$files = Storage::disk($disk)->files($dir);
return collect($files)->map(fn(string $file) => new SplFileInfo($file));
}
Expand Down
1 change: 1 addition & 0 deletions database/factories/ImportFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public function definition()
return [
'name' => fake()->text(),
'class_name' => MgImporter::class,
'dir_path' => '.',
];
}
}

0 comments on commit 77f1e6a

Please sign in to comment.