[TASK] Frontend should not expose exception for missing files
authorSteffen Ritter <info@rs-websystems.de>
Tue, 9 Oct 2012 16:03:28 +0000 (18:03 +0200)
committerHelmut Hummel <helmut.hummel@typo3.org>
Tue, 9 Oct 2012 19:10:21 +0000 (21:10 +0200)
The exceptions within FAL are not catched in frontend. The
webpage renders broken instead of gracefully dealing with that.

Change-Id: Idf23f059336f723ba27a10d25ff60fcc49f9648b
Fixes: #38829
Releases: 6.0
Reviewed-on: http://review.typo3.org/15453
Reviewed-by: Benjamin Mack
Tested-by: Benjamin Mack
Reviewed-by: Helmut Hummel
Tested-by: Helmut Hummel
typo3/sysext/core/Classes/Resource/Service/FrontendContentAdapterService.php
typo3/sysext/frontend/Classes/ContentObject/ContentObjectRenderer.php
typo3/sysext/frontend/Classes/ContentObject/FilesContentObject.php

index 566c7e7..e9662e2 100644 (file)
@@ -106,11 +106,6 @@ class FrontendContentAdapterService {
                                                        $row[$oldFieldName] = $fieldContents;
                                                }
                                        }
-                                       if (count($files) > 0) {
-
-                                       } elseif ($row['image'] > 0) {
-                                               throw new \RuntimeException('inconsistent count field in "' . $table . '".' . $migrateFieldName, 1333754565);
-                                       }
                                }
                        }
                }
index 227d20e..8c3669f 100644 (file)
@@ -5024,22 +5024,29 @@ class ContentObjectRenderer {
                                $imageResource = $gifCreator->getImageDimensions($theImage);
                                break;
                        default:
-                               if (\TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($file)) {
-                                       $fileObject = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance()->retrieveFileOrFolderObject($file);
-                               } else {
-                                       if ($fileArray['import.']) {
-                                               $ifile = $this->stdWrap('', $fileArray['import.']);
-                                               if ($ifile) {
-                                                       if (\TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($ifile)) {
-                                                               $file = $ifile;
-                                                       } else {
-                                                               $file = $fileArray['import'] . $ifile;
+                               try {
+                                       if (\TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($file)) {
+                                               $fileObject = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance()->retrieveFileOrFolderObject($file);
+                                       } else {
+                                               if ($fileArray['import.']) {
+                                                       $ifile = $this->stdWrap('', $fileArray['import.']);
+                                                       if ($ifile) {
+                                                               if (\TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($ifile)) {
+                                                                       $file = $ifile;
+                                                               } else {
+                                                                       $file = $fileArray['import'] . $ifile;
+                                                               }
                                                        }
                                                }
+                                               // clean ../ sections of the path and resolve to proper string. This is necessary for the Tx_File_BackwardsCompatibility_TslibContentAdapter to work.
+                                               $file = \TYPO3\CMS\Core\Utility\GeneralUtility::resolveBackPath($file);
+                                               $fileObject = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance()->retrieveFileOrFolderObject($file);
                                        }
-                                       // clean ../ sections of the path and resolve to proper string. This is necessary for the Tx_File_BackwardsCompatibility_TslibContentAdapter to work.
-                                       $file = \TYPO3\CMS\Core\Utility\GeneralUtility::resolveBackPath($file);
-                                       $fileObject = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance()->retrieveFileOrFolderObject($file);
+                               } catch(\TYPO3\CMS\Core\Resource\Exception $exception) {
+                                       /** @var \TYPO3\CMS\Core\Log\Logger $logger */
+                                       $logger = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\CMS\Core\Log\LogManager')->getLogger();
+                                       $logger->warning('The image "' . $file . '" could not be found and won\'t be included in frontend output');
+                                       return NULL;
                                }
                                if ($fileObject instanceof \TYPO3\CMS\Core\Resource\FileInterface) {
                                        $processingConfiguration = array();
@@ -5307,15 +5314,23 @@ class ContentObjectRenderer {
                $parts = explode(':', $key);
                $fileUidOrCurrentKeyword = $parts[0];
                $requestedFileInformationKey = $parts[1];
-               if ($fileUidOrCurrentKeyword === 'current') {
-                       $fileObject = $this->getCurrentFile();
-               } elseif (\TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($fileUidOrCurrentKeyword)) {
-                       /** @var \TYPO3\CMS\Core\Resource\ResourceFactory $fileFactory */
-                       $fileFactory = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Resource\\ResourceFactory');
-                       $fileObject = $fileFactory->getFileObject($fileUidOrCurrentKeyword);
-               } else {
+               try {
+                       if ($fileUidOrCurrentKeyword === 'current') {
+                               $fileObject = $this->getCurrentFile();
+                       } elseif (\TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($fileUidOrCurrentKeyword)) {
+                               /** @var \TYPO3\CMS\Core\Resource\ResourceFactory $fileFactory */
+                               $fileFactory = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Resource\\ResourceFactory');
+                               $fileObject = $fileFactory->getFileObject($fileUidOrCurrentKeyword);
+                       } else {
+                               $fileObject = NULL;
+                       }
+               } catch (\TYPO3\CMS\Core\Resource\Exception $exception) {
+                       /** @var \TYPO3\CMS\Core\Log\Logger $logger */
+                       $logger = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\CMS\Core\Log\LogManager')->getLogger();
+                       $logger->warning('The file "' . $fileUidOrCurrentKeyword . '" could not be found and won\'t be included in frontend output');
                        $fileObject = NULL;
                }
+
                if ($fileObject instanceof \TYPO3\CMS\Core\Resource\FileInterface) {
                        // All properties of the \TYPO3\CMS\Core\Resource\FileInterface are available here:
                        switch ($requestedFileInformationKey) {
index dfa84a5..c37e6c5 100644 (file)
@@ -57,7 +57,13 @@ class FilesContentObject extends \TYPO3\CMS\Frontend\ContentObject\AbstractConte
                        $referencesUid = $this->stdWrapValue('references', $conf);
                        $referencesUidArray = \TYPO3\CMS\Core\Utility\GeneralUtility::intExplode(',', $referencesUid, TRUE);
                        foreach ($referencesUidArray as $referenceUid) {
-                               $this->addToArray($fileRepository->findFileReferenceByUid($referenceUid), $fileObjects);
+                               try {
+                                       $this->addToArray($fileRepository->findFileReferenceByUid($referenceUid), $fileObjects);
+                               } catch (\TYPO3\CMS\Core\Resource\Exception $e) {
+                                       /** @var \TYPO3\CMS\Core\Log\Logger $logger */
+                                       $logger = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\CMS\Core\Log\LogManager')->getLogger();
+                                       $logger->warning('The file-reference with uid  "' . $referenceUid . '" could not be found and won\'t be included in frontend output');
+                               }
                        }
 
                        // It's important that this always stays "fieldName" and not be renamed to "field" as it would otherwise collide with the stdWrap key of that name
@@ -77,7 +83,13 @@ class FilesContentObject extends \TYPO3\CMS\Frontend\ContentObject\AbstractConte
                         */
                        $fileUids = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $this->stdWrapValue('files', $conf), TRUE);
                        foreach ($fileUids as $fileUid) {
-                               $this->addToArray($fileRepository->findByUid($fileUid), $fileObjects);
+                               try {
+                                       $this->addToArray($fileRepository->findByUid($fileUid), $fileObjects);
+                               } catch (\TYPO3\CMS\Core\Resource\Exception $e) {
+                                       /** @var \TYPO3\CMS\Core\Log\Logger $logger */
+                                       $logger = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\CMS\Core\Log\LogManager')->getLogger();
+                                       $logger->warning('The file with uid  "' . $fileUid . '" could not be found and won\'t be included in frontend output');
+                               }
                        }
                }
                if ($conf['collections'] || $conf['collections.']) {
@@ -85,10 +97,16 @@ class FilesContentObject extends \TYPO3\CMS\Frontend\ContentObject\AbstractConte
                        /** @var \TYPO3\CMS\Core\Resource\FileCollectionRepository $collectionRepository */
                        $collectionRepository = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Resource\\FileCollectionRepository');
                        foreach ($collectionUids as $collectionUid) {
-                               $fileCollection = $collectionRepository->findByUid($collectionUid);
-                               if ($fileCollection instanceof \TYPO3\CMS\Core\Resource\Collection\AbstractFileCollection) {
-                                       $fileCollection->loadContents();
-                                       $this->addToArray($fileCollection->getItems(), $fileObjects);
+                               try {
+                                       $fileCollection = $collectionRepository->findByUid($collectionUid);
+                                       if ($fileCollection instanceof \TYPO3\CMS\Core\Resource\Collection\AbstractFileCollection) {
+                                               $fileCollection->loadContents();
+                                               $this->addToArray($fileCollection->getItems(), $fileObjects);
+                                       }
+                               } catch (\TYPO3\CMS\Core\Resource\Exception $e) {
+                                       /** @var \TYPO3\CMS\Core\Log\Logger $logger */
+                                       $logger = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\CMS\Core\Log\LogManager')->getLogger();
+                                       $logger->warning('The file-collection with uid  "' . $collectionUid . '" could not be found or contents could not be loaded and won\'t be included in frontend output');
                                }
                        }
                }
@@ -98,9 +116,15 @@ class FilesContentObject extends \TYPO3\CMS\Frontend\ContentObject\AbstractConte
                        $fileFactory = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Resource\\ResourceFactory');
                        foreach ($folderIdentifiers as $folderIdentifier) {
                                if ($folderIdentifier) {
-                                       $folder = $fileFactory->getFolderObjectFromCombinedIdentifier($folderIdentifier);
-                                       if ($folder instanceof \TYPO3\CMS\Core\Resource\Folder) {
-                                               $this->addToArray($folder->getFiles(), $fileObjects);
+                                       try {
+                                               $folder = $fileFactory->getFolderObjectFromCombinedIdentifier($folderIdentifier);
+                                               if ($folder instanceof \TYPO3\CMS\Core\Resource\Folder) {
+                                                       $this->addToArray($folder->getFiles(), $fileObjects);
+                                               }
+                                       } catch (\TYPO3\CMS\Core\Resource\Exception $e) {
+                                               /** @var \TYPO3\CMS\Core\Log\Logger $logger */
+                                               $logger = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\CMS\Core\Log\LogManager')->getLogger();
+                                               $logger->warning('The folder with identifier  "' . $folderIdentifier . '" could not be found and won\'t be included in frontend output');
                                        }
                                }
                        }