]> git.mxchange.org Git - friendica.git/commitdiff
Apply suggestions
authorPhilipp <admin@philipp.info>
Tue, 3 Jan 2023 16:24:05 +0000 (17:24 +0100)
committerPhilipp <admin@philipp.info>
Tue, 3 Jan 2023 16:24:05 +0000 (17:24 +0100)
17 files changed:
src/Console/Maintenance.php
src/Console/Relocate.php
src/Core/Config/Capability/IManageConfigValues.php
src/Core/Config/Capability/ISetConfigValuesTransactional.php [deleted file]
src/Core/Config/Capability/ISetConfigValuesTransactionally.php [new file with mode: 0644]
src/Core/Config/Model/Config.php
src/Core/Config/Model/ConfigTransaction.php [new file with mode: 0644]
src/Core/Config/Model/TransactionalConfig.php [deleted file]
src/Core/Config/ValueObject/Cache.php
src/Core/Update.php
src/Database/DBStructure.php
src/Module/Admin/Site.php
tests/src/Core/Config/Cache/CacheTest.php
tests/src/Core/Config/ConfigTransactionTest.php [new file with mode: 0644]
tests/src/Core/Config/TransactionalConfigTest.php [deleted file]
update.php
view/theme/frio/style.php

index 6a11eb2bb57ba9027a8aef828774b0e56063a57e..076b89db828279fc8bc7d0b7c97370b5af777747 100644 (file)
@@ -100,7 +100,7 @@ HELP;
 
                $enabled = intval($this->getArgument(0));
 
-               $transactionConfig = $this->config->transactional();
+               $transactionConfig = $this->config->beginTransaction();
 
                $transactionConfig->set('system', 'maintenance', $enabled);
 
@@ -112,7 +112,7 @@ HELP;
                        $transactionConfig->delete('system', 'maintenance_reason');
                }
 
-               $transactionConfig->save();
+               $transactionConfig->commit();
 
                if ($enabled) {
                        $mode_str = "maintenance mode";
index 7a2ef1d0712e02af8e259d1734d593c2aafa199e..c63434cbb7e6e22b2176342937ecf6be30238f81 100644 (file)
@@ -101,9 +101,10 @@ HELP;
                $old_host = str_replace('http://', '@', Strings::normaliseLink($old_url));
 
                $this->out('Entering maintenance mode');
-               $this->config->set('system', 'maintenance', true, false);
-               $this->config->set('system', 'maintenance_reason', 'Relocating node to ' . $new_url, false);
-
+               $this->config->beginTransaction()
+                                        ->set('system', 'maintenance', true)
+                                        ->set('system', 'maintenance_reason', 'Relocating node to ' . $new_url)
+                                        ->commit();
                try {
                        if (!$this->database->transaction()) {
                                throw new \Exception('Unable to start a transaction, please retry later.');
@@ -189,10 +190,10 @@ HELP;
                        return 1;
                } finally {
                        $this->out('Leaving maintenance mode');
-                       $this->config->transactional()
+                       $this->config->beginTransaction()
                                                 ->set('system', 'maintenance', false)
                                                 ->delete('system', 'maintenance_reason')
-                                                ->save();
+                                                ->commit();
                }
 
                // send relocate
index 42ebea0004f207693015b7397cfab2d6082c880a..715887ddf3cee96670d896d47ac6e49b82c3e9d7 100644 (file)
@@ -94,9 +94,9 @@ interface IManageConfigValues
         *
         * It relies on the current instance, so after save(), the values of this config class will get altered at once too.
         *
-        * @return ISetConfigValuesTransactional
+        * @return ISetConfigValuesTransactionally
         */
-       public function transactional(): ISetConfigValuesTransactional;
+       public function beginTransaction(): ISetConfigValuesTransactionally;
 
        /**
         * Deletes the given key from the system configuration.
diff --git a/src/Core/Config/Capability/ISetConfigValuesTransactional.php b/src/Core/Config/Capability/ISetConfigValuesTransactional.php
deleted file mode 100644 (file)
index 9c58427..0000000
+++ /dev/null
@@ -1,84 +0,0 @@
-<?php
-/**
- * @copyright Copyright (C) 2010-2023, the Friendica project
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program.  If not, see <https://www.gnu.org/licenses/>.
- *
- */
-
-namespace Friendica\Core\Config\Capability;
-
-use Friendica\Core\Config\Exception\ConfigPersistenceException;
-
-/**
- * Interface for transactional saving of config values
- * It buffers every set/delete until "save()" is called
- */
-interface ISetConfigValuesTransactional
-{
-       /**
-        * Get a particular user's config variable given the category name
-        * ($cat) and a $key.
-        *
-        * Get a particular config value from the given category ($cat)
-        *
-        * @param string  $cat        The category of the configuration value
-        * @param string  $key           The configuration key to query
-        *
-        * @return mixed Stored value or null if it does not exist
-        *
-        * @throws ConfigPersistenceException In case the persistence layer throws errors
-        *
-        */
-       public function get(string $cat, string $key);
-
-       /**
-        * Sets a configuration value for system 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
-        *
-        * @return static the current instance
-        *
-        * @throws ConfigPersistenceException In case the persistence layer throws errors
-        */
-       public function set(string $cat, string $key, $value): self;
-
-       /**
-        * Deletes the given key from the system configuration.
-        *
-        * @param string $cat The category of the configuration value
-        * @param string $key The configuration key to delete
-        *
-        * @return static the current instance
-        *
-        * @throws ConfigPersistenceException In case the persistence layer throws errors
-        *
-        */
-       public function delete(string $cat, string $key): self;
-
-       /**
-        * Saves the node specific config values
-        *
-        * @throws ConfigPersistenceException In case the persistence layer throws errors
-        */
-       public function save(): void;
-}
diff --git a/src/Core/Config/Capability/ISetConfigValuesTransactionally.php b/src/Core/Config/Capability/ISetConfigValuesTransactionally.php
new file mode 100644 (file)
index 0000000..ae193f2
--- /dev/null
@@ -0,0 +1,84 @@
+<?php
+/**
+ * @copyright Copyright (C) 2010-2023, the Friendica project
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace Friendica\Core\Config\Capability;
+
+use Friendica\Core\Config\Exception\ConfigPersistenceException;
+
+/**
+ * Interface for transactional saving of config values
+ * It buffers every set/delete until "save()" is called
+ */
+interface ISetConfigValuesTransactionally
+{
+       /**
+        * Get a particular user's config variable given the category name
+        * ($cat) and a $key.
+        *
+        * Get a particular config value from the given category ($cat)
+        *
+        * @param string  $cat        The category of the configuration value
+        * @param string  $key           The configuration key to query
+        *
+        * @return mixed Stored value or null if it does not exist
+        *
+        * @throws ConfigPersistenceException In case the persistence layer throws errors
+        *
+        */
+       public function get(string $cat, string $key);
+
+       /**
+        * Sets a configuration value for system 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
+        *
+        * @return static the current instance
+        *
+        * @throws ConfigPersistenceException In case the persistence layer throws errors
+        */
+       public function set(string $cat, string $key, $value): self;
+
+       /**
+        * Deletes the given key from the system configuration.
+        *
+        * @param string $cat The category of the configuration value
+        * @param string $key The configuration key to delete
+        *
+        * @return static the current instance
+        *
+        * @throws ConfigPersistenceException In case the persistence layer throws errors
+        *
+        */
+       public function delete(string $cat, string $key): self;
+
+       /**
+        * Commits the changes of the current transaction
+        *
+        * @throws ConfigPersistenceException In case the persistence layer throws errors
+        */
+       public function commit(): void;
+}
index 24f5fd3b590a1f105e7be081e342541d42ed3249..29ea6b12d3a222f7c4753d7d34fb7f43882d4382 100644 (file)
@@ -22,7 +22,7 @@
 namespace Friendica\Core\Config\Model;
 
 use Friendica\Core\Config\Capability\IManageConfigValues;
-use Friendica\Core\Config\Capability\ISetConfigValuesTransactional;
+use Friendica\Core\Config\Capability\ISetConfigValuesTransactionally;
 use Friendica\Core\Config\Exception\ConfigFileException;
 use Friendica\Core\Config\Exception\ConfigPersistenceException;
 use Friendica\Core\Config\Util\ConfigFileManager;
@@ -63,9 +63,9 @@ class Config implements IManageConfigValues
        }
 
        /**     {@inheritDoc} */
-       public function transactional(): ISetConfigValuesTransactional
+       public function beginTransaction(): ISetConfigValuesTransactionally
        {
-               return new TransactionalConfig($this);
+               return new ConfigTransaction($this);
        }
 
        /**
diff --git a/src/Core/Config/Model/ConfigTransaction.php b/src/Core/Config/Model/ConfigTransaction.php
new file mode 100644 (file)
index 0000000..7ec5784
--- /dev/null
@@ -0,0 +1,89 @@
+<?php
+/**
+ * @copyright Copyright (C) 2010-2023, the Friendica project
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace Friendica\Core\Config\Model;
+
+use Friendica\Core\Config\Capability\IManageConfigValues;
+use Friendica\Core\Config\Capability\ISetConfigValuesTransactionally;
+use Friendica\Core\Config\Exception\ConfigPersistenceException;
+use Friendica\Core\Config\ValueObject\Cache;
+
+/**
+ * Transaction class for configurations, which sets values into a temporary buffer until "save()" is called
+ */
+class ConfigTransaction implements ISetConfigValuesTransactionally
+{
+       /** @var IManageConfigValues */
+       protected $config;
+       /** @var Cache */
+       protected $cache;
+       /** @var Cache */
+       protected $delCache;
+
+       public function __construct(IManageConfigValues $config)
+       {
+               $this->config   = $config;
+               $this->cache    = new Cache();
+               $this->delCache = new Cache();
+       }
+
+       /** {@inheritDoc} */
+       public function get(string $cat, string $key)
+       {
+               return !$this->delCache->get($cat, $key) ?
+                       ($this->cache->get($cat, $key) ?? $this->config->get($cat, $key)) :
+                       null;
+       }
+
+       /** {@inheritDoc} */
+       public function set(string $cat, string $key, $value): ISetConfigValuesTransactionally
+       {
+               $this->cache->set($cat, $key, $value, Cache::SOURCE_DATA);
+
+               return $this;
+       }
+
+
+       /** {@inheritDoc} */
+       public function delete(string $cat, string $key): ISetConfigValuesTransactionally
+       {
+               $this->cache->delete($cat, $key);
+               $this->delCache->set($cat, $key, 'deleted');
+
+               return $this;
+       }
+
+       /** {@inheritDoc} */
+       public function commit(): void
+       {
+               try {
+                       $newCache = $this->config->getCache()->merge($this->cache);
+                       $newCache = $newCache->diff($this->delCache);
+                       $this->config->load($newCache);
+
+                       // flush current cache
+                       $this->cache    = new Cache();
+                       $this->delCache = new Cache();
+               } catch (\Exception $e) {
+                       throw new ConfigPersistenceException('Cannot save config', $e);
+               }
+       }
+}
diff --git a/src/Core/Config/Model/TransactionalConfig.php b/src/Core/Config/Model/TransactionalConfig.php
deleted file mode 100644 (file)
index e9aa711..0000000
+++ /dev/null
@@ -1,89 +0,0 @@
-<?php
-/**
- * @copyright Copyright (C) 2010-2023, the Friendica project
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program.  If not, see <https://www.gnu.org/licenses/>.
- *
- */
-
-namespace Friendica\Core\Config\Model;
-
-use Friendica\Core\Config\Capability\IManageConfigValues;
-use Friendica\Core\Config\Capability\ISetConfigValuesTransactional;
-use Friendica\Core\Config\Exception\ConfigPersistenceException;
-use Friendica\Core\Config\ValueObject\Cache;
-
-/**
- * config class, which sets values into a temporary buffer until "save()" is called
- */
-class TransactionalConfig implements ISetConfigValuesTransactional
-{
-       /** @var IManageConfigValues */
-       protected $config;
-       /** @var Cache */
-       protected $cache;
-       /** @var Cache */
-       protected $delCache;
-
-       public function __construct(IManageConfigValues $config)
-       {
-               $this->config   = $config;
-               $this->cache    = new Cache();
-               $this->delCache = new Cache();
-       }
-
-       /** {@inheritDoc} */
-       public function get(string $cat, string $key)
-       {
-               return !$this->delCache->get($cat, $key) ?
-                       ($this->cache->get($cat, $key) ?? $this->config->get($cat, $key)) :
-                       null;
-       }
-
-       /** {@inheritDoc} */
-       public function set(string $cat, string $key, $value): ISetConfigValuesTransactional
-       {
-               $this->cache->set($cat, $key, $value, Cache::SOURCE_DATA);
-
-               return $this;
-       }
-
-
-       /** {@inheritDoc} */
-       public function delete(string $cat, string $key): ISetConfigValuesTransactional
-       {
-               $this->cache->delete($cat, $key);
-               $this->delCache->set($cat, $key, 'deleted');
-
-               return $this;
-       }
-
-       /** {@inheritDoc} */
-       public function save(): void
-       {
-               try {
-                       $newCache = $this->config->getCache()->merge($this->cache);
-                       $newCache = $newCache->diff($this->delCache);
-                       $this->config->load($newCache);
-
-                       // flush current cache
-                       $this->cache    = new Cache();
-                       $this->delCache = new Cache();
-               } catch (\Exception $e) {
-                       throw new ConfigPersistenceException('Cannot save config', $e);
-               }
-       }
-}
index 305c00d3305b6abf3ce062f1d874149dc5b317b9..b5af3280c0e6cf2960b7ddcffb9afe367a9f6a19 100644 (file)
@@ -332,10 +332,8 @@ class Cache
                                $keys = array_keys($cache->config[$category]);
 
                                foreach ($keys as $key) {
-                                       if (!is_null($newConfig[$category][$key] ?? null)) {
-                                               unset($newConfig[$category][$key]);
-                                               unset($newSource[$category][$key]);
-                                       }
+                                       unset($newConfig[$category][$key]);
+                                       unset($newSource[$category][$key]);
                                }
                        }
                }
index a02645783357b675ab111f764f78005126ed38a3..e5ee587dc1ca5adfa4a2d21d4712638ce55034fd 100644 (file)
@@ -160,10 +160,10 @@ class Update
                                                        Logger::warning('Pre update failed', ['version' => $version]);
                                                        DI::config()->set('system', 'update', Update::FAILED);
                                                        DI::lock()->release('dbupdate');
-                                                       DI::config()->transactional()
+                                                       DI::config()->beginTransaction()
                                                                                ->set('system', 'maintenance', false)
                                                                                ->delete('system', 'maintenance_reason')
-                                                                               ->save();
+                                                                               ->commit();
                                                        return $r;
                                                } else {
                                                        Logger::notice('Pre update executed.', ['version' => $version]);
@@ -183,10 +183,10 @@ class Update
                                                Logger::error('Update ERROR.', ['from' => $stored, 'to' => $current, 'retval' => $retval]);
                                                DI::config()->set('system', 'update', Update::FAILED);
                                                DI::lock()->release('dbupdate');
-                                               DI::config()->transactional()
+                                               DI::config()->beginTransaction()
                                                                        ->set('system', 'maintenance', false)
                                                                        ->delete('system', 'maintenance_reason')
-                                                                       ->save();
+                                                                       ->commit();
                                                return $retval;
                                        } else {
                                                Logger::notice('Database structure update finished.', ['from' => $stored, 'to' => $current]);
@@ -202,10 +202,10 @@ class Update
                                                        Logger::warning('Post update failed', ['version' => $version]);
                                                        DI::config()->set('system', 'update', Update::FAILED);
                                                        DI::lock()->release('dbupdate');
-                                                       DI::config()->transactional()
+                                                       DI::config()->beginTransaction()
                                                                                ->set('system', 'maintenance', false)
                                                                                ->delete('system', 'maintenance_reason')
-                                                                               ->save();
+                                                                               ->commit();
                                                        return $r;
                                                } else {
                                                        DI::config()->set('system', 'build', $version);
@@ -216,10 +216,10 @@ class Update
                                        DI::config()->set('system', 'build', $current);
                                        DI::config()->set('system', 'update', Update::SUCCESS);
                                        DI::lock()->release('dbupdate');
-                                       DI::config()->transactional()
+                                       DI::config()->beginTransaction()
                                                                ->set('system', 'maintenance', false)
                                                                ->delete('system', 'maintenance_reason')
-                                                               ->save();
+                                                               ->commit();
 
                                        Logger::notice('Update success.', ['from' => $stored, 'to' => $current]);
                                        if ($sendMail) {
index ed2a5e30e7cb21e4abf618b1fe2f39c103ce503f..7b284bf6d5cd3e01c9cc286d7565bcd8b34fb5e8 100644 (file)
@@ -182,10 +182,10 @@ class DBStructure
                $status = self::update($verbose, true);
 
                if ($enable_maintenance_mode) {
-                       DI::config()->transactional()
+                       DI::config()->beginTransaction()
                                                ->set('system', 'maintenance', false)
                                                ->delete('system', 'maintenance_reason')
-                                               ->save();
+                                               ->commit();
                }
 
                return $status;
index 50a7ee86866d264314cd76175daba8e7a007182d..39dc9f26dae184692b246772c5c4d7ac5f0389d2 100644 (file)
@@ -144,7 +144,7 @@ class Site extends BaseAdmin
                $relay_user_tags   = !empty($_POST['relay_user_tags']);
                $active_panel      = (!empty($_POST['active_panel'])      ? "#" . trim($_POST['active_panel']) : '');
 
-               $transactionConfig = DI::config()->transactional();
+               $transactionConfig = DI::config()->beginTransaction();
 
                // Has the directory url changed? If yes, then resubmit the existing profiles there
                if ($global_directory != DI::config()->get('system', 'directory') && ($global_directory != '')) {
@@ -320,7 +320,7 @@ class Site extends BaseAdmin
                $transactionConfig->set('system', 'relay_deny_tags'  , $relay_deny_tags);
                $transactionConfig->set('system', 'relay_user_tags'  , $relay_user_tags);
 
-               $transactionConfig->save();
+               $transactionConfig->commit();
 
                DI::baseUrl()->redirect('admin/site' . $active_panel);
        }
index 9d72774c40e29170bd2a0ec4eff4945fe8eccc76..2db6196b7b9fca5ed9ac8582b6a2450cf2bfa8cc 100644 (file)
@@ -369,16 +369,20 @@ class CacheTest extends MockedTest
 
                $configCache->set('system', 'test_2','with_data', Cache::SOURCE_DATA);
                $configCache->set('config', 'test_override','with_another_data', Cache::SOURCE_DATA);
+               $configCache->set('old_category', 'test_45','given category', Cache::SOURCE_DATA);
 
                $newCache = new Cache();
                $newCache->set('config', 'test_override','override it again', Cache::SOURCE_DATA);
                $newCache->set('system', 'test_3','new value', Cache::SOURCE_DATA);
+               $newCache->set('new_category', 'test_23','added category', Cache::SOURCE_DATA);
 
                $mergedCache = $configCache->merge($newCache);
 
                self::assertEquals('with_data', $mergedCache->get('system', 'test_2'));
                self::assertEquals('override it again', $mergedCache->get('config', 'test_override'));
                self::assertEquals('new value', $mergedCache->get('system', 'test_3'));
+               self::assertEquals('given category', $mergedCache->get('old_category', 'test_45'));
+               self::assertEquals('added category', $mergedCache->get('new_category', 'test_23'));
        }
 
        /**
diff --git a/tests/src/Core/Config/ConfigTransactionTest.php b/tests/src/Core/Config/ConfigTransactionTest.php
new file mode 100644 (file)
index 0000000..2eec9b6
--- /dev/null
@@ -0,0 +1,111 @@
+<?php
+
+namespace Friendica\Test\src\Core\Config;
+
+use Friendica\Core\Config\Capability\ISetConfigValuesTransactionally;
+use Friendica\Core\Config\Model\Config;
+use Friendica\Core\Config\Model\ConfigTransaction;
+use Friendica\Core\Config\Util\ConfigFileManager;
+use Friendica\Core\Config\ValueObject\Cache;
+use Friendica\Test\MockedTest;
+use Friendica\Test\Util\VFSTrait;
+
+class ConfigTransactionTest extends MockedTest
+{
+       use VFSTrait;
+
+       /** @var ConfigFileManager */
+       protected $configFileManager;
+
+       protected function setUp(): void
+       {
+               parent::setUp();
+
+               $this->setUpVfsDir();
+
+               $this->configFileManager = new ConfigFileManager($this->root->url(), $this->root->url() . '/config/', $this->root->url() . '/static/');
+       }
+
+       public function dataTests(): array
+       {
+               return [
+                       'default' => [
+                               'data' => include dirname(__FILE__, 4) . '/datasets/B.node.config.php',
+                       ]
+               ];
+       }
+
+       public function testInstance()
+       {
+               $config            = new Config($this->configFileManager, new Cache());
+               $configTransaction = new ConfigTransaction($config);
+
+               self::assertInstanceOf(ISetConfigValuesTransactionally::class, $configTransaction);
+               self::assertInstanceOf(ConfigTransaction::class, $configTransaction);
+       }
+
+       public function testConfigTransaction()
+       {
+               $config = new Config($this->configFileManager, new Cache());
+               $config->set('config', 'key1', 'value1');
+               $config->set('system', 'key2', 'value2');
+               $config->set('system', 'keyDel', 'valueDel');
+               $config->set('delete', 'keyDel', 'catDel');
+
+               $configTransaction = new ConfigTransaction($config);
+               self::assertEquals('value1', $configTransaction->get('config', 'key1'));
+               self::assertEquals('value2', $configTransaction->get('system', 'key2'));
+               self::assertEquals('valueDel', $configTransaction->get('system', 'keyDel'));
+               self::assertEquals('catDel', $configTransaction->get('delete', 'keyDel'));
+               // the config file knows it as well immediately
+               $tempData = include $this->root->url() . '/config/' . ConfigFileManager::CONFIG_DATA_FILE;
+               self::assertEquals('value1', $tempData['config']['key1'] ?? null);
+               self::assertEquals('value2', $tempData['system']['key2'] ?? null);
+
+               // new key-value
+               $configTransaction->set('transaction', 'key3', 'value3');
+               // overwrite key-value
+               $configTransaction->set('config', 'key1', 'changedValue1');
+               // delete key-value
+               $configTransaction->delete('system', 'keyDel');
+               // delete last key of category - so the category is gone
+               $configTransaction->delete('delete', 'keyDel');
+
+               // The main config still doesn't know about the change
+               self::assertNull($config->get('transaction', 'key3'));
+               self::assertEquals('value1', $config->get('config', 'key1'));
+               self::assertEquals('valueDel', $config->get('system', 'keyDel'));
+               self::assertEquals('catDel', $config->get('delete', 'keyDel'));
+               // but the transaction config of course knows it
+               self::assertEquals('value3', $configTransaction->get('transaction', 'key3'));
+               self::assertEquals('changedValue1', $configTransaction->get('config', 'key1'));
+               self::assertNull($configTransaction->get('system', 'keyDel'));
+               self::assertNull($configTransaction->get('delete', 'keyDel'));
+               // The config file still doesn't know it either
+               $tempData = include $this->root->url() . '/config/' . ConfigFileManager::CONFIG_DATA_FILE;
+               self::assertEquals('value1', $tempData['config']['key1'] ?? null);
+               self::assertEquals('value2', $tempData['system']['key2'] ?? null);
+               self::assertEquals('catDel', $tempData['delete']['keyDel'] ?? null);
+               self::assertNull($tempData['transaction']['key3'] ?? null);
+
+               // save it back!
+               $configTransaction->commit();
+
+               // Now every config and file knows the change
+               self::assertEquals('changedValue1', $config->get('config', 'key1'));
+               self::assertEquals('value3', $config->get('transaction', 'key3'));
+               self::assertNull($config->get('system', 'keyDel'));
+               self::assertNull($config->get('delete', 'keyDel'));
+               self::assertEquals('value3', $configTransaction->get('transaction', 'key3'));
+               self::assertEquals('changedValue1', $configTransaction->get('config', 'key1'));
+               self::assertNull($configTransaction->get('system', 'keyDel'));
+               $tempData = include $this->root->url() . '/config/' . ConfigFileManager::CONFIG_DATA_FILE;
+               self::assertEquals('changedValue1', $tempData['config']['key1'] ?? null);
+               self::assertEquals('value2', $tempData['system']['key2'] ?? null);
+               self::assertEquals('value3', $tempData['transaction']['key3'] ?? null);
+               self::assertNull($tempData['system']['keyDel'] ?? null);
+               self::assertNull($tempData['delete']['keyDel'] ?? null);
+               // the whole category should be gone
+               self::assertNull($tempData['delete'] ?? null);
+       }
+}
diff --git a/tests/src/Core/Config/TransactionalConfigTest.php b/tests/src/Core/Config/TransactionalConfigTest.php
deleted file mode 100644 (file)
index e2fdc63..0000000
+++ /dev/null
@@ -1,111 +0,0 @@
-<?php
-
-namespace Friendica\Test\src\Core\Config;
-
-use Friendica\Core\Config\Capability\ISetConfigValuesTransactional;
-use Friendica\Core\Config\Model\Config;
-use Friendica\Core\Config\Model\TransactionalConfig;
-use Friendica\Core\Config\Util\ConfigFileManager;
-use Friendica\Core\Config\ValueObject\Cache;
-use Friendica\Test\MockedTest;
-use Friendica\Test\Util\VFSTrait;
-
-class TransactionalConfigTest extends MockedTest
-{
-       use VFSTrait;
-
-       /** @var ConfigFileManager */
-       protected $configFileManager;
-
-       protected function setUp(): void
-       {
-               parent::setUp();
-
-               $this->setUpVfsDir();
-
-               $this->configFileManager = new ConfigFileManager($this->root->url(), $this->root->url() . '/config/', $this->root->url() . '/static/');
-       }
-
-       public function dataTests(): array
-       {
-               return [
-                       'default' => [
-                               'data' => include dirname(__FILE__, 4) . '/datasets/B.node.config.php',
-                       ]
-               ];
-       }
-
-       public function testInstance()
-       {
-               $config              = new Config($this->configFileManager, new Cache());
-               $transactionalConfig = new TransactionalConfig($config);
-
-               self::assertInstanceOf(ISetConfigValuesTransactional::class, $transactionalConfig);
-               self::assertInstanceOf(TransactionalConfig::class, $transactionalConfig);
-       }
-
-       public function testTransactionalConfig()
-       {
-               $config = new Config($this->configFileManager, new Cache());
-               $config->set('config', 'key1', 'value1');
-               $config->set('system', 'key2', 'value2');
-               $config->set('system', 'keyDel', 'valueDel');
-               $config->set('delete', 'keyDel', 'catDel');
-
-               $transactionalConfig = new TransactionalConfig($config);
-               self::assertEquals('value1', $transactionalConfig->get('config', 'key1'));
-               self::assertEquals('value2', $transactionalConfig->get('system', 'key2'));
-               self::assertEquals('valueDel', $transactionalConfig->get('system', 'keyDel'));
-               self::assertEquals('catDel', $transactionalConfig->get('delete', 'keyDel'));
-               // the config file knows it as well immediately
-               $tempData = include $this->root->url() . '/config/' . ConfigFileManager::CONFIG_DATA_FILE;
-               self::assertEquals('value1', $tempData['config']['key1'] ?? null);
-               self::assertEquals('value2', $tempData['system']['key2'] ?? null);
-
-               // new key-value
-               $transactionalConfig->set('transaction', 'key3', 'value3');
-               // overwrite key-value
-               $transactionalConfig->set('config', 'key1', 'changedValue1');
-               // delete key-value
-               $transactionalConfig->delete('system', 'keyDel');
-               // delete last key of category - so the category is gone
-               $transactionalConfig->delete('delete', 'keyDel');
-
-               // The main config still doesn't know about the change
-               self::assertNull($config->get('transaction', 'key3'));
-               self::assertEquals('value1', $config->get('config', 'key1'));
-               self::assertEquals('valueDel', $config->get('system', 'keyDel'));
-               self::assertEquals('catDel', $config->get('delete', 'keyDel'));
-               // but the transaction config of course knows it
-               self::assertEquals('value3', $transactionalConfig->get('transaction', 'key3'));
-               self::assertEquals('changedValue1', $transactionalConfig->get('config', 'key1'));
-               self::assertNull($transactionalConfig->get('system', 'keyDel'));
-               self::assertNull($transactionalConfig->get('delete', 'keyDel'));
-               // The config file still doesn't know it either
-               $tempData = include $this->root->url() . '/config/' . ConfigFileManager::CONFIG_DATA_FILE;
-               self::assertEquals('value1', $tempData['config']['key1'] ?? null);
-               self::assertEquals('value2', $tempData['system']['key2'] ?? null);
-               self::assertEquals('catDel', $tempData['delete']['keyDel'] ?? null);
-               self::assertNull($tempData['transaction']['key3'] ?? null);
-
-               // save it back!
-               $transactionalConfig->save();
-
-               // Now every config and file knows the change
-               self::assertEquals('changedValue1', $config->get('config', 'key1'));
-               self::assertEquals('value3', $config->get('transaction', 'key3'));
-               self::assertNull($config->get('system', 'keyDel'));
-               self::assertNull($config->get('delete', 'keyDel'));
-               self::assertEquals('value3', $transactionalConfig->get('transaction', 'key3'));
-               self::assertEquals('changedValue1', $transactionalConfig->get('config', 'key1'));
-               self::assertNull($transactionalConfig->get('system', 'keyDel'));
-               $tempData = include $this->root->url() . '/config/' . ConfigFileManager::CONFIG_DATA_FILE;
-               self::assertEquals('changedValue1', $tempData['config']['key1'] ?? null);
-               self::assertEquals('value2', $tempData['system']['key2'] ?? null);
-               self::assertEquals('value3', $tempData['transaction']['key3'] ?? null);
-               self::assertNull($tempData['system']['keyDel'] ?? null);
-               self::assertNull($tempData['delete']['keyDel'] ?? null);
-               // the whole category should be gone
-               self::assertNull($tempData['delete'] ?? null);
-       }
-}
index 7ad6e432feab92a3f50cb00d7afef6828c4ab95b..1dbf78e06f915647cf6300c4886623fe4ca8fdaa 100644 (file)
@@ -1184,13 +1184,13 @@ function update_1508()
 {
        $config = DBA::selectToArray('config');
 
-       $newConfig = DI::config()->transactional();
+       $newConfig = DI::config()->beginTransaction();
 
        foreach ($config as $entry) {
                $newConfig->set($entry['cat'], $entry['k'], $entry['v']);
        }
 
-       $newConfig->save();
+       $newConfig->commit();
 
-       DBA::e("DELETE FROM `config`");
+       DBA::e("TRUNCATE TABLE `config`");
 }
index 8feefdc930f4401140199947057f6f58b350adb2..479793b5962222fa4a9f9e9bf3bd467a1aeef4e1 100644 (file)
@@ -49,7 +49,7 @@ $login_bg_color   = '';
 $modified         = time();
 
 if (DI::mode()->has(\Friendica\App\Mode::MAINTENANCEDISABLED)) {
-       DI::config()->reload('frio');
+       DI::config()->reload();
 
        // Default to hard-coded values for empty settings
        $scheme           = DI::config()->get('frio', 'scheme', DI::config()->get('frio', 'schema'));