aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private/Config
diff options
context:
space:
mode:
Diffstat (limited to 'lib/private/Config')
-rw-r--r--lib/private/Config/ConfigManager.php24
-rw-r--r--lib/private/Config/PresetManager.php48
-rw-r--r--lib/private/Config/UserConfig.php19
3 files changed, 59 insertions, 32 deletions
diff --git a/lib/private/Config/ConfigManager.php b/lib/private/Config/ConfigManager.php
index ed516abdcbf..28397402249 100644
--- a/lib/private/Config/ConfigManager.php
+++ b/lib/private/Config/ConfigManager.php
@@ -14,10 +14,8 @@ use OCP\App\IAppManager;
use OCP\Config\Exceptions\TypeConflictException;
use OCP\Config\IUserConfig;
use OCP\Config\Lexicon\Entry;
-use OCP\Config\Lexicon\Preset;
use OCP\Config\ValueType;
use OCP\IAppConfig;
-use OCP\IConfig;
use OCP\Server;
use Psr\Log\LoggerInterface;
@@ -27,20 +25,23 @@ use Psr\Log\LoggerInterface;
* @since 32.0.0
*/
class ConfigManager {
- /** @since 32.0.0 */
- public const PRESET_CONFIGKEY = 'config_preset';
-
/** @var AppConfig|null $appConfig */
private ?IAppConfig $appConfig = null;
/** @var UserConfig|null $userConfig */
private ?IUserConfig $userConfig = null;
public function __construct(
- private readonly IConfig $config,
private readonly LoggerInterface $logger,
) {
}
+ public function clearConfigCaches(): void {
+ $this->loadConfigServices();
+ $this->appConfig->clearCache();
+ $this->userConfig->clearCacheAll();
+ }
+
+
/**
* Use the rename values from the list of ConfigLexiconEntry defined in each app ConfigLexicon
* to migrate config value to a new config key.
@@ -82,17 +83,6 @@ class ConfigManager {
}
/**
- * store in config.php the new preset
- * refresh cached preset
- */
- public function setLexiconPreset(Preset $preset): void {
- $this->config->setSystemValue(self::PRESET_CONFIGKEY, $preset->value);
- $this->loadConfigServices();
- $this->appConfig->clearCache();
- $this->userConfig->clearCacheAll();
- }
-
- /**
* config services cannot be load at __construct() or install will fail
*/
private function loadConfigServices(): void {
diff --git a/lib/private/Config/PresetManager.php b/lib/private/Config/PresetManager.php
new file mode 100644
index 00000000000..d9c029d15c2
--- /dev/null
+++ b/lib/private/Config/PresetManager.php
@@ -0,0 +1,48 @@
+<?php
+
+declare(strict_types=1);
+/**
+ * SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+
+namespace OC\Config;
+
+use OCP\Config\Lexicon\Preset;
+use OCP\IConfig;
+
+/**
+ * tools to maintains configurations
+ */
+class PresetManager {
+ private const PRESET_CONFIGKEY = 'config_preset';
+
+ private ?Preset $configLexiconPreset = null;
+
+ public function __construct(
+ private readonly IConfig $config,
+ private readonly ConfigManager $configManager,
+ ) {
+ }
+
+ /**
+ * store in config.php the new preset
+ * refresh cached preset
+ */
+ public function setLexiconPreset(Preset $preset): void {
+ $this->config->setSystemValue(self::PRESET_CONFIGKEY, $preset->value);
+ $this->configLexiconPreset = $preset;
+ $this->configManager->clearConfigCaches();
+ }
+
+ /**
+ * returns currently selected Preset
+ */
+ public function getLexiconPreset(): Preset {
+ if ($this->configLexiconPreset === null) {
+ $this->configLexiconPreset = Preset::tryFrom($this->config->getSystemValueInt(self::PRESET_CONFIGKEY, 0)) ?? Preset::NONE;
+ }
+
+ return $this->configLexiconPreset;
+ }
+}
diff --git a/lib/private/Config/UserConfig.php b/lib/private/Config/UserConfig.php
index 04ba0e29db0..4ddad3ec2f2 100644
--- a/lib/private/Config/UserConfig.php
+++ b/lib/private/Config/UserConfig.php
@@ -18,7 +18,6 @@ use OCP\Config\Exceptions\UnknownKeyException;
use OCP\Config\IUserConfig;
use OCP\Config\Lexicon\Entry;
use OCP\Config\Lexicon\ILexicon;
-use OCP\Config\Lexicon\Preset;
use OCP\Config\Lexicon\Strictness;
use OCP\Config\ValueType;
use OCP\DB\Exception as DBException;
@@ -27,7 +26,6 @@ use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IConfig;
use OCP\IDBConnection;
use OCP\Security\ICrypto;
-use OCP\Server;
use Psr\Log\LoggerInterface;
/**
@@ -68,11 +66,12 @@ class UserConfig implements IUserConfig {
/** @var array<string, array{entries: array<string, Entry>, aliases: array<string, string>, strictness: Strictness}> ['app_id' => ['strictness' => ConfigLexiconStrictness, 'entries' => ['config_key' => ConfigLexiconEntry[]]] */
private array $configLexiconDetails = [];
private bool $ignoreLexiconAliases = false;
- private ?Preset $configLexiconPreset = null;
public function __construct(
protected IDBConnection $connection,
protected IConfig $config,
+ private readonly ConfigManager $configManager,
+ private readonly PresetManager $presetManager,
protected LoggerInterface $logger,
protected ICrypto $crypto,
) {
@@ -772,8 +771,7 @@ class UserConfig implements IUserConfig {
// interested to check options in case a modification of the value is needed
// ie inverting value from previous key when using lexicon option RENAME_INVERT_BOOLEAN
if ($origKey !== $key && $type === ValueType::BOOL) {
- $configManager = Server::get(ConfigManager::class);
- $value = ($configManager->convertToBool($value, $this->getLexiconEntry($app, $key))) ? '1' : '0';
+ $value = ($this->configManager->convertToBool($value, $this->getLexiconEntry($app, $key))) ? '1' : '0';
}
return $value;
@@ -1636,7 +1634,6 @@ class UserConfig implements IUserConfig {
public function clearCacheAll(): void {
$this->lazyLoaded = $this->fastLoaded = [];
$this->lazyCache = $this->fastCache = $this->valueDetails = $this->configLexiconDetails = [];
- $this->configLexiconPreset = null;
}
/**
@@ -1937,7 +1934,7 @@ class UserConfig implements IUserConfig {
// only look for default if needed, default from Lexicon got priority if not overwritten by admin
if ($default !== null) {
- $default = $this->getSystemDefault($app, $configValue) ?? $configValue->getDefault($this->getLexiconPreset()) ?? $default;
+ $default = $this->getSystemDefault($app, $configValue) ?? $configValue->getDefault($this->presetManager->getLexiconPreset()) ?? $default;
}
// returning false will make get() returning $default and set() not changing value in database
@@ -2039,12 +2036,4 @@ class UserConfig implements IUserConfig {
public function ignoreLexiconAliases(bool $ignore): void {
$this->ignoreLexiconAliases = $ignore;
}
-
- private function getLexiconPreset(): Preset {
- if ($this->configLexiconPreset === null) {
- $this->configLexiconPreset = Preset::tryFrom($this->config->getSystemValueInt(ConfigManager::PRESET_CONFIGKEY, 0)) ?? Preset::NONE;
- }
-
- return $this->configLexiconPreset;
- }
}