[BUGFIX] Make FAL Folder not found handling more user friendly
authorSteffen Ritter <info@rs-websystems.de>
Mon, 3 Sep 2012 09:06:40 +0000 (11:06 +0200)
committerBenjamin Mack <benni@typo3.org>
Wed, 3 Oct 2012 08:40:11 +0000 (10:40 +0200)
If an user moves the folder he currently views in the file
list module, after reload he sees only a red FlashMessage
error because the viewed folder is gone.

As the JavaScript cannot determine what might be the
identifier of the moved folder (after moving) it cannot
redirect there. Thus the file module needs to react more
user friendly in such a situation.

As a solution the module tries parent folders in, too.

Change-Id: Id9e8d988b159c3f0a21b41c4d1782101146ad23c
Fixes: #40547
Releases: 6.0
Reviewed-on: http://review.typo3.org/14301
Tested-by: Marcel Burkhalter
Reviewed-by: Anja Leichsenring
Tested-by: Anja Leichsenring
Reviewed-by: Benjamin Mack
Tested-by: Benjamin Mack
typo3/sysext/filelist/Classes/Controller/FileListController.php
typo3/sysext/lang/locallang_mod_file_list.xlf

index dd708d8..2e67c02 100644 (file)
@@ -51,7 +51,7 @@ class FileListController {
        /* @var \TYPO3\CMS\Core\Resource\Folder $folderObject */
        protected $folderObject;
 
-       /* @var t3lib_FlashMessage $errorMessage */
+       /* @var \TYPO3\CMS\Core\Messaging\FlashMessage $errorMessage */
        protected $errorMessage;
 
        // Pointer to listing
@@ -99,32 +99,45 @@ class FileListController {
                $this->overwriteExistingFiles = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('overwriteExistingFiles');
                // Setting module name:
                $this->MCONF = $GLOBALS['MCONF'];
-               // Create the folder object
-               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();
+                       // 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 {
-                                       $this->folderObject = NULL;
+                                       // 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;
+                                       }
                                }
+                       } 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);
+                               }
+
+                               $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::ERROR);
                }
                // Configure the "menu" - which is used internally to save the values of sorting, displayThumbs etc.
                $this->menuConfig();
@@ -354,7 +367,7 @@ class FileListController {
                        $markerArray = array(
                                'CSH' => $docHeaderButtons['csh'],
                                'FUNC_MENU' => \TYPO3\CMS\Backend\Utility\BackendUtility::getFuncMenu($this->id, 'SET[function]', $this->MOD_SETTINGS['function'], $this->MOD_MENU['function']),
-                               'CONTENT' => $pageContent
+                               'CONTENT' => ($this->errorMessage ? $this->errorMessage->render() : '') . $pageContent
                        );
                        $this->content = $this->doc->moduleBody(array(), $docHeaderButtons, array_merge($markerArray, $otherMarkers));
                        // Renders the module page
@@ -362,6 +375,7 @@ class FileListController {
                } else {
                        $content = '';
                        if ($this->errorMessage) {
+                               $this->errorMessage->setSeverity(\TYPO3\CMS\Core\Messaging\FlashMessage::ERROR);
                                $content = $this->doc->moduleBody(array(), array_merge(array('LEVEL_UP' => '', 'REFRESH' => ''), $this->getButtons()), array('CSH' => '', 'TITLE' => '', 'FOLDER_INFO' => '', 'PAGE_ICON' => '', 'FUNC_MENU' => '', 'CONTENT' => $this->errorMessage->render()));
                        }
                        // Create output - no access (no warning though)
@@ -412,4 +426,4 @@ class FileListController {
 }
 
 
-?>
\ No newline at end of file
+?>
index 02c2bf4..6e24708 100644 (file)
                                <source>You are trying to access a folder in a storage that is not browsable.</source>
                        </trans-unit>
                        <trans-unit id="folderNotFoundTitle" xml:space="preserve">
-                               <source>Folder access denied.</source>
+                               <source>Folder not found.</source>
                        </trans-unit>
                        <trans-unit id="folderNotFoundMessage" xml:space="preserve">
-                               <source>The folder "%s" cannot be accessed.</source>
+                               <source>The folder "%s" cannot be accessed. Trying to use parent folder(s).</source>
                        </trans-unit>
                </body>
        </file>