Skip to content

Commit de5e5a3

Browse files
Upgrade to Laravel 9 + PHP 8.2 - Flysystem
1 parent 0419bc8 commit de5e5a3

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

changelog.md

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
77
## [Unreleased]
88

99
## v5.0
10+
## v5.0.1
1011
### Changed
1112
- Added support for Laravel 9 + PHP > v8.0
1213

src/FlatfileExport.php

+11-5
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,15 @@
66
use Illuminate\Filesystem\FilesystemAdapter;
77
use Illuminate\Support\Arr;
88
use Illuminate\Support\Enumerable;
9+
use Illuminate\Support\Facades\Log;
910
use Illuminate\Support\Facades\Storage;
1011
use Illuminate\Support\Str;
1112
use League\Csv\CannotInsertRecord;
1213
use League\Csv\EncloseField;
1314
use League\Csv\Writer;
14-
use League\Flysystem\Adapter\Local;
15+
use League\Flysystem\FilesystemException;
16+
use League\Flysystem\Local\LocalFilesystemAdapter;
17+
use RealMediaTechnicStaudacher\LaravelFlatfiles\StreamFilters\RemoveSequence;
1518
use RuntimeException;
1619
use Symfony\Component\HttpFoundation\BinaryFileResponse;
1720
use Symfony\Component\HttpFoundation\StreamedResponse;
@@ -177,14 +180,17 @@ public function moveToTarget(): bool
177180
$this->addBomIfNeeded();
178181

179182
/** @noinspection PhpUndefinedMethodInspection */
180-
if ($this->disk->getAdapter() instanceof Local
183+
if ($this->disk->getAdapter() instanceof LocalFilesystemAdapter
181184
&& $this->disk->path($this->pathToFileOnDisk) === $this->pathToLocalTmpFile) {
182185
// No temp file that has be moved
183186
return true;
184187
}
185188

186-
if ($this->disk->putStream($this->pathToFileOnDisk, fopen($this->pathToLocalTmpFile, 'rb'))) {
187-
return unlink($this->pathToLocalTmpFile);
189+
try {
190+
$this->disk->writeStream($this->pathToFileOnDisk, fopen($this->pathToLocalTmpFile, 'rb'));
191+
unlink($this->pathToLocalTmpFile);
192+
} catch (FilesystemException $e) {
193+
Log::error('Could not write file '.$e->getMessage());
188194
}
189195

190196
return false;
@@ -198,7 +204,7 @@ private function determineDefaultWriter(): FlatfileExport
198204
case 'csv':
199205
if (!$this->pathToLocalTmpFile) {
200206
/** @noinspection PhpUndefinedMethodInspection */
201-
if ($this->disk->getAdapter() instanceof Local) {
207+
if ($this->disk->getAdapter() instanceof LocalFilesystemAdapter) {
202208
$this->pathToLocalTmpFile = $this->disk->path($this->pathToFileOnDisk);
203209

204210
$localFileDirectory = pathinfo($this->pathToLocalTmpFile, PATHINFO_DIRNAME);

0 commit comments

Comments
 (0)