From 6fbbdc00f73ca0e3a535bea27437f95cc2af1639 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Stefan=20B=C3=BCrk?= <stefan@buerk.tech>
Date: Thu, 21 Sep 2023 14:56:42 +0200
Subject: [PATCH] [BUGFIX] Guard local storage with missing base folder in
 filelist
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Storages using the local storage driver with a non existing
base folder are put offline automatically. However, the file
list module displays a to generic error message not pointing
to that fact.

This change adds a concrete check for this case and displays
a more specific error flash message in the file list module now.

This can be tested by creating a additional local storage with
a non-existing relative path, for example:

    `fileadmin/not-existing-folder/`

Resolves: #85323
Releases: main, 12.4, 11.5
Change-Id: Ie3ad64a99c0871d258470ffc858639dee4de1108
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/81265
Reviewed-by: Stefan Bürk <stefan@buerk.tech>
Tested-by: core-ci <typo3@b13.com>
Tested-by: Stefan Bürk <stefan@buerk.tech>
---
 .../Classes/Controller/FileListController.php | 22 ++++++++++++++-----
 .../Language/locallang_mod_file_list.xlf      |  6 +++++
 2 files changed, 23 insertions(+), 5 deletions(-)

diff --git a/typo3/sysext/filelist/Classes/Controller/FileListController.php b/typo3/sysext/filelist/Classes/Controller/FileListController.php
index 3671b289c71c..44d32e7ff6a2 100644
--- a/typo3/sysext/filelist/Classes/Controller/FileListController.php
+++ b/typo3/sysext/filelist/Classes/Controller/FileListController.php
@@ -114,6 +114,7 @@ class FileListController implements LoggerAwareInterface
             $parsedBody['overwriteExistingFiles'] ?? $queryParams['overwriteExistingFiles'] ?? null
         );
 
+        $storage = null;
         try {
             if ($this->id !== '') {
                 $backendUser->evaluateUserSpecificFileFilterSettings();
@@ -152,11 +153,22 @@ class FileListController implements LoggerAwareInterface
             }
         } catch (InsufficientFolderAccessPermissionsException $permissionException) {
             $this->folderObject = null;
-            $this->addFlashMessage(
-                sprintf($lang->sL('LLL:EXT:filelist/Resources/Private/Language/locallang_mod_file_list.xlf:missingFolderPermissionsMessage'), $this->id),
-                $lang->sL('LLL:EXT:filelist/Resources/Private/Language/locallang_mod_file_list.xlf:missingFolderPermissionsTitle'),
-                FlashMessage::ERROR
-            );
+            if ($storage !== null && $storage->getDriverType() === 'Local' && !$storage->isOnline()) {
+                // If the base folder for a local storage does not exists, the storage is marked as offline and the
+                // access permission exception is thrown. In this case we however want to display another error message.
+                // @see https://forge.typo3.org/issues/85323
+                $this->addFlashMessage(
+                    sprintf($lang->sL('LLL:EXT:filelist/Resources/Private/Language/locallang_mod_file_list.xlf:localStorageOfflineMessage'), $storage->getName()),
+                    $lang->sL('LLL:EXT:filelist/Resources/Private/Language/locallang_mod_file_list.xlf:localStorageOfflineTitle'),
+                    FlashMessage::ERROR
+                );
+            } else {
+                $this->addFlashMessage(
+                    sprintf($lang->sL('LLL:EXT:filelist/Resources/Private/Language/locallang_mod_file_list.xlf:missingFolderPermissionsMessage'), $this->id),
+                    $lang->sL('LLL:EXT:filelist/Resources/Private/Language/locallang_mod_file_list.xlf:missingFolderPermissionsTitle'),
+                    FlashMessage::ERROR
+                );
+            }
         } catch (Exception $fileException) {
             $this->folderObject = null;
             // Take the first object of the first storage
diff --git a/typo3/sysext/filelist/Resources/Private/Language/locallang_mod_file_list.xlf b/typo3/sysext/filelist/Resources/Private/Language/locallang_mod_file_list.xlf
index 2765ab2b8ec9..96555afa9452 100644
--- a/typo3/sysext/filelist/Resources/Private/Language/locallang_mod_file_list.xlf
+++ b/typo3/sysext/filelist/Resources/Private/Language/locallang_mod_file_list.xlf
@@ -75,6 +75,12 @@
 			<trans-unit id="missingFolderPermissionsMessage" resname="missingFolderPermissionsMessage">
 				<source>You have no access to the folder "%s".</source>
 			</trans-unit>
+			<trans-unit id="localStorageOfflineTitle" resname="localStorageOfflineTitle">
+				<source>Base folder for local storage missing</source>
+			</trans-unit>
+			<trans-unit id="localStorageOfflineMessage" resname="localStorageOfflineMessage">
+				<source>Base folder for local storage does not exists. Verify that the base folder for "%s" exists.</source>
+			</trans-unit>
 			<trans-unit id="folderNotFoundTitle" resname="folderNotFoundTitle">
 				<source>Folder not found.</source>
 			</trans-unit>
-- 
GitLab