[BUGFIX] Proper error handling of ResourceDoesNotExistException 20/36420/2
authorruud <ruudsilvrants@gmail.com>
Thu, 29 Jan 2015 17:44:19 +0000 (18:44 +0100)
committerFrans Saris <franssaris@gmail.com>
Fri, 30 Jan 2015 17:08:08 +0000 (18:08 +0100)
Handles and displaying a proper error message when
ResourceDoesNotExistException is thrown.

Resolves: #56997
Releases: master, 6.2
Change-Id: I193f9eac929f856d2d195307110d2c18122c8bb9
Reviewed-on: http://review.typo3.org/36420
Reviewed-by: Fabien Udriot <fabien.udriot@ecodev.ch>
Tested-by: Fabien Udriot <fabien.udriot@ecodev.ch>
Reviewed-by: Frans Saris <franssaris@gmail.com>
Tested-by: Frans Saris <franssaris@gmail.com>
typo3/sysext/core/Classes/Utility/File/ExtendedFileUtility.php
typo3/sysext/lang/locallang_core.xlf

index fe61c50..76df9e9 100644 (file)
@@ -17,6 +17,8 @@ namespace TYPO3\CMS\Core\Utility\File;
 use TYPO3\CMS\Backend\Utility\BackendUtility;
 use TYPO3\CMS\Backend\Utility\IconUtility;
 use TYPO3\CMS\Core\Messaging\FlashMessage;
+use TYPO3\CMS\Core\Messaging\FlashMessageService;
+use TYPO3\CMS\Core\Resource\Exception\ResourceDoesNotExistException;
 use TYPO3\CMS\Core\Resource\File;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 
@@ -390,7 +392,20 @@ class ExtendedFileUtility extends \TYPO3\CMS\Core\Utility\File\BasicFileUtility
                }
                // Example indentifier for $cmds['data'] => "4:mypath/tomyfolder/myfile.jpg"
                // for backwards compatibility: the combined file identifier was the path+filename
-               $fileObject = $this->getFileObject($cmds['data']);
+               try {
+                       $fileObject = $this->getFileObject($cmds['data']);
+               } catch (ResourceDoesNotExistException $ex) {
+                       $flashMessage = GeneralUtility::makeInstance(
+                               'TYPO3\\CMS\\Core\\Messaging\\FlashMessage',
+                               sprintf( $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:message.description.fileNotFound'), $cmds['data']),
+                               $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:message.header.fileNotFound'),
+                               FlashMessage::ERROR,
+                               TRUE
+                       );
+                       $this->addFlashMessage($flashMessage);
+
+                       return FALSE;
+               }
                // @todo implement the recycler feature which has been removed from the original implementation
                // checks to delete the file
                if ($fileObject instanceof File) {
index ac3ceaf..ea7d2fb 100644 (file)
@@ -735,6 +735,12 @@ Would you like to save now in order to refresh the display?</source>
                        <trans-unit id="message.description.fileHasBrokenReferences" xml:space="preserve">
                                <source>The file has %s broken reference(s) but it will be deleted regardless.</source>
                        </trans-unit>
+                       <trans-unit id="message.header.fileNotFound" xml:space="preserve">
+                               <source>File not found</source>
+                       </trans-unit>
+                       <trans-unit id="message.description.fileNotFound" xml:space="preserve">
+                               <source>The file %s is not found, possible already removed.</source>
+                       </trans-unit>
                        <trans-unit id="message.header.fileDeleted" xml:space="preserve">
                                <source>File deleted</source>
                        </trans-unit>