From 6a3ee818f1590a8fee0d119d9ed15fb35a904cef Mon Sep 17 00:00:00 2001
From: Marc Willmann <mw@f7.de>
Date: Tue, 25 Oct 2016 17:18:18 +0200
Subject: [PATCH] [BUGFIX] Don't set resource storages permanently offline
 automatically

When the storage drive coudn't be initialized correctly the storage is
only put offline for the current request. The error thrown by the driver
is logged to database table sys_log as well.

Resolves: #75184
Releases: master, 7.6
Change-Id: I4b05b732f887c0679e9cdda77793e4b304ac3fdb
Reviewed-on: https://review.typo3.org/50371
Reviewed-by: Oliver Hader <oliver.hader@typo3.org>
Tested-by: Oliver Hader <oliver.hader@typo3.org>
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
---
 .../core/Classes/Resource/ResourceStorage.php | 36 +++++++++++++++++--
 .../Configuration/DefaultConfiguration.php    | 15 ++++++++
 2 files changed, 48 insertions(+), 3 deletions(-)

diff --git a/typo3/sysext/core/Classes/Resource/ResourceStorage.php b/typo3/sysext/core/Classes/Resource/ResourceStorage.php
index 9f027a3aaa80..7f33867c4feb 100644
--- a/typo3/sysext/core/Classes/Resource/ResourceStorage.php
+++ b/typo3/sysext/core/Classes/Resource/ResourceStorage.php
@@ -180,9 +180,17 @@ class ResourceStorage implements ResourceStorageInterface
         try {
             $this->driver->processConfiguration();
         } catch (Exception\InvalidConfigurationException $e) {
-            // configuration error
-            // mark this storage as permanently unusable
-            $this->markAsPermanentlyOffline();
+            // Configuration error
+            $this->isOnline = false;
+
+            $message = sprintf(
+                'Failed initializing storage [%d] "%s", error: %s',
+                $this->getUid(),
+                $this->getName(),
+                $e->getMessage()
+            );
+
+            $this->getLogger()->error($message);
         }
         $this->driver->initialize();
         $this->capabilities = $this->driver->getCapabilities();
@@ -3012,4 +3020,26 @@ class ResourceStorage implements ResourceStorageInterface
     {
         return $this->isDefault;
     }
+
+    /**
+     * Returns the current BE user.
+     *
+     * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
+     */
+    protected function getBackendUser()
+    {
+        return $GLOBALS['BE_USER'];
+    }
+
+    /**
+     * @return \TYPO3\CMS\Core\Log\Logger
+     */
+    protected function getLogger()
+    {
+        /** @var $logManager \TYPO3\CMS\Core\Log\LogManager */
+        $logManager = GeneralUtility::makeInstance(
+            \TYPO3\CMS\Core\Log\LogManager::class
+        );
+        return $logManager->getLogger(get_class($this));
+    }
 }
diff --git a/typo3/sysext/core/Configuration/DefaultConfiguration.php b/typo3/sysext/core/Configuration/DefaultConfiguration.php
index 7c78a927dfb7..cca1c0f232dc 100644
--- a/typo3/sysext/core/Configuration/DefaultConfiguration.php
+++ b/typo3/sysext/core/Configuration/DefaultConfiguration.php
@@ -1159,6 +1159,21 @@ return [
             \TYPO3\CMS\Core\Log\LogLevel::WARNING => [
                 \TYPO3\CMS\Core\Log\Writer\FileWriter::class => []
             ]
+        ],
+        'TYPO3' => [
+            'CMS' => [
+                'Core' => [
+                    'Resource' => [
+                        'ResourceStorage' => [
+                            'writerConfiguration' => [
+                                \TYPO3\CMS\Core\Log\LogLevel::ERROR => [
+                                    \TYPO3\CMS\Core\Log\Writer\DatabaseWriter::class => []
+                                ]
+                            ]
+                        ]
+                    ]
+                ]
+            ]
         ]
     ],
     'USER' => [],
-- 
GitLab