Skip to content

Commit 69e359a

Browse files
committed
Fix CSV import storage disk handling and fail loudly.
This forces import uploads and reads to use the local disk and throws explicit exceptions when files are missing or unreadable so queue failures are visible. Made-with: Cursor
1 parent c1d9ceb commit 69e359a

2 files changed

Lines changed: 18 additions & 8 deletions

File tree

src/Jobs/ImportCourseFromCsv.php

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@
99
use Illuminate\Foundation\Bus\Dispatchable;
1010
use Illuminate\Queue\InteractsWithQueue;
1111
use Illuminate\Queue\SerializesModels;
12-
use Illuminate\Support\Facades\File;
12+
use Illuminate\Support\Facades\Storage;
1313
use Maatwebsite\Excel\Facades\Excel;
14+
use RuntimeException;
1415
use Tapp\FilamentLms\Imports\CourseStepsImport;
1516

1617
class ImportCourseFromCsv implements ShouldQueue
@@ -19,17 +20,25 @@ class ImportCourseFromCsv implements ShouldQueue
1920

2021
public function __construct(
2122
protected string $courseName,
22-
protected string $filePath
23+
protected string $storedPath
2324
) {}
2425

2526
public function handle(): void
2627
{
27-
if (! File::isReadable($this->filePath)) {
28-
return;
28+
$disk = Storage::disk('local');
29+
30+
if (! $disk->exists($this->storedPath)) {
31+
throw new RuntimeException("Course import file does not exist on local disk: {$this->storedPath}");
32+
}
33+
34+
$filePath = $disk->path($this->storedPath);
35+
36+
if (! is_readable($filePath)) {
37+
throw new RuntimeException("Course import file is not readable: {$filePath}");
2938
}
3039

31-
Excel::import(new CourseStepsImport($this->courseName), $this->filePath);
40+
Excel::import(new CourseStepsImport($this->courseName), $filePath);
3241

33-
File::delete($this->filePath);
42+
$disk->delete($this->storedPath);
3443
}
3544
}

src/Resources/CourseResource/Pages/ListCourses.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ protected function getHeaderActions(): array
5959

6060
$storedPath = $file->storeAs(
6161
'filament-lms/course-imports',
62-
Str::uuid().'.csv'
62+
Str::uuid().'.csv',
63+
'local'
6364
);
6465

6566
if ($storedPath === false) {
@@ -72,7 +73,7 @@ protected function getHeaderActions(): array
7273
return;
7374
}
7475

75-
ImportCourseFromCsv::dispatch($courseName, Storage::path($storedPath));
76+
ImportCourseFromCsv::dispatch($courseName, $storedPath);
7677

7778
Notification::make()
7879
->title('Import queued')

0 commit comments

Comments
 (0)