You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using import TemporaryFile::copyFrom an exception is thrown because line: if (!$diskInstance->exists($filePath)) {
presumes the existence of a deprecated method that was removed from \League\Flysystem\FilesystemAdapter with v3
This line should call fileExists: if (!$diskInstance->fileExists($filePath)) {
I am importing a file from Azure Blob, but
How can the issue be reproduced?
create a new laravel project:
laravel new flysystem-repro
cd flysystem-repro
install maatwebsite/excel: composer require maatwebsite/excel
create an import class: php artisan make:import UsersImport --model=User
call from a controller:
use Maatwebsite\Excel\Facades\Excel;
use App\Imports\UsersImport;
public function import()
{
$filePath = storage_path('app/test.xlsx'); // Use a simple XLSX file
Excel::import(new UsersImport, $filePath, 'azure-blob', \Maatwebsite\Excel\Excel::XLSX);
}
What should be the expected behaviour?
I would expect the package to use fileExists from Flysystem v3, which is a requirement for Laravel 10, as the package claims support for Laravel 10.
I am not sure if you are trying to maintain backwards-compatibility for versions of Laravel 8 that used the original version of flysystem, but if so, I would suggest this change to Maatwebsite\Excel\Files\TemporaryFile::copyFrom:
/**
* @param string|UploadedFile $filePath
* @param string|null $disk
* @return TemporaryFile
*/
public function copyFrom($filePath, string $disk = null): TemporaryFile
{
if ($filePath instanceof UploadedFile) {
$readStream = fopen($filePath->getRealPath(), 'rb');
} elseif ($disk === null && realpath($filePath) !== false) {
$readStream = fopen($filePath, 'rb');
} else {
$diskInstance = app('filesystem')->disk($disk);
// Check for Flysystem v3 (fileExists) and fallback to Flysystem v2 (exists)
if (method_exists($diskInstance, 'fileExists')) {
if (!$diskInstance->fileExists($filePath)) {
$logPath = '[' . $filePath . ']';
if ($disk) {
$logPath .= ' (' . $disk . ')';
}
throw new FileNotFoundException('File ' . $logPath . ' does not exist and cannot be imported.');
}
} else {
// For Flysystem v2
if (!$diskInstance->exists($filePath)) {
$logPath = '[' . $filePath . ']';
if ($disk) {
$logPath .= ' (' . $disk . ')';
}
throw new FileNotFoundException('File ' . $logPath . ' does not exist and cannot be imported.');
}
}
$readStream = $diskInstance->readStream($filePath);
}
$this->put($readStream);
if (is_resource($readStream)) {
fclose($readStream);
}
return $this->sync();
}
Otherwise, if you are only supporting newer Laravel versions that use Flysystem v3:
/**
* @param string|UploadedFile $filePath
* @param string|null $disk
* @return TemporaryFile
*/
public function copyFrom($filePath, string $disk = null): TemporaryFile
{
if ($filePath instanceof UploadedFile) {
$readStream = fopen($filePath->getRealPath(), 'rb');
} elseif ($disk === null && realpath($filePath) !== false) {
$readStream = fopen($filePath, 'rb');
} else {
$diskInstance = app('filesystem')->disk($disk);
// For Flysystem v3: Use fileExists() instead of exists()
if (!$diskInstance->fileExists($filePath)) {
$logPath = '[' . $filePath . ']';
if ($disk) {
$logPath .= ' (' . $disk . ')';
}
throw new FileNotFoundException('File ' . $logPath . ' does not exist and cannot be imported.');
}
$readStream = $diskInstance->readStream($filePath);
}
$this->put($readStream);
if (is_resource($readStream)) {
fclose($readStream);
}
return $this->sync();
}
The text was updated successfully, but these errors were encountered:
Is the bug applicable and reproducable to the latest version of the package and hasn't it been reported before?
What version of Laravel Excel are you using?
3.1.58
What version of Laravel are you using?
10.48.22
What version of PHP are you using?
8.3.12
Describe your issue
When using import TemporaryFile::copyFrom an exception is thrown because line:
if (!$diskInstance->exists($filePath)) {
presumes the existence of a deprecated method that was removed from \League\Flysystem\FilesystemAdapter with v3
This line should call fileExists:
if (!$diskInstance->fileExists($filePath)) {
I am importing a file from Azure Blob, but
How can the issue be reproduced?
create a new laravel project:
install maatwebsite/excel:
composer require maatwebsite/excel
create an import class:
php artisan make:import UsersImport --model=User
call from a controller:
What should be the expected behaviour?
I would expect the package to use fileExists from Flysystem v3, which is a requirement for Laravel 10, as the package claims support for Laravel 10.
I am not sure if you are trying to maintain backwards-compatibility for versions of Laravel 8 that used the original version of flysystem, but if so, I would suggest this change to Maatwebsite\Excel\Files\TemporaryFile::copyFrom:
Otherwise, if you are only supporting newer Laravel versions that use Flysystem v3:
The text was updated successfully, but these errors were encountered: