From 7e2e2f425e7077cf62e214997c8a3fe3c1cb0106 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sun, 17 Mar 2019 19:12:20 -0400 Subject: [PATCH] Check that provided class implements IStorage in StorageManager::setBackend - Add notice in admin if setting value change failed - Add notice in console if setting value change failed --- mod/admin.php | 4 +++- src/Core/Console/Storage.php | 6 +++++- src/Core/StorageManager.php | 8 +++++++- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/mod/admin.php b/mod/admin.php index 39c2e9341b..f8a75b7a2d 100644 --- a/mod/admin.php +++ b/mod/admin.php @@ -1200,7 +1200,9 @@ function admin_page_site_post(App $a) * @var $storagebackend \Friendica\Model\Storage\IStorage */ $storagebackend = Strings::escapeTags(trim(defaults($_POST, 'storagebackend', ''))); - StorageManager::setBackend($storagebackend); + if (!StorageManager::setBackend($storagebackend)) { + info(L10n::t('Invalid storage backend setting value.')); + } // save storage backend form if (!is_null($storagebackend) && $storagebackend != "") { diff --git a/src/Core/Console/Storage.php b/src/Core/Console/Storage.php index a7a0ffd38b..8b02d874c5 100644 --- a/src/Core/Console/Storage.php +++ b/src/Core/Console/Storage.php @@ -106,7 +106,11 @@ HELP; return -1; } - StorageManager::setBackend($class); + if (!StorageManager::setBackend($class)) { + $this->out($class . ' is not a valid backend storage class.'); + return -1; + } + return 0; } diff --git a/src/Core/StorageManager.php b/src/Core/StorageManager.php index 335c28f051..3bb1cc4511 100644 --- a/src/Core/StorageManager.php +++ b/src/Core/StorageManager.php @@ -54,12 +54,18 @@ class StorageManager * @brief Set current storage backend class * * @param string $class Backend class name + * @return bool * @throws \Friendica\Network\HTTPException\InternalServerErrorException */ public static function setBackend($class) { - /// @todo Check that $class implements IStorage + if (!in_array('Friendica\Model\Storage\IStorage', class_implements($class))) { + return false; + } + Config::set('storage', 'class', $class); + + return true; } /** -- 2.39.5