[BUGFIX] Catch FolderDoesNotExist Exception on links/images 70/20570/6
authorAlexander Opitz <opitz.alexander@googlemail.com>
Tue, 7 May 2013 08:25:06 +0000 (10:25 +0200)
committerPhilipp Gampe <philipp.gampe@typo3.org>
Sat, 25 May 2013 15:28:34 +0000 (17:28 +0200)
If you have RTE content which have false links/images to files, we
get a FolderDoesNotExistException (FileDoesNotExistException in 6.0).
This should be catched.

Reproduce
* Create content element text
* In RTE change to text mode
* Add <img src="nofile" /> for image
or
* Add <a href="nowhere">link</a> for link
* save

Resolves: #46785
Releases: 6.2, 6.1, 6.0
Change-Id: I7b959825e8e36dc5b1941c9fa411afa321a594fb
Reviewed-on: https://review.typo3.org/20570
Reviewed-by: Simon Schick
Tested-by: Simon Schick
Reviewed-by: Henrik Ziegenhain
Tested-by: Henrik Ziegenhain
Reviewed-by: Philipp Gampe
Tested-by: Philipp Gampe
typo3/sysext/core/Classes/Html/RteHtmlParser.php

index d2b11b4..1c4acdc 100644 (file)
@@ -573,12 +573,16 @@ class RteHtmlParser extends \TYPO3\CMS\Core\Html\HtmlParser {
                                                $attribArray['src'] = preg_replace('#^' . preg_quote($sitePath, '#') . '#', '', $attribArray['src']);
                                                // If the image is not magic and does not have a file uid, try to add the uid
                                                if (!$attribArray['data-htmlarea-file-uid'] && !$isMagicImage) {
-                                                       $fileOrFolderObject = $fileFactory->retrieveFileOrFolderObject($attribArray['src']);
-                                                       if ($fileOrFolderObject instanceof \TYPO3\CMS\Core\Resource\FileInterface) {
-                                                               $fileIdentifier = $fileOrFolderObject->getIdentifier();
-                                                               $fileObject = $fileOrFolderObject->getStorage()->getFile($fileIdentifier);
-                                                               $attribArray['data-htmlarea-file-uid'] = $fileObject->getUid();
-                                                               $attribArray['data-htmlarea-file-table'] = 'sys_file';
+                                                       try {
+                                                               $fileOrFolderObject = $fileFactory->retrieveFileOrFolderObject($attribArray['src']);
+                                                               if ($fileOrFolderObject instanceof \TYPO3\CMS\Core\Resource\FileInterface) {
+                                                                       $fileIdentifier = $fileOrFolderObject->getIdentifier();
+                                                                       $fileObject = $fileOrFolderObject->getStorage()->getFile($fileIdentifier);
+                                                                       $attribArray['data-htmlarea-file-uid'] = $fileObject->getUid();
+                                                                       $attribArray['data-htmlarea-file-table'] = 'sys_file';
+                                                               }
+                                                       } catch (\TYPO3\CMS\Core\Resource\Exception\FolderDoesNotExistException $notFoundException) {
+                                                               // Nothing to be done if file/folder not found
                                                        }
                                                }
                                                $attribArray['src'] = $siteUrl . $attribArray['src'];
@@ -774,7 +778,11 @@ class RteHtmlParser extends \TYPO3\CMS\Core\Html\HtmlParser {
                                                } elseif ($fileChar) {
                                                        // It is an internal file or folder
                                                        // Try to transform the href into a FAL reference
-                                                       $fileOrFolderObject = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance()->retrieveFileOrFolderObject($link_param);
+                                                       try {
+                                                               $fileOrFolderObject = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance()->retrieveFileOrFolderObject($link_param);
+                                                       } catch (\TYPO3\CMS\Core\Resource\Exception\FolderDoesNotExistException $notFoundException) {
+                                                               // Nothing to be done if file/folder not found
+                                                       }
                                                        if ($fileOrFolderObject instanceof \TYPO3\CMS\Core\Resource\Folder) {
                                                                // It's a folder
                                                                $folderIdentifier = $fileOrFolderObject->getIdentifier();