[BUGFIX] Allow recursive folder deletion 60/35060/9
authorHelmut Hummel <helmut.hummel@typo3.org>
Thu, 4 Dec 2014 22:44:40 +0000 (23:44 +0100)
committerFrans Saris <franssaris@gmail.com>
Thu, 11 Dec 2014 19:14:10 +0000 (20:14 +0100)
Remove the useless check for the number of existing
files in the ExtendedFileUtility.
We now let FAL try to delete recursively by default.
It will tell us, if the permissions do not suffice
for the current user.

Resolves: #63580
Releases: master, 6.2
Change-Id: Iec7ab95d493ce3594a4131b45e5bcb77de9e21b6
Reviewed-on: http://review.typo3.org/35060
Reviewed-by: Markus Klein <klein.t3@reelworx.at>
Tested-by: Markus Klein <klein.t3@reelworx.at>
Reviewed-by: Stefan Neufeind <typo3.neufeind@speedpartner.de>
Reviewed-by: Helmut Hummel <helmut.hummel@typo3.org>
Tested-by: Helmut Hummel <helmut.hummel@typo3.org>
Reviewed-by: Frans Saris <franssaris@gmail.com>
Tested-by: Frans Saris <franssaris@gmail.com>
typo3/sysext/core/Classes/Resource/Driver/AbstractHierarchicalFilesystemDriver.php
typo3/sysext/core/Classes/Resource/Driver/LocalDriver.php
typo3/sysext/core/Classes/Resource/ResourceStorage.php
typo3/sysext/core/Classes/Utility/File/ExtendedFileUtility.php

index 25ae441..17361eb 100644 (file)
@@ -55,6 +55,7 @@ abstract class AbstractHierarchicalFilesystemDriver extends AbstractDriver {
         *
         * @param string $fileIdentifier The file path (including the file name!)
         * @return string
+        * @throws \TYPO3\CMS\Core\Resource\Exception\InvalidPathException
         */
        protected function canonicalizeAndCheckFileIdentifier($fileIdentifier) {
                if ($fileIdentifier !== '') {
index 54e589c..36ecc3e 100644 (file)
@@ -581,6 +581,7 @@ class LocalDriver extends AbstractHierarchicalFilesystemDriver {
         *
         * @param string $fileIdentifier
         * @return string
+        * @throws Exception\InvalidPathException
         */
        protected function getAbsolutePath($fileIdentifier) {
                $relativeFilePath = ltrim($this->canonicalizeAndCheckFileIdentifier($fileIdentifier), '/');
@@ -1018,6 +1019,7 @@ class LocalDriver extends AbstractHierarchicalFilesystemDriver {
         * @param bool $deleteRecursively
         * @return bool
         * @throws Exception\FileOperationErrorException
+        * @throws Exception\InvalidPathException
         */
        public function deleteFolder($folderIdentifier, $deleteRecursively = FALSE) {
                $folderPath = $this->getAbsolutePath($folderIdentifier);
index 453c6ef..b72fe31 100644 (file)
@@ -1842,6 +1842,10 @@ class ResourceStorage implements ResourceStorageInterface {
         * @param Folder $folderObject
         * @param bool $deleteRecursively
         * @throws \RuntimeException
+        * @throws Exception\InsufficientFolderAccessPermissionsException
+        * @throws Exception\InsufficientUserPermissionsException
+        * @throws Exception\FileOperationErrorException
+        * @throws Exception\InvalidPathException
         * @return bool
         */
        public function deleteFolder($folderObject, $deleteRecursively = FALSE) {
index cf84c34..548391d 100644 (file)
@@ -390,21 +390,11 @@ class ExtendedFileUtility extends BasicFileUtility {
                        }
                } else {
                        try {
-                               /** @var $fileObject \TYPO3\CMS\Core\Resource\FolderInterface */
-                               if ($fileObject->getFileCount() > 0) {
-                                       // render a message that the folder could not be deleted because it still contains files
-                                       $flashMessage = GeneralUtility::makeInstance(
-                                               FlashMessage::class,
-                                               sprintf($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:message.description.folderNotDeletedHasFiles'), $fileObject->getName()),
-                                               $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:message.header.folderNotDeletedHasFiles'),
-                                               FlashMessage::WARNING,
-                                               TRUE
-                                       );
-                                       $this->addFlashMessage($flashMessage);
-                               } else {
-                                       $result = $fileObject->delete(TRUE);
-
+                               /** @var \TYPO3\CMS\Core\Resource\Folder $fileObject */
+                               $result = $fileObject->delete(TRUE);
+                               if ($result) {
                                        // notify the user that the folder was deleted
+                                       /** @var FlashMessage $flashMessage */
                                        $flashMessage = GeneralUtility::makeInstance(
                                                FlashMessage::class,
                                                sprintf($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:message.description.folderDeleted'), $fileObject->getName()),
@@ -416,13 +406,14 @@ class ExtendedFileUtility extends BasicFileUtility {
                                        // Log success
                                        $this->writelog(4, 0, 3, 'Directory "%s" deleted', array($fileObject->getIdentifier()));
                                }
-
+                       } catch (\TYPO3\CMS\Core\Resource\Exception\InsufficientUserPermissionsException $e) {
+                               $this->writelog(4, 1, 120, 'Could not delete directory! Is directory "%s" empty? (You are not allowed to delete directories recursively).', array($fileObject->getIdentifier()));
                        } catch (\TYPO3\CMS\Core\Resource\Exception\InsufficientFolderAccessPermissionsException $e) {
                                $this->writelog(4, 1, 123, 'You are not allowed to access the directory', array($fileObject->getIdentifier()));
                        } catch (\TYPO3\CMS\Core\Resource\Exception\NotInMountPointException $e) {
                                $this->writelog(4, 1, 121, 'Target was not within your mountpoints! T="%s"', array($fileObject->getIdentifier()));
-                       } catch (\RuntimeException $e) {
-                               $this->writelog(4, 1, 120, 'Could not delete directory! Write-permission problem? Is directory "%s" empty? (You are not allowed to delete directories recursively).', array($fileObject->getIdentifier()));
+                       } catch (\TYPO3\CMS\Core\Resource\Exception\FileOperationErrorException $e) {
+                               $this->writelog(4, 1, 120, 'Could not delete directory "%s"! Write-permission problem?', array($fileObject->getIdentifier()));
                        }
                }
                return $result;