Skip to content

Commit

Permalink
Merge pull request #125 from adriaardila/filament3
Browse files Browse the repository at this point in the history
Fix import with local disks not working after last beta release
  • Loading branch information
frankyso authored Sep 14, 2023
2 parents 809eb09 + 618dd15 commit 15aa163
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
3 changes: 1 addition & 2 deletions src/Actions/ImportAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
use Filament\Forms\Components\Hidden;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\Toggle;
use Illuminate\Support\Facades\App;
use Konnco\FilamentImport\Concerns\HasActionMutation;
use Konnco\FilamentImport\Concerns\HasActionUniqueField;
use Konnco\FilamentImport\Concerns\HasTemporaryDisk;
Expand Down Expand Up @@ -165,7 +164,7 @@ private function getFields(ImportField|Field $field): Field
$options = $this->cachedHeadingOptions;

if (count($options) === 0) {
$options = $this->toCollection($filePath, ! App::runningUnitTests() ? $this->getTemporaryDisk() : null)->first()?->first()->filter(fn ($value) => $value != null)->map('trim')->toArray();
$options = $this->toCollection($filePath, $this->temporaryDiskIsRemote() ? $this->getTemporaryDisk() : null)->first()?->first()->filter(fn ($value) => $value != null)->map('trim')->toArray();
}

$selected = array_search($field->getName(), $options);
Expand Down
6 changes: 6 additions & 0 deletions src/Concerns/HasTemporaryDisk.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,10 @@ public function temporaryDirectory(string $temporaryPath): void
{
$this->temporaryDirectory = $temporaryPath;
}

public function temporaryDiskIsRemote(): bool
{
$driver = config("filesystems.disks.{$this->getTemporaryDisk()}.driver");
return in_array($driver, ['s3', 'ftp', 'sftp']);
}
}
7 changes: 3 additions & 4 deletions src/Import.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@
use Konnco\FilamentImport\Actions\ImportField;
use Konnco\FilamentImport\Concerns\HasActionMutation;
use Konnco\FilamentImport\Concerns\HasActionUniqueField;
use Konnco\FilamentImport\Concerns\HasTemporaryDisk;
use Maatwebsite\Excel\Concerns\Importable;

class Import
{
use Importable;
use HasActionMutation;
use HasActionUniqueField;
use HasTemporaryDisk;

protected string $spreadsheet;

Expand Down Expand Up @@ -104,10 +106,7 @@ public function handleBlankRows($shouldHandleBlankRows = false): static

public function getSpreadsheetData(): Collection
{
$driver = config("filesystems.disks.{$this->disk}.driver");
$isRemote = in_array($driver, ['s3', 'ftp', 'sftp']);

$data = $this->toCollection($isRemote ? $this->spreadsheet : new UploadedFile(Storage::disk($this->disk)->path($this->spreadsheet), $this->spreadsheet))
$data = $this->toCollection($this->temporaryDiskIsRemote() ? $this->spreadsheet : new UploadedFile(Storage::disk($this->disk)->path($this->spreadsheet), $this->spreadsheet))
->first()
->skip((int) $this->shouldSkipHeader);
if (! $this->shouldHandleBlankRows) {
Expand Down

0 comments on commit 15aa163

Please sign in to comment.