Revert "[BUGFIX] Do not turn storages automatically offline" 92/50192/5
authorHelmut Hummel <typo3@helhum.io>
Wed, 12 Oct 2016 10:36:50 +0000 (12:36 +0200)
committerBenni Mack <benni@typo3.org>
Mon, 17 Oct 2016 12:21:16 +0000 (14:21 +0200)
This reverts commit 157e1f269902c9b3ab57c95f71534949606fc658.

This change introduced bugs with storages that were explicitly marked offline.
Besides that, it removed pubic API without deprecation
and lacked (clearly documented) concept on the behavior in the error case.

Reverts: #75184
Resolves: #78256
Releases: master
Change-Id: I6d51d9cb64e241bc8e7e354bc271ed89649f0e13
Reviewed-on: https://review.typo3.org/50192
Reviewed-by: Benni Mack <benni@typo3.org>
Tested-by: Benni Mack <benni@typo3.org>
typo3/sysext/core/Classes/Resource/ResourceStorage.php

index c2fddce..e5a680e 100644 (file)
@@ -15,7 +15,7 @@ namespace TYPO3\CMS\Core\Resource;
  */
 
 use TYPO3\CMS\Core\Database\ConnectionPool;
-use TYPO3\CMS\Core\Log\LogManager;
+use TYPO3\CMS\Core\Registry;
 use TYPO3\CMS\Core\Resource\Exception\InvalidTargetFolderException;
 use TYPO3\CMS\Core\Resource\Index\FileIndexRepository;
 use TYPO3\CMS\Core\Resource\Index\Indexer;
@@ -140,7 +140,7 @@ class ResourceStorage implements ResourceStorageInterface
      *
      * @var bool
      */
-    protected $isOnline = false;
+    protected $isOnline = null;
 
     /**
      * @var bool
@@ -160,11 +160,6 @@ class ResourceStorage implements ResourceStorageInterface
     const PROCESSING_FOLDER_LEVELS = 2;
 
     /**
-     * @var \TYPO3\CMS\Core\Log\Logger
-     */
-    protected $logger;
-
-    /**
      * Constructor for a storage object.
      *
      * @param Driver\DriverInterface $driver
@@ -172,9 +167,6 @@ class ResourceStorage implements ResourceStorageInterface
      */
     public function __construct(Driver\DriverInterface $driver, array $storageRecord)
     {
-        $logManager = GeneralUtility::makeInstance(LogManager::class);
-        $this->logger = $logManager->getLogger(__CLASS__);
-
         $this->storageRecord = $storageRecord;
         $this->configuration = ResourceFactory::getInstance()->convertFlexFormDataToConfigurationArray($storageRecord['configuration']);
         $this->capabilities =
@@ -182,13 +174,6 @@ class ResourceStorage implements ResourceStorageInterface
             ($this->storageRecord['is_public'] ? self::CAPABILITY_PUBLIC : 0) |
             ($this->storageRecord['is_writable'] ? self::CAPABILITY_WRITABLE : 0);
 
-        if ($this->getUid() === 0) {
-            // Legacy storage is always online
-            $this->isOnline = true;
-        } else {
-            $this->isOnline = (bool)$this->storageRecord['is_online'];
-        }
-
         $this->driver = $driver;
         $this->driver->setStorageUid($storageRecord['uid']);
         $this->driver->mergeConfigurationCapabilities($this->capabilities);
@@ -196,16 +181,8 @@ class ResourceStorage implements ResourceStorageInterface
             $this->driver->processConfiguration();
         } catch (Exception\InvalidConfigurationException $e) {
             // configuration error
-            // mark this storage as offline
-            $this->isOnline = false;
-
-            if (TYPO3_REQUESTTYPE === TYPO3_REQUESTTYPE_BE) {
-                $this->logger->error(
-                    'The storage "%s" has been turned offline due to a configuration error.',
-                    [$this->storageRecord['name']]
-                );
-                $this->markAsPermanentlyOffline();
-            }
+            // mark this storage as permanently unusable
+            $this->markAsPermanentlyOffline();
         }
         $this->driver->initialize();
         $this->capabilities = $this->driver->getCapabilities();
@@ -372,8 +349,29 @@ class ResourceStorage implements ResourceStorageInterface
      */
     public function isOnline()
     {
-        if (TYPO3_REQUESTTYPE !== TYPO3_REQUESTTYPE_BE) {
-            return true;
+        if ($this->isOnline === null) {
+            if ($this->getUid() === 0) {
+                $this->isOnline = true;
+            }
+            // the storage is not marked as online for a longer time
+            if ($this->storageRecord['is_online'] == 0) {
+                $this->isOnline = false;
+            }
+            if ($this->isOnline !== false) {
+                // all files are ALWAYS available in the frontend
+                if (TYPO3_MODE === 'FE') {
+                    $this->isOnline = true;
+                } else {
+                    // check if the storage is disabled temporary for now
+                    $registryObject = GeneralUtility::makeInstance(Registry::class);
+                    $offlineUntil = $registryObject->get('core', 'sys_file_storage-' . $this->getUid() . '-offline-until');
+                    if ($offlineUntil && $offlineUntil > time()) {
+                        $this->isOnline = false;
+                    } else {
+                        $this->isOnline = true;
+                    }
+                }
+            }
         }
         return $this->isOnline;
     }
@@ -413,6 +411,22 @@ class ResourceStorage implements ResourceStorageInterface
         $this->isOnline = false;
     }
 
+    /**
+     * Marks this storage as offline for the next 5 minutes.
+     *
+     * Non-permanent: This typically happens for remote storages
+     * that are "flaky" and not available all the time.
+     *
+     * @return void
+     */
+    public function markAsTemporaryOffline()
+    {
+        $registryObject = GeneralUtility::makeInstance(Registry::class);
+        $registryObject->set('core', 'sys_file_storage-' . $this->getUid() . '-offline-until', time() + 60 * 5);
+        $this->storageRecord['is_online'] = 0;
+        $this->isOnline = false;
+    }
+
     /*********************************
      * User Permissions / File Mounts
      ********************************/