From 9bb58916458a3e90533ed757318f0212daa1d0cb Mon Sep 17 00:00:00 2001 From: nupplaPhil Date: Fri, 17 Jan 2020 19:31:34 +0100 Subject: [PATCH] Fix loading SystemResource files --- src/Core/StorageManager.php | 13 +++++++------ tests/src/Core/StorageManagerTest.php | 6 +++++- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/Core/StorageManager.php b/src/Core/StorageManager.php index 6a8fac5b80..7dd4c67371 100644 --- a/src/Core/StorageManager.php +++ b/src/Core/StorageManager.php @@ -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; diff --git a/tests/src/Core/StorageManagerTest.php b/tests/src/Core/StorageManagerTest.php index 443f8e786b..7cef2dc281 100644 --- a/tests/src/Core/StorageManagerTest.php +++ b/tests/src/Core/StorageManagerTest.php @@ -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)); } /**