[BUGFIX] Root-level folders cannot be displayed
authorAndreas Wolf <andreas.wolf@typo3.org>
Wed, 3 Oct 2012 15:40:08 +0000 (17:40 +0200)
committerHelmut Hummel <helmut.hummel@typo3.org>
Tue, 9 Oct 2012 10:07:50 +0000 (12:07 +0200)
Due to a recent fix in the folder resolving mechanism, the root-level
folders of a storage were not displayed anymore in the file list module.

This commit re-enables displaying rootlevel folders, at the expense of
removing the hierarchy resolving (i.e., we now always choose the
root-level folder of a storage instead of the next higher level. This
concept was broken anyways, as folders do not need to be in a hierarchy.
Thus we cannot use such a simple resolving mechanism, but have to
implement that per driver instead.

There is currently no permission check in the file list controller, so
both the selected folder and the (fallback) root-level folder might be
displayed though the user has no permission to do so.

Change-Id: I71580031f0cc14b2cfac76b80b3641dd05a3e052
Resolves: #41569
Releases: 6.0
Reviewed-on: http://review.typo3.org/15321
Reviewed-by: Helmut Hummel
Tested-by: Helmut Hummel
typo3/sysext/core/Classes/Resource/ResourceFactory.php
typo3/sysext/filelist/Classes/Controller/FileListController.php

index ab8dd09..8d4c15e 100644 (file)
@@ -349,6 +349,21 @@ class ResourceFactory implements \TYPO3\CMS\Core\SingletonInterface {
        }
 
        /**
+        * Gets a storage object from a combined identifier
+        *
+        * @param string $identifier An identifier of the form [storage uid]:[object identifier]
+        * @return \TYPO3\CMS\Core\Resource\ResourceStorage
+        */
+       public function getStorageObjectFromCombinedIdentifier($identifier) {
+               $parts = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(':', $identifier);
+               if (count($parts) === 2) {
+                       $storageUid = $parts[0];
+               }
+
+               return $this->getStorageObject($storageUid);
+       }
+
+       /**
         * Gets a file or folder object.
         *
         * @param string $identifier
index d38aabb..ac15a23 100644 (file)
@@ -99,45 +99,39 @@ class FileListController {
                $this->overwriteExistingFiles = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('overwriteExistingFiles');
                // Setting module name:
                $this->MCONF = $GLOBALS['MCONF'];
-                       // Create the folder object, even try parent folders
-               while ($this->folderObject === NULL && count(\TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode('/', $combinedIdentifier, TRUE)) >= 1) {
-                       try {
-                               if ($combinedIdentifier) {
-                                       $fileFactory = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Resource\\ResourceFactory');
-                                       $this->folderObject = $fileFactory->getFolderObjectFromCombinedIdentifier($combinedIdentifier);
-                                       // Disallow the rendering of the processing folder (e.g. could be called manually)
-                                       // and all folders without any defined storage
-                                       if ($this->folderObject && ($this->folderObject->getStorage()->getUid() == 0 || trim($this->folderObject->getStorage()->getProcessingFolder()->getIdentifier(), '/') == trim($this->folderObject->getIdentifier(), '/'))) {
-                                               $this->folderObject = NULL;
-                                       }
-                               } else {
-                                       // Take the first object of the first storage
-                                       $fileStorages = $GLOBALS['BE_USER']->getFileStorages();
-                                       $fileStorage = reset($fileStorages);
-                                       if ($fileStorage) {
-                                               // Validating the input "id" (the path, directory!) and
-                                               // checking it against the mounts of the user. - now done in the controller
-                                               $this->folderObject = $fileStorage->getRootLevelFolder();
-                                       } else {
-                                               $this->folderObject = NULL;
-                                       }
+               try {
+                       if ($combinedIdentifier) {
+                               /** @var $fileFactory \TYPO3\CMS\Core\Resource\ResourceFactory */
+                               $fileFactory = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Resource\\ResourceFactory');
+                               $this->folderObject = $fileFactory->getFolderObjectFromCombinedIdentifier($combinedIdentifier);
+                               // Disallow the rendering of the processing folder (e.g. could be called manually)
+                               // and all folders without any defined storage
+                               if ($this->folderObject && ($this->folderObject->getStorage()->getUid() == 0 || trim($this->folderObject->getStorage()->getProcessingFolder()->getIdentifier(), '/') === trim($this->folderObject->getIdentifier(), '/'))) {
+                                       $storage = $fileFactory->getStorageObjectFromCombinedIdentifier($combinedIdentifier);
+                                       $this->folderObject = $storage->getRootLevelFolder();
                                }
-                       } catch (\TYPO3\CMS\Core\Resource\Exception\FolderDoesNotExistException $fileException) {
-                               // Set folder object to null and throw a message later on
-                               $this->folderObject = NULL;
-                               if ($this->id == $combinedIdentifier) {
-                                       $this->errorMessage = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage',
-                                               sprintf($GLOBALS['LANG']->getLL('folderNotFoundMessage', TRUE),
-                                                               htmlspecialchars($this->id)
-                                               ),
-                                               $GLOBALS['LANG']->getLL('folderNotFoundTitle', TRUE),
-                                               \TYPO3\CMS\Core\Messaging\FlashMessage::NOTICE);
+                       } else {
+                               // Take the first object of the first storage
+                               $fileStorages = $GLOBALS['BE_USER']->getFileStorages();
+                               $fileStorage = reset($fileStorages);
+                               if ($fileStorage) {
+                                       // Validating the input "id" (the path, directory!) and
+                                       // checking it against the mounts of the user. - now done in the controller
+                                       $this->folderObject = $fileStorage->getRootLevelFolder();
+                               } else {
+                                       throw new \RuntimeException('Could not find any folder to be displayed.', 1349276894);
                                }
-
-                               $combinedIdentifierParts = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode('/', $combinedIdentifier, TRUE);
-                               array_pop($combinedIdentifierParts);
-                               $combinedIdentifier = implode('/', $combinedIdentifierParts) . '/';
                        }
+               } catch (\TYPO3\CMS\Core\Resource\Exception\FolderDoesNotExistException $fileException) {
+                       // Set folder object to null and throw a message later on
+                       $this->folderObject = NULL;
+                       $this->errorMessage = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage',
+                               sprintf($GLOBALS['LANG']->getLL('folderNotFoundMessage', TRUE),
+                                               htmlspecialchars($this->id)
+                               ),
+                               $GLOBALS['LANG']->getLL('folderNotFoundTitle', TRUE),
+                               \TYPO3\CMS\Core\Messaging\FlashMessage::NOTICE
+                       );
                }
                // Configure the "menu" - which is used internally to save the values of sorting, displayThumbs etc.
                $this->menuConfig();