]> git.mxchange.org Git - friendica.git/commitdiff
Fix loading SystemResource files
authornupplaPhil <admin@philipp.info>
Fri, 17 Jan 2020 18:31:34 +0000 (19:31 +0100)
committernupplaPhil <admin@philipp.info>
Fri, 17 Jan 2020 18:31:34 +0000 (19:31 +0100)
src/Core/StorageManager.php
tests/src/Core/StorageManagerTest.php

index 6a8fac5b808f9968ab0c10f41884bdd4f6533b41..7dd4c67371cf96514afab162cc0871f403e421c2 100644 (file)
@@ -62,7 +62,8 @@ class StorageManager
 
                $currentName = $this->config->get('storage', 'name', '');
 
-               $this->currentBackend = $this->getByName($currentName);
+               // you can only use user backends as a "default" backend, so the second parameter is true
+               $this->currentBackend = $this->getByName($currentName, true);
        }
 
        /**
@@ -79,13 +80,13 @@ class StorageManager
         * @brief Return storage backend class by registered name
         *
         * @param string|null $name        Backend name
-        * @param boolean     $userBackend Just return instances in case it's a user backend (e.g. not SystemResource)
+        * @param boolean     $userBackend True, if just user specific instances should be returrned (e.g. not SystemResource)
         *
         * @return Storage\IStorage|null null if no backend registered at $name
         *
         * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         */
-       public function getByName(string $name = null, $userBackend = true)
+       public function getByName(string $name = null, $userBackend = false)
        {
                // If there's no cached instance create a new instance
                if (!isset($this->backendInstances[$name])) {
@@ -133,7 +134,7 @@ class StorageManager
         *
         * @return boolean True, if the backend is a valid backend
         */
-       public function isValidBackend(string $name = null, bool $userBackend = true)
+       public function isValidBackend(string $name = null, bool $userBackend = false)
        {
                return array_key_exists($name, $this->backends) ||
                       (!$userBackend && $name === Storage\SystemResource::getName());
@@ -148,12 +149,12 @@ class StorageManager
         */
        public function setBackend(string $name = null)
        {
-               if (!$this->isValidBackend($name)) {
+               if (!$this->isValidBackend($name, false)) {
                        return false;
                }
 
                if ($this->config->set('storage', 'name', $name)) {
-                       $this->currentBackend = $this->getByName($name);
+                       $this->currentBackend = $this->getByName($name, false);
                        return true;
                } else {
                        return false;
index 443f8e786b83248f185533c2e3d20359f7360d6b..7cef2dc281e053aa3694f3402b2e766e32c10c55 100644 (file)
@@ -139,7 +139,11 @@ class StorageManagerTest extends DatabaseTest
        {
                $storageManager = new StorageManager($this->dba, $this->config, $this->logger, $this->l10n);
 
-               $this->assertEquals($userBackend, $storageManager->isValidBackend($name));
+               // true in every of the backends
+               $this->assertEquals(!empty($assertName), $storageManager->isValidBackend($name));
+
+               // if userBackend is set to true, filter out e.g. SystemRessource
+               $this->assertEquals($userBackend, $storageManager->isValidBackend($name, true));
        }
 
        /**