]> git.mxchange.org Git - friendica.git/commitdiff
Check that provided class implements IStorage in StorageManager::setBackend
authorHypolite Petovan <hypolite@mrpetovan.com>
Sun, 17 Mar 2019 23:12:20 +0000 (19:12 -0400)
committerHypolite Petovan <hypolite@mrpetovan.com>
Wed, 20 Mar 2019 02:42:44 +0000 (22:42 -0400)
- Add notice in admin if setting value change failed
- Add notice in console if setting value change failed

mod/admin.php
src/Core/Console/Storage.php
src/Core/StorageManager.php

index 39c2e9341b3483af8fc4aa5facc975320887d17e..f8a75b7a2d740ffbc5af5f7cf9391010790be327 100644 (file)
@@ -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 != "") {
index a7a0ffd38b34a7183b47c3b2f53d3e4e893238b3..8b02d874c56f02bd3cddbbccc1c8bcb2b7821bd0 100644 (file)
@@ -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;
        }
 
index 335c28f05126baf5e7801b70befda94425542849..3bb1cc4511161960dcbc47aec33634eba7c8895f 100644 (file)
@@ -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;
        }
 
        /**