Skip to content

Commit 3b29c24

Browse files
authored
fix: preserve RemoteTemporaryFile type when working with remote storage (#4290)
* fix: preserve `RemoteTemporaryFile` type when working with remote storage - Added optional parameter to `RemoteTemporaryFile::sync()` allowing directory creation without content copying - Modified `Writer` to use `RemoteTemporaryFile::sync(false)` instead of creating a new `LocalTemporaryFile` - Prevents type change from `RemoteTemporaryFile` to `LocalTemporaryFile` while ensuring local directory structure exists for writing * chore: Remove unused import
1 parent 910bc3b commit 3b29c24

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

src/Files/RemoteTemporaryFile.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,14 @@ public function delete(): bool
9393
/**
9494
* @return TemporaryFile
9595
*/
96-
public function sync(): TemporaryFile
96+
public function sync(bool $copy = true): TemporaryFile
9797
{
9898
if (!$this->localTemporaryFile->exists()) {
9999
$this->localTemporaryFile = resolve(TemporaryFileFactory::class)
100100
->makeLocal(Arr::last(explode('/', $this->filename)));
101101
}
102102

103-
$this->disk()->copy(
103+
$copy && $this->disk()->copy(
104104
$this,
105105
$this->localTemporaryFile->getLocalPath()
106106
);

src/Writer.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace Maatwebsite\Excel;
44

5-
use Illuminate\Support\Arr;
65
use Maatwebsite\Excel\Concerns\WithBackgroundColor;
76
use Maatwebsite\Excel\Concerns\WithCustomValueBinder;
87
use Maatwebsite\Excel\Concerns\WithDefaultStyles;
@@ -177,8 +176,9 @@ public function write($export, TemporaryFile $temporaryFile, string $writerType)
177176
);
178177

179178
if ($temporaryFile instanceof RemoteTemporaryFile && !$temporaryFile->existsLocally() && !$this->isRunningServerless()) {
180-
$temporaryFile = resolve(TemporaryFileFactory::class)
181-
->makeLocal(Arr::last(explode('/', $temporaryFile->getLocalPath())));
179+
// just ensure that local copy exists (it creates the directory structure),
180+
// no need to copy remote content since it will be overwritten below
181+
$temporaryFile->sync(false);
182182
}
183183

184184
$writer->save(

0 commit comments

Comments
 (0)