diff options
| author | Greg Roach <greg@subaqua.co.uk> | 2020-12-27 20:12:27 +0000 |
|---|---|---|
| committer | Greg Roach <greg@subaqua.co.uk> | 2021-03-11 10:22:29 +0000 |
| commit | f7cf8a155e2743f3d124eef3d30a558ab062fa4b (patch) | |
| tree | a45052d9dc68b2049f4848e1043f56f6782ad3dd /app/Http/RequestHandlers/DeletePath.php | |
| parent | 7989fe578b0082b5d3378ee0b461904deb3802d1 (diff) | |
| download | webtrees-f7cf8a155e2743f3d124eef3d30a558ab062fa4b.tar.gz webtrees-f7cf8a155e2743f3d124eef3d30a558ab062fa4b.tar.bz2 webtrees-f7cf8a155e2743f3d124eef3d30a558ab062fa4b.zip | |
Remove vendor dir, add support for PHP 8.0, drop support for PHP 7.1 and 7.2
Diffstat (limited to 'app/Http/RequestHandlers/DeletePath.php')
| -rw-r--r-- | app/Http/RequestHandlers/DeletePath.php | 38 |
1 files changed, 16 insertions, 22 deletions
diff --git a/app/Http/RequestHandlers/DeletePath.php b/app/Http/RequestHandlers/DeletePath.php index 7d0cdaf5e8..304f337a93 100644 --- a/app/Http/RequestHandlers/DeletePath.php +++ b/app/Http/RequestHandlers/DeletePath.php @@ -22,6 +22,9 @@ namespace Fisharebest\Webtrees\Http\RequestHandlers; use Fisharebest\Webtrees\FlashMessages; use Fisharebest\Webtrees\I18N; use Fisharebest\Webtrees\Registry; +use League\Flysystem\FilesystemException; +use League\Flysystem\UnableToDeleteDirectory; +use League\Flysystem\UnableToDeleteFile; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Server\RequestHandlerInterface; @@ -31,6 +34,7 @@ use function assert; use function e; use function is_string; use function response; +use function str_ends_with; /** * Delete a file or folder from the data filesystem. @@ -49,30 +53,20 @@ class DeletePath implements RequestHandlerInterface $path = $request->getQueryParams()['path']; assert(is_string($path)); - if ($data_filesystem->has($path)) { - $metadata = $data_filesystem->getMetadata($path); - - switch ($metadata['type']) { - case 'file': - try { - $data_filesystem->delete($path); - FlashMessages::addMessage(I18N::translate('The file %s has been deleted.', e($path)), 'success'); - } catch (Throwable $ex) { - FlashMessages::addMessage(I18N::translate('The file %s could not be deleted.', e($path)), 'danger'); - } - break; - - case 'dir': - try { - $data_filesystem->deleteDir($path); - FlashMessages::addMessage(I18N::translate('The folder %s has been deleted.', e($path)), 'success'); - } catch (Throwable $ex) { - FlashMessages::addMessage(I18N::translate('The folder %s could not be deleted.', e($path)), 'danger'); - } - break; + if (str_ends_with($path, '/')) { + try { + $data_filesystem->deleteDirectory($path); + FlashMessages::addMessage(I18N::translate('The folder %s has been deleted.', e($path)), 'success'); + } catch (FilesystemException | UnableToDeleteDirectory $ex) { + FlashMessages::addMessage(I18N::translate('The folder %s could not be deleted.', e($path)), 'danger'); } } else { - FlashMessages::addMessage(I18N::translate('The file %s could not be deleted.', e($path)), 'danger'); + try { + $data_filesystem->delete($path); + FlashMessages::addMessage(I18N::translate('The file %s has been deleted.', e($path)), 'success'); + } catch (FilesystemException | UnableToDeleteFile $ex) { + FlashMessages::addMessage(I18N::translate('The file %s could not be deleted.', e($path)), 'danger'); + } } return response(); |
