From da458dc4e2adbee2be6aaae4abbd498cc6523acb Mon Sep 17 00:00:00 2001 From: Andreas Wolf <andreas.wolf@typo3.org> Date: Wed, 3 Oct 2012 17:40:08 +0200 Subject: [PATCH] [BUGFIX] Root-level folders cannot be displayed 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 --- .../core/Classes/Resource/ResourceFactory.php | 15 +++++ .../Classes/Controller/FileListController.php | 66 +++++++++---------- 2 files changed, 45 insertions(+), 36 deletions(-) diff --git a/typo3/sysext/core/Classes/Resource/ResourceFactory.php b/typo3/sysext/core/Classes/Resource/ResourceFactory.php index ab8dd09d64d9..8d4c15e7753e 100644 --- a/typo3/sysext/core/Classes/Resource/ResourceFactory.php +++ b/typo3/sysext/core/Classes/Resource/ResourceFactory.php @@ -348,6 +348,21 @@ class ResourceFactory implements \TYPO3\CMS\Core\SingletonInterface { return $this->getStorageObject($storageUid)->getFolder($folderIdentifier); } + /** + * 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. * diff --git a/typo3/sysext/filelist/Classes/Controller/FileListController.php b/typo3/sysext/filelist/Classes/Controller/FileListController.php index d38aabbf589c..ac15a23b6c20 100644 --- a/typo3/sysext/filelist/Classes/Controller/FileListController.php +++ b/typo3/sysext/filelist/Classes/Controller/FileListController.php @@ -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(); -- GitLab