[BUGFIX] Catch exception in filelist when file is missing 84/28284/5
authorFrans Saris <franssaris@gmail.com>
Wed, 12 Mar 2014 08:48:37 +0000 (09:48 +0100)
committerGeorg Ringer <georg.ringer@gmail.com>
Wed, 19 Mar 2014 07:44:25 +0000 (08:44 +0100)
The code responsible for rendering the thumbs belonging to a
record doesn't catch the exceptions when a file couldn't be found.

This change adds a try catch around the functions that
tries to retrieve the file and displays a flash message when
the file is missing.

Resolves: #56077
Releases: 6.2
Change-Id: Icc6550db43c8738c74fd7ea8faac6e99a54bc0f3
Reviewed-on: https://review.typo3.org/28284
Reviewed-by: Markus Klein
Reviewed-by: Wouter Wolters
Tested-by: Wouter Wolters
Reviewed-by: Georg Ringer
Tested-by: Georg Ringer
typo3/sysext/backend/Classes/Utility/BackendUtility.php

index 07f2e0e..66af510 100644 (file)
@@ -29,6 +29,7 @@ namespace TYPO3\CMS\Backend\Utility;
 
 use TYPO3\CMS\Backend\Utility\IconUtility;
 use TYPO3\CMS\Core\Messaging\FlashMessage;
+use TYPO3\CMS\Core\Resource\File;
 use TYPO3\CMS\Core\Resource\ProcessedFile;
 use TYPO3\CMS\Core\Resource\ResourceFactory;
 use TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser;
@@ -1538,15 +1539,26 @@ class BackendUtility {
                        foreach ($thumbs as $theFile) {
                                if ($theFile) {
                                        $fileName = trim($uploaddir . '/' . $theFile, '/');
-                                       $fileObject = ResourceFactory::getInstance()->retrieveFileOrFolderObject($fileName);
-                                       $fileExtension = $fileObject->getExtension();
-
-                                       if ($fileObject->isMissing()) {
-                                               $flashMessage = \TYPO3\CMS\Core\Resource\Utility\BackendUtility::getFlashMessageForMissingFile($fileObject);
+                                       try {
+                                               /** @var File $fileObject */
+                                               $fileObject = ResourceFactory::getInstance()->retrieveFileOrFolderObject($fileName);
+                                               if ($fileObject->isMissing()) {
+                                                       $flashMessage = \TYPO3\CMS\Core\Resource\Utility\BackendUtility::getFlashMessageForMissingFile($fileObject);
+                                                       $thumbData .= $flashMessage->render();
+                                                       continue;
+                                               }
+                                       } catch (\TYPO3\CMS\Core\Resource\Exception\ResourceDoesNotExistException $exception) {
+                                               /** @var \TYPO3\CMS\Core\Messaging\FlashMessage $flashMessage */
+                                               $flashMessage = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage',
+                                                       htmlspecialchars($exception->getMessage()),
+                                                       $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:warning.file_missing', TRUE),
+                                                       \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR
+                                               );
                                                $thumbData .= $flashMessage->render();
                                                continue;
                                        }
 
+                                       $fileExtension = $fileObject->getExtension();
                                        if ($fileExtension == 'ttf' || GeneralUtility::inList($GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'], $fileExtension)) {
                                                $imageUrl = $fileObject->process(ProcessedFile::CONTEXT_IMAGEPREVIEW, array(
                                                        'width' => $sizeParts[0],