[BUGFIX] RTE Linking with file upload fails 47/28247/4
authorTymoteusz Motylewski <t.motylewski@gmail.com>
Tue, 11 Mar 2014 10:10:21 +0000 (11:10 +0100)
committerFrans Saris <franssaris@gmail.com>
Wed, 19 Mar 2014 07:29:33 +0000 (08:29 +0100)
Catch exceptions raised when the potential target folder or
the default user upload folder does not exist.

The change  https://review.typo3.org/27323 from ticket
http://forge.typo3.org/issues/48512 should be applied
in few places more.

Resolves: #56751
Related: #48512
Releases: 6.2
Change-Id: I7446697d64a580203f8f772d4bba690542dd7cb2
Reviewed-on: https://review.typo3.org/28247
Reviewed-by: Markus Klein
Tested-by: Markus Klein
Reviewed-by: Frans Saris
Tested-by: Frans Saris
typo3/sysext/recordlist/Classes/Browser/ElementBrowser.php
typo3/sysext/rtehtmlarea/Classes/SelectImage.php

index cdfee0f..35250b2 100644 (file)
@@ -996,22 +996,24 @@ class ElementBrowser {
                                        try {
                                                $fileOrFolderObject = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance()->retrieveFileOrFolderObject($this->expandFolder);
                                        } catch (\Exception $e) {
+                                               // No path is selected
                                        }
 
                                        if ($fileOrFolderObject instanceof Folder) {
                                                // It's a folder
                                                $selectedFolder = $fileOrFolderObject;
                                        } elseif ($fileOrFolderObject instanceof \TYPO3\CMS\Core\Resource\FileInterface) {
-                                               // It's a file
-                                               // @todo: find the parent folder, right now done a bit ugly, because the file does not
-                                               // support finding the parent folder of a file on purpose
-                                               $folderIdentifier = dirname($fileOrFolderObject->getIdentifier());
-                                               $selectedFolder = $fileOrFolderObject->getStorage()->getFolder($folderIdentifier);
+                                               // it's a file
+                                               $selectedFolder = $fileOrFolderObject->getParentFolder();
                                        }
                                }
                                // Or get the user's default upload folder
                                if (!$selectedFolder) {
-                                       $selectedFolder = $GLOBALS['BE_USER']->getDefaultUploadFolder();
+                                       try {
+                                               $selectedFolder = $GLOBALS['BE_USER']->getDefaultUploadFolder();
+                                       } catch (\Exception $e) {
+                                               // The configured default user folder does not exist
+                                       }
                                }
                                // Build the file upload and folder creation form
                                $uploadForm = '';
@@ -1398,8 +1400,8 @@ class ElementBrowser {
                        }
                }
                // Create upload/create folder forms, if a path is given
+               $this->selectedFolder = FALSE;
                if ($this->expandFolder) {
-                       $this->selectedFolder = FALSE;
                        $fileOrFolderObject = NULL;
 
                        // Try to fetch the folder the user had open the last time he browsed files
@@ -1415,15 +1417,16 @@ class ElementBrowser {
                                $this->selectedFolder = $fileOrFolderObject;
                        } elseif ($fileOrFolderObject instanceof \TYPO3\CMS\Core\Resource\FileInterface) {
                                // It's a file
-                               // @todo: find the parent folder, right now done a bit ugly, because the file does not
-                               // support finding the parent folder of a file on purpose
-                               $folderIdentifier = dirname($fileOrFolderObject->getIdentifier());
-                               $this->selectedFolder = $fileOrFolderObject->getStorage()->getFolder($folderIdentifier);
+                               $this->selectedFolder = $fileOrFolderObject->getParentFolder();
                        }
                }
                // Or get the user's default upload folder
                if (!$this->selectedFolder) {
-                       $this->selectedFolder = $GLOBALS['BE_USER']->getDefaultUploadFolder();
+                       try {
+                               $this->selectedFolder = $GLOBALS['BE_USER']->getDefaultUploadFolder();
+                       } catch (\Exception $e) {
+                               // The configured default user folder does not exist
+                       }
                }
                        // Build the file upload and folder creation form
                $uploadForm = '';
index af9622e..5e098c9 100644 (file)
@@ -722,21 +722,27 @@ class SelectImage extends \TYPO3\CMS\Recordlist\Browser\ElementBrowser {
                                // Get the selected folder
                                $selectedFolder = FALSE;
                                if ($this->expandFolder) {
-                                       $fileOrFolderObject = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance()->retrieveFileOrFolderObject($this->expandFolder);
+                                       $fileOrFolderObject = NULL;
+                                       try {
+                                               $fileOrFolderObject = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance()->retrieveFileOrFolderObject($this->expandFolder);
+                                       } catch (\Exception $e) {
+                                               // No path is selected
+                                       }
                                        if ($fileOrFolderObject instanceof \TYPO3\CMS\Core\Resource\Folder) {
                                                // it's a folder
                                                $selectedFolder = $fileOrFolderObject;
                                        } elseif ($fileOrFolderObject instanceof \TYPO3\CMS\Core\Resource\FileInterface) {
                                                // it's a file
-                                               // @todo: find the parent folder, right now done a bit ugly, because the file does not
-                                               // support finding the parent folder of a file on purpose
-                                               $folderIdentifier = dirname($fileOrFolderObject->getIdentifier());
-                                               $selectedFolder = $fileOrFolderObject->getStorage()->getFolder($folderIdentifier);
+                                               $selectedFolder = $fileOrFolderObject->getParentFolder();
                                        }
                                }
                                // If no folder is selected, get the user's default upload folder
                                if (!$selectedFolder) {
-                                       $selectedFolder = $GLOBALS['BE_USER']->getDefaultUploadFolder();
+                                       try {
+                                               $selectedFolder = $GLOBALS['BE_USER']->getDefaultUploadFolder();
+                                       } catch (\Exception $e) {
+                                               // The configured default user folder does not exist
+                                       }
                                }
                                // Build the file upload and folder creation form
                                $uploadForm = '';