]> git.mxchange.org Git - friendica.git/commitdiff
Bugfixings in Config
authorPhilipp Holzer <admin@philipp.info>
Fri, 22 Feb 2019 22:51:13 +0000 (23:51 +0100)
committerPhilipp Holzer <admin@philipp.info>
Fri, 22 Feb 2019 22:51:13 +0000 (23:51 +0100)
- replaced usage of "!<unset>!" with null-returns
- fixed bool settings (0/1)
- fixed overriding config-values
- fixed basepath problems

24 files changed:
bin/daemon.php
src/App.php
src/Core/Config.php
src/Core/Config/Adapter/AbstractDbaConfigAdapter.php
src/Core/Config/Adapter/IConfigAdapter.php
src/Core/Config/Adapter/IPConfigAdapter.php
src/Core/Config/Adapter/JITConfigAdapter.php
src/Core/Config/Adapter/JITPConfigAdapter.php
src/Core/Config/Adapter/PreloadConfigAdapter.php
src/Core/Config/Adapter/PreloadPConfigAdapter.php
src/Core/Config/Cache/ConfigCache.php
src/Core/Config/Cache/ConfigCacheLoader.php
src/Core/Config/Cache/IConfigCache.php
src/Core/Config/Cache/IPConfigCache.php
src/Core/Config/Configuration.php
src/Core/Config/PConfiguration.php
src/Core/PConfig.php
src/Database/DBA.php
src/Factory/DBFactory.php
src/Factory/DependencyFactory.php
src/Model/Photo.php
tests/include/ApiTest.php
tests/src/Database/DBATest.php
tests/src/Database/DBStructureTest.php

index 047bf71be77b4ac31dbea889098e5dd52dce8b5b..298cfa2534ad1221ddbf1cf7561de89830b354e2 100755 (executable)
@@ -144,7 +144,9 @@ if (!$foreground) {
        file_put_contents($pidfile, $pid);
 
        // We lose the database connection upon forking
-       Factory\DBFactory::init($a->getConfigCache(), $a->getProfiler(), $_SERVER);
+       /// @todo refactoring during https://github.com/friendica/friendica/issues/6720
+       $basePath = \Friendica\Util\BasePath::create(dirname(__DIR__), $_SERVER);
+       Factory\DBFactory::init($basePath, $a->getConfigCache(), $a->getProfiler(), $_SERVER);
 }
 
 Config::set('system', 'worker_daemon_mode', true);
index 3df285cb385a59602ff8f0fb0952a9f736a3add4..e5ac5dda3cc926a87ef8d5d479842bd17780d6f3 100644 (file)
@@ -205,6 +205,7 @@ class App
        /**
         * @brief App constructor.
         *
+        * @param string           $basePath   The basedir of the app
         * @param Configuration    $config    The Configuration
         * @param LoggerInterface  $logger    The current app logger
         * @param Profiler         $profiler  The profiler of this application
@@ -212,14 +213,15 @@ class App
         *
         * @throws Exception if the Basepath is not usable
         */
-       public function __construct(Configuration $config, LoggerInterface $logger, Profiler $profiler, $isBackend = true)
+       public function __construct($basePath, Configuration $config, LoggerInterface $logger, Profiler $profiler, $isBackend = true)
        {
                BaseObject::setApp($this);
 
                $this->logger   = $logger;
                $this->config   = $config;
                $this->profiler = $profiler;
-               $this->basePath = $this->config->get('system', 'basepath');
+               $cfgBasePath = $this->config->get('system', 'basepath');
+               $this->basePath = (isset($cfgBasePath) && $cfgBasePath !== '') ? $cfgBasePath : $basePath;
 
                if (!Core\System::isDirectoryUsable($this->basePath, false)) {
                        throw new Exception('Basepath \'' . $this->basePath . '\' isn\'t usable.');
index 4bf9c5b11d2d4aa96495516edfc38dc94c098f25..f974e2fff295673cc9fb29cce0e27bee503e3dc9 100644 (file)
@@ -65,8 +65,6 @@ class Config
         *
         * Stores a config value ($value) in the category ($cat) under the key ($key)
         *
-        * Note: Please do not store booleans - convert to 0/1 integer values!
-        *
         * @param string $cat The category of the configuration value
         * @param string $key    The configuration key to set
         * @param mixed  $value  The value to store
index 770dfd2c957107814bcda19cfa99fd53c5734c99..38caf35cac1cfb6f537468f42c5b233a28fc8d07 100644 (file)
@@ -6,7 +6,11 @@ use Friendica\Database\DBA;
 
 abstract class AbstractDbaConfigAdapter
 {
-       /** @var bool */
+       /**
+        * The connection state of the adapter
+        *
+        * @var bool
+        */
        protected $connected = true;
 
        public function __construct()
@@ -14,8 +18,66 @@ abstract class AbstractDbaConfigAdapter
                $this->connected = DBA::connected();
        }
 
+       /**
+        * Checks if the adapter is currently connected
+        *
+        * @return bool
+        */
        public function isConnected()
        {
                return $this->connected;
        }
+
+       /**
+        * Formats a DB value to a config value
+        * - null   = The db-value isn't set
+        * - bool   = The db-value is either '0' or '1'
+        * - array  = The db-value is a serialized array
+        * - string = The db-value is a string
+        *
+        * Keep in mind that there aren't any numeric/integer config values in the database
+        *
+        * @param null|string $value
+        *
+        * @return null|array|string
+        */
+       protected function toConfigValue($value)
+       {
+               if (!isset($value)) {
+                       return null;
+               }
+
+               switch (true) {
+                       // manage array value
+                       case preg_match("|^a:[0-9]+:{.*}$|s", $value):
+                               return unserialize($value);
+
+                       default:
+                               return $value;
+               }
+       }
+
+       /**
+        * Formats a config value to a DB value (string)
+        *
+        * @param mixed $value
+        *
+        * @return string
+        */
+       protected function toDbValue($value)
+       {
+               // if not set, save an empty string
+               if (!isset($value)) {
+                       return '';
+               }
+
+               switch (true) {
+                       // manage arrays
+                       case is_array($value):
+                               return serialize($value);
+
+                       default:
+                               return (string)$value;
+               }
+       }
 }
index 21cd9a4b2ab8f184f870af8e55add727b81ee92a..892c476e7c30f3b1d003c0096594b35ffc5b30e7 100644 (file)
@@ -21,10 +21,12 @@ interface IConfigAdapter
         * Get a particular system-wide config variable given the category name
         * ($family) and a key.
         *
+        * Note: Boolean variables are defined as 0/1 in the database
+        *
         * @param string  $cat The category of the configuration value
         * @param string  $key The configuration key to query
         *
-        * @return mixed Stored value or "!<unset>!" if it does not exist
+        * @return null|mixed Stored value or null if it does not exist
         */
        public function get($cat, $key);
 
@@ -46,9 +48,9 @@ interface IConfigAdapter
         * and removes it from the database.
         *
         * @param string $cat The category of the configuration value
-        * @param string $key   The configuration key to delete
+        * @param string $key The configuration key to delete
         *
-        * @return mixed
+        * @return bool Operation success
         */
        public function delete($cat, $key);
 
index 8e6c050b276d0e22840d07a8c9043b9db29da75f..c505532c5922b7b6cb1809809463c3bb820cb010 100644 (file)
@@ -28,11 +28,13 @@ interface IPConfigAdapter
         * Get a particular user's config variable given the category name
         * ($family) and a key.
         *
+        * Note: Boolean variables are defined as 0/1 in the database
+        *
         * @param string  $uid           The user_id
         * @param string  $cat           The category of the configuration value
         * @param string  $key           The configuration key to query
         *
-        * @return mixed Stored value or "!<unset>!" if it does not exist
+        * @return null|mixed Stored value or null if it does not exist
         */
        public function get($uid, $cat, $key);
 
@@ -59,7 +61,7 @@ interface IPConfigAdapter
         * @param string $cat The category of the configuration value
         * @param string $key The configuration key to delete
         *
-        * @return bool
+        * @return bool Operation success
         */
        public function delete($uid, $cat, $key);
 
index c0d680d2c9657458f2c7029c2dae01f731db905f..5a41463036b2cfbfd18777f0aa4c4c73398efd0b 100644 (file)
@@ -34,40 +34,49 @@ class JITConfigAdapter extends AbstractDbaConfigAdapter implements IConfigAdapte
                $configs = DBA::select('config', ['v', 'k'], ['cat' => $cat]);
                while ($config = DBA::fetch($configs)) {
                        $key   = $config['k'];
-                       $value = $config['v'];
+                       $value = $this->toConfigValue($config['v']);
 
-                       if (isset($value) && $value !== '') {
+                       // The value was in the db, so don't check it again (unless you have to)
+                       $this->in_db[$cat][$key] = true;
+
+                       // just save it in case it is set
+                       if (isset($value)) {
                                $return[$key] = $value;
-                               $this->in_db[$cat][$key] = true;
                        }
                }
                DBA::close($configs);
 
-               return [$cat => $config];
+               return [$cat => $return];
        }
 
        /**
         * {@inheritdoc}
+        *
+        * @param bool $mark if true, mark the selection of the current cat/key pair
         */
-       public function get($cat, $key)
+       public function get($cat, $key, $mark = true)
        {
                if (!$this->isConnected()) {
-                       return '!<unset>!';
+                       return null;
+               }
+
+               // The value got checked, so mark it to avoid checking it over and over again
+               if ($mark) {
+                       $this->in_db[$cat][$key] = true;
                }
 
                $config = DBA::selectFirst('config', ['v'], ['cat' => $cat, 'k' => $key]);
                if (DBA::isResult($config)) {
                        // manage array value
-                       $value = (preg_match("|^a:[0-9]+:{.*}$|s", $config['v']) ? unserialize($config['v']) : $config['v']);
+                       $value = $this->toConfigValue($config['v']);
 
-                       if (isset($value) && $value !== '') {
-                               $this->in_db[$cat][$key] = true;
+                       // just return it in case it is set
+                       if (isset($value)) {
                                return $value;
                        }
                }
 
-               $this->in_db[$cat][$key] = false;
-               return '!<unset>!';
+               return null;
        }
 
        /**
@@ -84,7 +93,7 @@ class JITConfigAdapter extends AbstractDbaConfigAdapter implements IConfigAdapte
                // The exception are array values.
                $dbvalue = (!is_array($value) ? (string)$value : $value);
 
-               $stored = $this->get($cat, $key);
+               $stored = $this->get($cat, $key, false);
 
                if (!isset($this->in_db[$cat])) {
                        $this->in_db[$cat] = [];
@@ -93,12 +102,11 @@ class JITConfigAdapter extends AbstractDbaConfigAdapter implements IConfigAdapte
                        $this->in_db[$cat][$key] = false;
                }
 
-               if (($stored === $dbvalue) && $this->in_db[$cat][$key]) {
+               if (isset($stored) && ($stored === $dbvalue) && $this->in_db[$cat][$key]) {
                        return true;
                }
 
-               // manage array value
-               $dbvalue = (is_array($value) ? serialize($value) : $dbvalue);
+               $dbvalue = $this->toDbValue($dbvalue);
 
                $result = DBA::update('config', ['v' => $dbvalue], ['cat' => $cat, 'k' => $key], true);
 
index 4485ee5df9ddd759cccec5352318acc3ef9b5e06..e320104e730b2fbe4cc86d2ff86270c90bc2c019 100644 (file)
@@ -29,16 +29,18 @@ class JITPConfigAdapter extends AbstractDbaConfigAdapter implements IPConfigAdap
                if (DBA::isResult($pconfigs)) {
                        while ($pconfig = DBA::fetch($pconfigs)) {
                                $key = $pconfig['k'];
-                               $value = $pconfig['v'];
+                               $value = $this->toConfigValue($pconfig['v']);
 
-                               if (isset($value) && $value !== '') {
+                               // The value was in the db, so don't check it again (unless you have to)
+                               $this->in_db[$uid][$cat][$key] = true;
+
+                               if (isset($value)) {
                                        $return[$key] = $value;
-                                       $this->in_db[$uid][$cat][$key] = true;
                                }
                        }
                } else if ($cat != 'config') {
                        // Negative caching
-                       $return = "!<unset>!";
+                       $return = null;
                }
                DBA::close($pconfigs);
 
@@ -51,22 +53,23 @@ class JITPConfigAdapter extends AbstractDbaConfigAdapter implements IPConfigAdap
        public function get($uid, $cat, $key)
        {
                if (!$this->isConnected()) {
-                       return '!<unset>!';
+                       return null;
                }
 
+               // The value was in the db, so don't check it again (unless you have to)
+               $this->in_db[$uid][$cat][$key] = true;
+
                $pconfig = DBA::selectFirst('pconfig', ['v'], ['uid' => $uid, 'cat' => $cat, 'k' => $key]);
                if (DBA::isResult($pconfig)) {
-                       // manage array value
-                       $value = (preg_match("|^a:[0-9]+:{.*}$|s", $pconfig['v']) ? unserialize($pconfig['v']) : $pconfig['v']);
+                       $value = $this->toConfigValue($pconfig['v']);
 
-                       if (isset($value) && $value !== '') {
-                               $this->in_db[$uid][$cat][$key] = true;
+                       if (isset($value)) {
                                return $value;
                        }
                }
 
                $this->in_db[$uid][$cat][$key] = false;
-               return '!<unset>!';
+               return null;
        }
 
        /**
@@ -118,13 +121,11 @@ class JITPConfigAdapter extends AbstractDbaConfigAdapter implements IPConfigAdap
                        return false;
                }
 
-               if (!empty($this->in_db[$uid][$cat][$key])) {
+               if (isset($this->in_db[$uid][$cat][$key])) {
                        unset($this->in_db[$uid][$cat][$key]);
                }
 
-               $result = DBA::delete('pconfig', ['uid' => $uid, 'cat' => $cat, 'k' => $key]);
-
-               return $result;
+               return DBA::delete('pconfig', ['uid' => $uid, 'cat' => $cat, 'k' => $key]);
        }
 
        /**
index 218648cbdb4fc4e2c1dfaae67f959d24c7d2313c..7ebd1efcf8917fecd4642fa89461966b182faaed 100644 (file)
@@ -35,8 +35,6 @@ class PreloadConfigAdapter extends AbstractDbaConfigAdapter implements IConfigAd
                        $value = $config['v'];
                        if (isset($value) && $value !== '') {
                                $return[$config['cat']][$config['k']] = $value;
-                       } else {
-                               $return[$config['cat']][$config['k']] = '!<unset>!';
                        }
                }
                DBA::close($configs);
@@ -52,7 +50,7 @@ class PreloadConfigAdapter extends AbstractDbaConfigAdapter implements IConfigAd
        public function get($cat, $key)
        {
                if (!$this->isConnected()) {
-                       return '!<unset>!';
+                       return null;
                }
 
                $config = DBA::selectFirst('config', ['v'], ['cat' => $cat, 'k' => $key]);
@@ -65,7 +63,7 @@ class PreloadConfigAdapter extends AbstractDbaConfigAdapter implements IConfigAd
                        }
                }
 
-               return '!<unset>!';
+               return null;
        }
 
        /**
@@ -89,9 +87,7 @@ class PreloadConfigAdapter extends AbstractDbaConfigAdapter implements IConfigAd
                // manage array value
                $dbvalue = is_array($value) ? serialize($value) : $value;
 
-               $result = DBA::update('config', ['v' => $dbvalue], ['cat' => $cat, 'k' => $key], true);
-
-               return $result;
+               return DBA::update('config', ['v' => $dbvalue], ['cat' => $cat, 'k' => $key], true);
        }
 
        /**
@@ -103,9 +99,7 @@ class PreloadConfigAdapter extends AbstractDbaConfigAdapter implements IConfigAd
                        return false;
                }
 
-               $result = DBA::delete('config', ['cat' => $cat, 'k' => $key]);
-
-               return $result;
+               return DBA::delete('config', ['cat' => $cat, 'k' => $key]);
        }
 
        /**
index 12e25df9f903d069b081e036cf4cba0b11a07c18..d2ba971ff6a9cb82cd60ec284d028a0011a0a34f 100644 (file)
@@ -52,8 +52,6 @@ class PreloadPConfigAdapter extends AbstractDbaConfigAdapter implements IPConfig
                        $value = $pconfig['v'];
                        if (isset($value) && $value !== '') {
                                $return[$pconfig['cat']][$pconfig['k']] = $value;
-                       } else {
-                               $return[$pconfig['cat']][$pconfig['k']] = '!<unset>!';
                        }
                }
                DBA::close($pconfigs);
@@ -69,7 +67,7 @@ class PreloadPConfigAdapter extends AbstractDbaConfigAdapter implements IPConfig
        public function get($uid, $cat, $key)
        {
                if (!$this->isConnected()) {
-                       return '!<unset>!';
+                       return null;
                }
 
                if (!$this->isLoaded($uid, $cat, $key)) {
@@ -85,7 +83,7 @@ class PreloadPConfigAdapter extends AbstractDbaConfigAdapter implements IPConfig
                                return $value;
                        }
                }
-               return '!<unset>!';
+               return null;
        }
 
        /**
@@ -112,9 +110,7 @@ class PreloadPConfigAdapter extends AbstractDbaConfigAdapter implements IPConfig
                // manage array value
                $dbvalue = is_array($value) ? serialize($value) : $value;
 
-               $result = DBA::update('pconfig', ['v' => $dbvalue], ['uid' => $uid, 'cat' => $cat, 'k' => $key], true);
-
-               return $result;
+               return DBA::update('pconfig', ['v' => $dbvalue], ['uid' => $uid, 'cat' => $cat, 'k' => $key], true);
        }
 
        /**
@@ -130,9 +126,7 @@ class PreloadPConfigAdapter extends AbstractDbaConfigAdapter implements IPConfig
                        $this->load($uid, $cat);
                }
 
-               $result = DBA::delete('pconfig', ['uid' => $uid, 'cat' => $cat, 'k' => $key]);
-
-               return $result;
+               return DBA::delete('pconfig', ['uid' => $uid, 'cat' => $cat, 'k' => $key]);
        }
 
        /**
index 4ebcc87482f044b278d0fdd626d47b97624fc9da..cf50b43d4f4685fb1ba221ac8fa021aa9f559f65 100644 (file)
@@ -6,8 +6,6 @@ namespace Friendica\Core\Config\Cache;
  * The Friendica config cache for the application
  * Initial, all *.config.php files are loaded into this cache with the
  * ConfigCacheLoader ( @see ConfigCacheLoader )
- *
- * Is used for further caching operations too (depending on the ConfigAdapter )
  */
 class ConfigCache implements IConfigCache, IPConfigCache
 {
@@ -37,7 +35,7 @@ class ConfigCache implements IConfigCache, IPConfigCache
 
                                foreach ($keys as $key) {
                                        $value = $config[$category][$key];
-                                       if (isset($value) && $value !== '!<unset>!') {
+                                       if (isset($value)) {
                                                if ($overwrite) {
                                                        $this->set($category, $key, $value);
                                                } else {
@@ -56,22 +54,13 @@ class ConfigCache implements IConfigCache, IPConfigCache
        {
                if (isset($this->config[$cat][$key])) {
                        return $this->config[$cat][$key];
-               } elseif ($key == null && isset($this->config[$cat])) {
+               } elseif (!isset($key) && isset($this->config[$cat])) {
                        return $this->config[$cat];
                } else {
-                       return '!<unset>!';
+                       return null;
                }
        }
 
-       /**
-        * {@inheritdoc}
-        */
-       public function has($cat, $key = null)
-       {
-               return (isset($this->config[$cat][$key]) && $this->config[$cat][$key] !== '!<unset>!') ||
-               ($key == null && isset($this->config[$cat]) && $this->config[$cat] !== '!<unset>!' && is_array($this->config[$cat]));
-       }
-
        /**
         * Sets a default value in the config cache. Ignores already existing keys.
         *
@@ -91,9 +80,6 @@ class ConfigCache implements IConfigCache, IPConfigCache
         */
        public function set($cat, $key, $value)
        {
-               // Only arrays are serialized in database, so we have to unserialize sparingly
-               $value = is_string($value) && preg_match("|^a:[0-9]+:{.*}$|s", $value) ? unserialize($value) : $value;
-
                if (!isset($this->config[$cat])) {
                        $this->config[$cat] = [];
                }
@@ -103,15 +89,6 @@ class ConfigCache implements IConfigCache, IPConfigCache
                return true;
        }
 
-       /**
-        * {@inheritdoc}
-        */
-       public function hasP($uid, $cat, $key = null)
-       {
-               return (isset($this->config[$uid][$cat][$key]) && $this->config[$uid][$cat][$key] !== '!<unset>!') ||
-                       ($key == null && isset($this->config[$uid][$cat]) && $this->config[$uid][$cat] !== '!<unset>!' && is_array($this->config[$uid][$cat]));
-       }
-
        /**
         * {@inheritdoc}
         */
@@ -142,7 +119,7 @@ class ConfigCache implements IConfigCache, IPConfigCache
 
                                foreach ($keys as $key) {
                                        $value = $config[$category][$key];
-                                       if (isset($value) && $value !== '!<unset>!') {
+                                       if (isset($value)) {
                                                $this->setP($uid, $category, $key, $value);
                                        }
                                }
@@ -157,10 +134,10 @@ class ConfigCache implements IConfigCache, IPConfigCache
        {
                if (isset($this->config[$uid][$cat][$key])) {
                        return $this->config[$uid][$cat][$key];
-               } elseif ($key == null && isset($this->config[$uid][$cat])) {
+               } elseif (!isset($key) && isset($this->config[$uid][$cat])) {
                        return $this->config[$uid][$cat];
                } else {
-                       return '!<unset>!';
+                       return null;
                }
        }
 
@@ -169,9 +146,6 @@ class ConfigCache implements IConfigCache, IPConfigCache
         */
        public function setP($uid, $cat, $key, $value)
        {
-               // Only arrays are serialized in database, so we have to unserialize sparingly
-               $value = is_string($value) && preg_match("|^a:[0-9]+:{.*}$|s", $value) ? unserialize($value) : $value;
-
                if (!isset($this->config[$uid]) || !is_array($this->config[$uid])) {
                        $this->config[$uid] = [];
                }
index b728d1082140c5279d70f03d8ca6791c1770b25b..b043bf27cbc21b0e19d0d5ab194261ec90d1e332 100644 (file)
@@ -37,9 +37,6 @@ class ConfigCacheLoader
         */
        public function loadConfigFiles(ConfigCache $config)
        {
-               // Setting at least the basepath we know
-               $config->set('system', 'basepath', $this->baseDir);
-
                $config->load($this->loadCoreConfig('defaults'));
                $config->load($this->loadCoreConfig('settings'));
 
index 9d948527d4659d359a139207483c0bb36f907607..499bd312d0c5365d836de46b453941c3073a4de7 100644 (file)
@@ -20,9 +20,9 @@ interface IConfigCache
         * Gets a value from the config cache.
         *
         * @param string $cat     Config category
-        * @param string $key       Config key
+        * @param string $key     Config key
         *
-        * @return mixed Returns the value of the Config entry or '!<unset>!' if not set
+        * @return null|mixed Returns the value of the Config entry or null if not set
         */
        function get($cat, $key = null);
 
@@ -47,15 +47,6 @@ interface IConfigCache
         */
        function delete($cat, $key);
 
-       /**
-        * Checks if a value is set in the config cache.
-        *
-        * @param string $cat  Config category
-        * @param string $key  Config key
-        * @return bool
-        */
-       function has($cat, $key = null);
-
        /**
         * Returns the whole configuration cache
         *
index 4ac21481a15180bff68ef3a832db56bfdfaee030..30076a2a9302db8712df0546ad098980fa40dd15 100644 (file)
@@ -23,7 +23,7 @@ interface IPConfigCache
         * @param string $cat     Config category
         * @param string $key     Config key
         *
-        * @return string The value of the config entry or '!<unset>!' if not set
+        * @return null|string The value of the config entry or null if not set
         */
        function getP($uid, $cat, $key = null);
 
@@ -50,17 +50,6 @@ interface IPConfigCache
         */
        function deleteP($uid, $cat, $key);
 
-
-       /**
-        * Checks if a value is set in the user config cache.
-        *
-        * @param int    $uid  User Id
-        * @param string $cat  Config category
-        * @param string $key  Config key
-        * @return bool
-        */
-       function hasP($uid, $cat, $key = null);
-
        /**
         * Returns the whole configuration cache
         *
index 2ac0da0ad1b967b0d580f1f559b2d971f3f055e7..532ed982a9d46498d3de738e741f58db33b26cbc 100644 (file)
@@ -83,20 +83,19 @@ class Configuration
                if ($this->configAdapter->isConnected() &&
                        (!$this->configAdapter->isLoaded($cat, $key) ||
                        $refresh)) {
+
                        $dbvalue = $this->configAdapter->get($cat, $key);
 
-                       if ($dbvalue !== '!<unset>!') {
+                       if (isset($dbvalue)) {
                                $this->configCache->set($cat, $key, $dbvalue);
                                return $dbvalue;
                        }
                }
 
                // use the config cache for return
-               if ($this->configCache->has($cat, $key)) {
-                       return $this->configCache->get($cat, $key);
-               } else {
-                       return $default_value;
-               }
+               $result = $this->configCache->get($cat, $key);
+
+               return (isset($result)) ? $result : $default_value;
        }
 
        /**
index 99b1aa14698b17d9b14fc0f57c966b39419c22dc..0d3b0c178c6cb24c02a53c8ec54454e3a096e220 100644 (file)
@@ -77,18 +77,15 @@ class PConfiguration
                                $refresh)) {
                        $dbValue = $this->configAdapter->get($uid, $cat, $key);
 
-                       if ($dbValue !== '!<unset>!') {
+                       if (isset($dbValue)) {
                                $this->configCache->setP($uid, $cat, $key, $dbValue);
                                return $dbValue;
                        }
                }
 
                // use the config cache for return
-               if ($this->configCache->hasP($uid, $cat, $key)) {
-                       return $this->configCache->getP($uid, $cat, $key);
-               } else {
-                       return $default_value;
-               }
+               $result = $this->configCache->getP($uid, $cat, $key);
+               return (isset($result)) ? $result : $default_value;
        }
 
        /**
index f62b59f4765342e2b5b77fc5d35b9a09b6c9b1e2..da4c802937d301271f3d80497bb454a50b5a2983 100644 (file)
@@ -65,8 +65,6 @@ class PConfig
        /**
         * @brief Sets a configuration value for a user
         *
-        * @note  Please do not store booleans - convert to 0/1 integer values!
-        *
         * @param string $uid    The user_id
         * @param string $cat    The category of the configuration value
         * @param string $key    The configuration key to set
index 1c17d9aca52d38f7a59ea91e9a9cf2ccfef85c10..97e5c63c808296a06a77026c4e588b091bea1a6d 100644 (file)
@@ -40,6 +40,10 @@ class DBA
         * @var Profiler
         */
        private static $profiler;
+       /**
+        * @var string
+        */
+       private static $basedir;
        private static $server_info = '';
        private static $connection;
        private static $driver;
@@ -55,13 +59,14 @@ class DBA
        private static $db_name = '';
        private static $db_charset = '';
 
-       public static function connect(IConfigCache $configCache, Profiler $profiler, $serveraddr, $user, $pass, $db, $charset = null)
+       public static function connect($basedir, IConfigCache $configCache, Profiler $profiler, $serveraddr, $user, $pass, $db, $charset = null)
        {
                if (!is_null(self::$connection) && self::connected()) {
                        return true;
                }
 
                // We are storing these values for being able to perform a reconnect
+               self::$basedir = $basedir;
                self::$configCache = $configCache;
                self::$profiler = $profiler;
                self::$db_serveraddr = $serveraddr;
@@ -1034,7 +1039,7 @@ class DBA
         * This process must only be started once, since the value is cached.
         */
        private static function buildRelationData() {
-               $definition = DBStructure::definition(self::$configCache->get('system', 'basepath'));
+               $definition = DBStructure::definition(self::$basedir);
 
                foreach ($definition AS $table => $structure) {
                        foreach ($structure['fields'] AS $field => $field_struct) {
index c1a7965013e84a14dff775c365a7d11e2f3a9a85..b4f0c9e3c194eb11f664df918c3654a04e96f366 100644 (file)
@@ -11,13 +11,16 @@ class DBFactory
        /**
         * Initialize the DBA connection
         *
+        * @param string             $basePath    The basepath of the application
         * @param Cache\IConfigCache $configCache The configuration cache
-        * @param Profiler          $profiler    The profiler
-        * @param array             $server      The $_SERVER variables
+        * @param Profiler           $profiler    The profiler
+        * @param array              $server      The $_SERVER variables
         *
         * @throws \Exception if connection went bad
+        *
+        * @todo refactor basedir during https://github.com/friendica/friendica/issues/6720
         */
-       public static function init(Cache\IConfigCache $configCache, Profiler $profiler, array $server)
+       public static function init($basePath, Cache\IConfigCache $configCache, Profiler $profiler, array $server)
        {
                if (Database\DBA::connected()) {
                        return;
@@ -48,9 +51,9 @@ class DBFactory
                        $db_data = $server['MYSQL_DATABASE'];
                }
 
-               if (Database\DBA::connect($configCache, $profiler, $db_host, $db_user, $db_pass, $db_data, $charset)) {
+               if (Database\DBA::connect($basePath, $configCache, $profiler, $db_host, $db_user, $db_pass, $db_data, $charset)) {
                        // Loads DB_UPDATE_VERSION constant
-                       Database\DBStructure::definition($configCache->get('system', 'basepath'), false);
+                       Database\DBStructure::definition($basePath, false);
                }
 
                unset($db_host, $db_user, $db_pass, $db_data, $charset);
index acbf4bfaf7a0ced05776e455404baba58439d194..52178bb77fb9d41e753205f187d94d20b55f191d 100644 (file)
@@ -22,16 +22,16 @@ class DependencyFactory
         */
        public static function setUp($channel, $directory, $isBackend = true)
        {
-               $basedir = BasePath::create($directory, $_SERVER);
-               $configLoader = new Cache\ConfigCacheLoader($basedir);
+               $basePath = BasePath::create($directory, $_SERVER);
+               $configLoader = new Cache\ConfigCacheLoader($basePath);
                $configCache = Factory\ConfigFactory::createCache($configLoader);
                $profiler = Factory\ProfilerFactory::create($configCache);
-               Factory\DBFactory::init($configCache, $profiler, $_SERVER);
+               Factory\DBFactory::init($basePath, $configCache, $profiler, $_SERVER);
                $config = Factory\ConfigFactory::createConfig($configCache);
                // needed to call PConfig::init()
                Factory\ConfigFactory::createPConfig($configCache);
                $logger = Factory\LoggerFactory::create($channel, $config);
 
-               return new App($config, $logger, $profiler, $isBackend);
+               return new App($basePath, $config, $logger, $profiler, $isBackend);
        }
 }
index 152e870e8595c57da88a7f14212b9a8131cb173b..8ad7f3145f3d8c30d593c3b1b34c24999774171a 100644 (file)
@@ -10,8 +10,8 @@ use Friendica\BaseObject;
 use Friendica\Core\Cache;
 use Friendica\Core\Config;
 use Friendica\Core\L10n;
-use Friendica\Core\System;
 use Friendica\Core\StorageManager;
+use Friendica\Core\System;
 use Friendica\Database\DBA;
 use Friendica\Database\DBStructure;
 use Friendica\Model\Storage\IStorage;
@@ -203,7 +203,7 @@ class Photo extends BaseObject
         */
        private static function getFields()
        {
-               $allfields = DBStructure::definition(false);
+               $allfields = DBStructure::definition(self::getApp()->getBasePath(), false);
                $fields = array_keys($allfields["photo"]["fields"]);
                array_splice($fields, array_search("data", $fields), 1);
                return $fields;
index 289b3fcea54f278db4f5b099817d7dd7109b0f0f..2f8becc18cb8195b8beaf10808014e46b0c636d0 100644 (file)
@@ -36,15 +36,15 @@ class ApiTest extends DatabaseTest
         */
        public function setUp()
        {
-               $basedir = BasePath::create(dirname(__DIR__) . '/../');
-               $configLoader = new Cache\ConfigCacheLoader($basedir);
+               $basePath = BasePath::create(dirname(__DIR__) . '/../');
+               $configLoader = new Cache\ConfigCacheLoader($basePath);
                $configCache = Factory\ConfigFactory::createCache($configLoader);
                $profiler = Factory\ProfilerFactory::create($configCache);
-               Factory\DBFactory::init($configCache, $profiler, $_SERVER);
+               Factory\DBFactory::init($basePath, $configCache, $profiler, $_SERVER);
                $config = Factory\ConfigFactory::createConfig($configCache);
                Factory\ConfigFactory::createPConfig($configCache);
                $logger = Factory\LoggerFactory::create('test', $config);
-               $this->app = new App($config, $logger, $profiler, false);
+               $this->app = new App($basePath, $config, $logger, $profiler, false);
 
                parent::setUp();
 
index e8b9c68b19c3aff0f40e9457c923931ab4bf4e4a..8e102ec63237f27be346ef9b6bc621d3cbf9e38e 100644 (file)
@@ -13,15 +13,15 @@ class DBATest extends DatabaseTest
 {
        public function setUp()
        {
-               $basedir = BasePath::create(dirname(__DIR__) . '/../../');
-               $configLoader = new Cache\ConfigCacheLoader($basedir);
+               $basePath = BasePath::create(dirname(__DIR__) . '/../../');
+               $configLoader = new Cache\ConfigCacheLoader($basePath);
                $configCache = Factory\ConfigFactory::createCache($configLoader);
                $profiler = Factory\ProfilerFactory::create($configCache);
-               Factory\DBFactory::init($configCache, $profiler, $_SERVER);
+               Factory\DBFactory::init($basePath, $configCache, $profiler, $_SERVER);
                $config = Factory\ConfigFactory::createConfig($configCache);
                Factory\ConfigFactory::createPConfig($configCache);
                $logger = Factory\LoggerFactory::create('test', $config);
-               $this->app = new App($config, $logger, $profiler, false);
+               $this->app = new App($basePath, $config, $logger, $profiler, false);
 
                parent::setUp();
 
index 325ad4e5e7f18571358e7403473b265c0d437129..454d6e8a4e20673266cd65cfb26f4bc3ae9eb9f1 100644 (file)
@@ -13,15 +13,15 @@ class DBStructureTest extends DatabaseTest
 {
        public function setUp()
        {
-               $basedir = BasePath::create(dirname(__DIR__) . '/../../');
-               $configLoader = new Cache\ConfigCacheLoader($basedir);
+               $basePath = BasePath::create(dirname(__DIR__) . '/../../');
+               $configLoader = new Cache\ConfigCacheLoader($basePath);
                $configCache = Factory\ConfigFactory::createCache($configLoader);
                $profiler = Factory\ProfilerFactory::create($configCache);
-               Factory\DBFactory::init($configCache, $profiler, $_SERVER);
+               Factory\DBFactory::init($basePath, $configCache, $profiler, $_SERVER);
                $config = Factory\ConfigFactory::createConfig($configCache);
                Factory\ConfigFactory::createPConfig($configCache);
                $logger = Factory\LoggerFactory::create('test', $config);
-               $this->app = new App($config, $logger, $profiler, false);
+               $this->app = new App($basePath, $config, $logger, $profiler, false);
 
                parent::setUp();
        }