]> git.mxchange.org Git - friendica.git/commitdiff
Migrate distributed cache config value
authorPhilipp <admin@philipp.info>
Tue, 14 Dec 2021 09:14:24 +0000 (10:14 +0100)
committerPhilipp <admin@philipp.info>
Tue, 14 Dec 2021 09:14:24 +0000 (10:14 +0100)
database.sql
src/Core/Config/Util/ConfigFileLoader.php
src/Core/Config/ValueObject/Cache.php
static/dbstructure.config.php
update.php

index bdf928fbe563caba1858bcf4ce09b267cdca8189..d1c73cc048f3f606932d629760f3f8145188cd47 100644 (file)
@@ -1,6 +1,6 @@
 -- ------------------------------------------
 -- Friendica 2021.12-rc (Siberian Iris)
--- DB_UPDATE_VERSION 1445
+-- DB_UPDATE_VERSION 1446
 -- ------------------------------------------
 
 
index 7740ec326aa87d7165013e7178584be333c0a03b..853e7921495ddf8441cb11bc00cf2a3b385c3bbe 100644 (file)
@@ -96,8 +96,8 @@ class ConfigFileLoader
        public function setupCache(Cache $config, array $server = [], bool $raw = false)
        {
                // Load static config files first, the order is important
-               $config->load($this->loadStaticConfig('defaults'), Cache::SOURCE_FILE);
-               $config->load($this->loadStaticConfig('settings'), Cache::SOURCE_FILE);
+               $config->load($this->loadStaticConfig('defaults'), Cache::SOURCE_STATIC);
+               $config->load($this->loadStaticConfig('settings'), Cache::SOURCE_STATIC);
 
                // try to load the legacy config first
                $config->load($this->loadLegacyConfig('htpreconfig'), Cache::SOURCE_FILE);
index e92bccea40f73d3ee96407cd73c4135fa68d16a8..1a176d16015de2c87e2173cf18ceaa5c4aa43a78 100644 (file)
@@ -31,14 +31,16 @@ use ParagonIE\HiddenString\HiddenString;
  */
 class Cache
 {
+       /** @var int Indicates that the cache entry is a default value - Lowest Priority */
+       const SOURCE_STATIC = 0;
        /** @var int Indicates that the cache entry is set by file - Low Priority */
-       const SOURCE_FILE = 0;
+       const SOURCE_FILE = 1;
        /** @var int Indicates that the cache entry is set by the DB config table - Middle Priority */
-       const SOURCE_DB = 1;
+       const SOURCE_DB = 2;
        /** @var int Indicates that the cache entry is set by a server environment variable - High Priority */
        const SOURCE_ENV = 3;
        /** @var int Indicates that the cache entry is fixed and must not be changed */
-       const SOURCE_FIX = 4;
+       const SOURCE_FIX = 5;
 
        /** @var int Default value for a config source */
        const SOURCE_DEFAULT = self::SOURCE_FILE;
@@ -113,6 +115,19 @@ class Cache
                }
        }
 
+       /**
+        * Returns the source value of the current, cached config value
+        *
+        * @param string $cat Config category
+        * @param string $key Config key
+        *
+        * @return int
+        */
+       public function getSource(string $cat, string $key): int
+       {
+               return $this->source[$cat][$key] ?? -1;
+       }
+
        /**
         * Sets a value in the config cache. Accepts raw output from the config table
         *
index e0645c05e07f0ddc10a2f9631277225f70501bf8..1c3b296ca3fed1363570bb4d3b2615b113666049 100644 (file)
@@ -55,7 +55,7 @@
 use Friendica\Database\DBA;
 
 if (!defined('DB_UPDATE_VERSION')) {
-       define('DB_UPDATE_VERSION', 1445);
+       define('DB_UPDATE_VERSION', 1446);
 }
 
 return [
index 81e5be8d649875be0c76d4810003ba5cc909e72f..82351a7b2a732a259ae9daa35d03819bf2cf4e57 100644 (file)
@@ -1070,3 +1070,18 @@ function update_1444()
 
        return Update::SUCCESS;
 }
+
+function update_1446()
+{
+       $distributed_cache_driver_source = DI::config()->getCache()->getSource('system', 'distributed_cache_driver');
+       $cache_driver_source = DI::config()->getCache()->getSource('system', 'cache_driver');
+
+       // In case the distributed cache driver is the default value, but the current cache driver isn't default,
+       // we assume that the distributed cache driver should be the same as the current cache driver
+       if ($distributed_cache_driver_source === \Friendica\Core\Config\ValueObject\Cache::SOURCE_STATIC &&
+               $cache_driver_source !== \Friendica\Core\Config\ValueObject\Cache::SOURCE_STATIC) {
+                DI::config()->set('system', 'distributed_cache_driver', DI::config()->get('system', 'cache_driver'));
+       }
+
+       return Update::SUCCESS;
+}
\ No newline at end of file