From b0e778d2e98fc056cc16b0e2d28c1fdb844b513b Mon Sep 17 00:00:00 2001 From: Greg Roach Date: Thu, 11 Mar 2021 11:55:18 +0000 Subject: [PATCH] Remove vendor dir, add support for PHP 8.0, drop support for PHP 7.1 and 7.2 --- app/Http/RequestHandlers/ExportGedcomClient.php | 7 +++---- app/Http/RequestHandlers/UploadMediaAction.php | 2 +- app/Module/ClippingsCartModule.php | 7 +++---- app/Services/HousekeepingService.php | 17 ++++++++--------- app/Webtrees.php | 2 +- 5 files changed, 16 insertions(+), 19 deletions(-) diff --git a/app/Http/RequestHandlers/ExportGedcomClient.php b/app/Http/RequestHandlers/ExportGedcomClient.php index 7260ced53fd..595fcc9fa4b 100644 --- a/app/Http/RequestHandlers/ExportGedcomClient.php +++ b/app/Http/RequestHandlers/ExportGedcomClient.php @@ -27,6 +27,7 @@ use Fisharebest\Webtrees\Tree; use Illuminate\Database\Capsule\Manager as DB; use League\Flysystem\Filesystem; +use League\Flysystem\ZipArchive\FilesystemZipArchiveProvider; use League\Flysystem\ZipArchive\ZipArchiveAdapter; use Psr\Http\Message\ResponseFactoryInterface; use Psr\Http\Message\ResponseInterface; @@ -121,7 +122,8 @@ public function handle(ServerRequestInterface $request): ResponseInterface // Create a new/empty .ZIP file $temp_zip_file = stream_get_meta_data(tmpfile())['uri']; - $zip_adapter = new ZipArchiveAdapter($temp_zip_file); + $zip_provider = new FilesystemZipArchiveProvider($temp_zip_file, 0755); + $zip_adapter = new ZipArchiveAdapter($zip_provider); $zip_filesystem = new Filesystem($zip_adapter); $zip_filesystem->writeStream($download_filename, $tmp_stream); fclose($tmp_stream); @@ -146,9 +148,6 @@ public function handle(ServerRequestInterface $request): ResponseInterface } } - // Need to force-close ZipArchive filesystems. - $zip_adapter->getArchive()->close(); - // Use a stream, so that we do not have to load the entire file into memory. $stream_factory = app(StreamFactoryInterface::class); assert($stream_factory instanceof StreamFactoryInterface); diff --git a/app/Http/RequestHandlers/UploadMediaAction.php b/app/Http/RequestHandlers/UploadMediaAction.php index bcd41b94ee0..62b9f32c07f 100644 --- a/app/Http/RequestHandlers/UploadMediaAction.php +++ b/app/Http/RequestHandlers/UploadMediaAction.php @@ -116,7 +116,7 @@ public function handle(ServerRequestInterface $request): ResponseInterface $path = $folder . $filename; - if ($data_filesystem->has($path)) { + if ($data_filesystem->fileExists($path)) { FlashMessages::addMessage(I18N::translate('The file %s already exists. Use another filename.', $path, 'error')); continue; } diff --git a/app/Module/ClippingsCartModule.php b/app/Module/ClippingsCartModule.php index ece0452ada1..b450fe4f303 100644 --- a/app/Module/ClippingsCartModule.php +++ b/app/Module/ClippingsCartModule.php @@ -48,6 +48,7 @@ use Fisharebest\Webtrees\Tree; use Illuminate\Support\Collection; use League\Flysystem\Filesystem; +use League\Flysystem\ZipArchive\FilesystemZipArchiveProvider; use League\Flysystem\ZipArchive\ZipArchiveAdapter; use Psr\Http\Message\ResponseFactoryInterface; use Psr\Http\Message\ResponseInterface; @@ -279,7 +280,8 @@ public function postDownloadAction(ServerRequestInterface $request): ResponseInt // Create a new/empty .ZIP file $temp_zip_file = stream_get_meta_data(tmpfile())['uri']; - $zip_adapter = new ZipArchiveAdapter($temp_zip_file); + $zip_provider = new FilesystemZipArchiveProvider($temp_zip_file, 0755); + $zip_adapter = new ZipArchiveAdapter($zip_provider); $zip_filesystem = new Filesystem($zip_adapter); $media_filesystem = $tree->mediaFilesystem($data_filesystem); @@ -375,9 +377,6 @@ public function postDownloadAction(ServerRequestInterface $request): ResponseInt // Finally add the GEDCOM file to the .ZIP file. $zip_filesystem->writeStream('clippings.ged', $stream); - // Need to force-close ZipArchive filesystems. - $zip_adapter->getArchive()->close(); - // Use a stream, so that we do not have to load the entire file into memory. $stream = app(StreamFactoryInterface::class)->createStreamFromFile($temp_zip_file); diff --git a/app/Services/HousekeepingService.php b/app/Services/HousekeepingService.php index 598e887c3c5..957d21a84cb 100644 --- a/app/Services/HousekeepingService.php +++ b/app/Services/HousekeepingService.php @@ -23,7 +23,10 @@ use Fisharebest\Webtrees\Carbon; use Illuminate\Database\Capsule\Manager as DB; use League\Flysystem\Filesystem; +use League\Flysystem\FilesystemException; use League\Flysystem\FilesystemOperator; +use League\Flysystem\UnableToDeleteDirectory; +use League\Flysystem\UnableToDeleteFile; /** * Clean up old data, files and folders. @@ -461,17 +464,13 @@ private function deleteFileOrFolder(FilesystemOperator $filesystem, string $path { if ($filesystem->fileExists($path)) { try { - $metadata = $filesystem->getMetadata($path); - - if ($metadata['type'] === 'dir') { + $filesystem->delete($path); + } catch (FilesystemException | UnableToDeleteFile $ex) { + try { $filesystem->deleteDirectory($path); + } catch (FilesystemException | UnableToDeleteDirectory $ex) { + return false; } - - if ($metadata['type'] === 'file') { - $filesystem->delete($path); - } - } catch (Exception $ex) { - return false; } } diff --git a/app/Webtrees.php b/app/Webtrees.php index d94f4b67774..3613d5badd2 100644 --- a/app/Webtrees.php +++ b/app/Webtrees.php @@ -99,7 +99,7 @@ class Webtrees public const STABILITY = '-dev'; // Version number - public const VERSION = '2.0.13' . self::STABILITY; + public const VERSION = '2.1.0' . self::STABILITY; // Project website. public const URL = 'https://webtrees.net/';