[BUGFIX] Exception if thumbnail does not exist 46/26446/4
authorMarkus Klein <klein.t3@mfc-linz.at>
Mon, 16 Dec 2013 10:02:50 +0000 (11:02 +0100)
committerMarkus Klein <klein.t3@mfc-linz.at>
Wed, 26 Mar 2014 20:51:09 +0000 (21:51 +0100)
BackendUtility::thumbCode() tries to retrieve the extension
of a file object that might be NULL.

Add a check for having a valid file object.

Resolves: #54394
Releases: 6.1
Change-Id: Ia97fbb5fd3d9bd53c0d776a93969f9d059eebc4a
Reviewed-on: https://review.typo3.org/26446
Reviewed-by: Oliver Klee
Reviewed-by: Stefan Neufeind
Reviewed-by: Markus Klein
Tested-by: Markus Klein
typo3/sysext/backend/Classes/Utility/BackendUtility.php

index 60e101f..d778e06 100644 (file)
@@ -1572,6 +1572,11 @@ class BackendUtility {
                                if ($theFile) {
                                        $fileName = trim($uploaddir . '/' . $theFile, '/');
                                        $fileObject = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance()->retrieveFileOrFolderObject($fileName);
+                                       if ($fileObject === NULL) {
+                                               $thumbData .= static::createMessageForMissingThumbnail($fileName);
+                                               continue;
+                                       }
+
                                        $fileExtension = $fileObject->getExtension();
                                        if ($fileExtension == 'ttf' || \TYPO3\CMS\Core\Utility\GeneralUtility::inList($GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'], $fileExtension)) {
                                                $imageUrl = $fileObject->process(\TYPO3\CMS\Core\Resource\ProcessedFile::CONTEXT_IMAGEPREVIEW, array(
@@ -1608,6 +1613,23 @@ class BackendUtility {
        }
 
        /**
+        * Create FlashMessage indicating a missing file
+        *
+        * @param string $filePath Path to file including filename
+        * @return string Rendered FlashMessage
+        */
+       static protected function createMessageForMissingThumbnail($filePath) {
+               /** @var \TYPO3\CMS\Core\Messaging\FlashMessage $flashMessage */
+               $flashMessage = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage',
+                       $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:warning.file_missing_text') .
+                       ' <abbr title="' . htmlspecialchars($filePath) . '">' . htmlspecialchars(basename($filePath)) . '</abbr>',
+                       $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:warning.file_missing'),
+                       \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR
+               );
+               return $flashMessage->render();
+       }
+
+       /**
         * Returns single image tag to thumbnail using a thumbnail script (like thumbs.php)
         *
         * @param string $thumbScript Must point to "thumbs.php" relative to the script position