#111658Element browser and link browser throw "No storage found with uid" when the last opened folder belongs to a deleted file storage
Description
Problem
After a file storage has been deleted, “Add file” on a file field (element browser) fails with an uncaught exception if the folder last opened in the element browser was inside that storage. Seen on TYPO3 14.3.11 with PHP 8.5.5.
(1/1) #1599235454 InvalidArgumentException No storage found with uid "2". at TYPO3\CMS\Core\Resource\StorageRepository->fetchRecordDataByUid() at TYPO3\CMS\Core\Resource\StorageRepository->getStorageObject() at TYPO3\CMS\Core\Resource\ResourceFactory->getFolderObjectFromCombinedIdentifier() at TYPO3\CMS\Filelist\ElementBrowser\AbstractResourceBrowser->initSelectedFolder() at TYPO3\CMS\Filelist\ElementBrowser\FileBrowser->render() at TYPO3\CMS\Backend\Controller\ElementBrowserController
Expected: the element browser ignores the outdated folder and opens without a preselected folder, as it already does when the remembered folder has been removed.
Actual: the element browser cannot be opened for the rest of the backend session. The editor cannot add any file, also none from other storages.
Workaround: log out and log in again (the remembered folder is only restored within the same session), or remove uc[moduleData][browse_links.php][expandFolder] of the backend user.
Steps to reproduce
- Create a second file storage (driver Local) pointing to an existing folder; it gets e.g. uid 2.
- Edit a content element with a file field, open “Add file” and select a folder of the new storage in the element browser. Close the element browser.
- Delete the file storage record.
- Without logging out, click “Add file” again.
Cause
AbstractResourceBrowser::initSelectedFolder() (EXT:filelist) restores expandFolder (here 2:/) from the module session data and resolves it with ResourceFactory::getFolderObjectFromCombinedIdentifier(). It is meant to ignore outdated session data, but only catches FolderDoesNotExistException and InsufficientFolderAccessPermissionsException:
try {
$this->selectedFolder = $resourceFactory->getFolderObjectFromCombinedIdentifier($this->expandFolder);
} catch (FolderDoesNotExistException|InsufficientFolderAccessPermissionsException) {
// Outdated module session data
}
For a storage that no longer exists, StorageRepository::fetchRecordDataByUid() throws a plain \InvalidArgumentException (1599235454), which is not caught. The deleted storage record is not part of the storage cache.
ElementBrowserController writes the value back to the module data before rendering, so every further attempt in the same session fails again.
AbstractResourceLinkHandler (EXT:filelist) has the same catch list around the same call for the remembered folder. From reading the code, the file and folder tabs of the link browser are affected too (not reproduced).
Suggested fix
--- a/typo3/sysext/filelist/Classes/ElementBrowser/AbstractResourceBrowser.php
+++ b/typo3/sysext/filelist/Classes/ElementBrowser/AbstractResourceBrowser.php
@@ protected function initSelectedFolder(): void
try {
$this->selectedFolder = $resourceFactory->getFolderObjectFromCombinedIdentifier($this->expandFolder);
- } catch (FolderDoesNotExistException|InsufficientFolderAccessPermissionsException) {
+ } catch (FolderDoesNotExistException|InsufficientFolderAccessPermissionsException|\InvalidArgumentException) {
// Outdated module session data: Last used folder has been removed meanwhile, or
- // access to last used folder has been removed. Do not set a preselected folder.
+ // access to last used folder or its storage has been removed. Do not set a preselected folder.
}
--- a/typo3/sysext/filelist/Classes/LinkHandler/AbstractResourceLinkHandler.php
+++ b/typo3/sysext/filelist/Classes/LinkHandler/AbstractResourceLinkHandler.php
@@
- } catch (FolderDoesNotExistException|InsufficientFolderAccessPermissionsException) {
+ } catch (FolderDoesNotExistException|InsufficientFolderAccessPermissionsException|\InvalidArgumentException) {
// Outdated module session data: Last used folder has been removed meanwhile, or
- // access to last used folder has been removed. Do not set a preselected folder.
+ // access to last used folder or its storage has been removed. Do not set a preselected folder.
}Reviews 0
No change resolves or names this issue in its commit message, and no comment links one.
Fix this issue
Start the commit message of your patch with this. Add what the patch does, and the versions it goes to in "Releases:". How to create a patch
- Commit message
-
[BUGFIX] Element browser and link browser throw "No storage found with uid" when the last opened folder belongs to a deleted file storage Resolves: #111658 Releases: main