mirror of
https://github.com/nextcloud/server.git
synced 2026-05-28 04:32:30 -04:00
feat(lexicon): using configmanager
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
This commit is contained in:
parent
e39ab65239
commit
d5e487078a
3 changed files with 14 additions and 15 deletions
|
|
@ -15,6 +15,7 @@ use NCU\Config\Lexicon\ConfigLexiconEntry;
|
|||
use NCU\Config\Lexicon\ConfigLexiconStrictness;
|
||||
use NCU\Config\Lexicon\IConfigLexicon;
|
||||
use OC\AppFramework\Bootstrap\Coordinator;
|
||||
use OC\Config\ConfigManager;
|
||||
use OCP\DB\Exception as DBException;
|
||||
use OCP\DB\QueryBuilder\IQueryBuilder;
|
||||
use OCP\Exceptions\AppConfigIncorrectTypeException;
|
||||
|
|
@ -24,6 +25,7 @@ use OCP\IAppConfig;
|
|||
use OCP\IConfig;
|
||||
use OCP\IDBConnection;
|
||||
use OCP\Security\ICrypto;
|
||||
use OCP\Server;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
/**
|
||||
|
|
@ -59,7 +61,7 @@ class AppConfig implements IAppConfig {
|
|||
private array $valueTypes = []; // type for all config values
|
||||
private bool $fastLoaded = false;
|
||||
private bool $lazyLoaded = false;
|
||||
/** @var array<array-key, array{entries: array<array-key, ConfigLexiconEntry>, aliases: array<array-key, string>, strictness: ConfigLexiconStrictness}> ['app_id' => ['strictness' => ConfigLexiconStrictness, 'entries' => ['config_key' => ConfigLexiconEntry[]]] */
|
||||
/** @var array<string, array{entries: array<string, ConfigLexiconEntry>, aliases: array<string, string>, strictness: ConfigLexiconStrictness}> ['app_id' => ['strictness' => ConfigLexiconStrictness, 'entries' => ['config_key' => ConfigLexiconEntry[]]] */
|
||||
private array $configLexiconDetails = [];
|
||||
private bool $ignoreLexiconAliases = false;
|
||||
|
||||
|
|
@ -478,11 +480,9 @@ class AppConfig implements IAppConfig {
|
|||
|
||||
// in case the key was modified while running matchAndApplyLexiconDefinition() we are
|
||||
// interested to check options in case a modification of the value is needed
|
||||
if ($origKey !== $key) {
|
||||
$lexiconEntry = $this->getLexiconEntry($app, $key);
|
||||
if ($type === self::VALUE_BOOL && $lexiconEntry?->hasOption(ConfigLexiconEntry::RENAME_INVERT_BOOLEAN)) {
|
||||
$value = (in_array(strtolower($value), ['1', 'true', 'yes', 'on'])) ? '0' : '1';
|
||||
}
|
||||
if ($origKey !== $key && $type === self::VALUE_BOOL) {
|
||||
$configManager = Server::get(ConfigManager::class);
|
||||
$value = ($configManager->convertToBool($value, $this->getLexiconEntry($app, $key))) ? '1' : '0';
|
||||
}
|
||||
|
||||
return $value;
|
||||
|
|
@ -1677,7 +1677,7 @@ class AppConfig implements IAppConfig {
|
|||
* @param string $appId
|
||||
* @internal
|
||||
*
|
||||
* @return array{entries: array<array-key, ConfigLexiconEntry>, aliases: array<array-key, string>, strictness: ConfigLexiconStrictness}
|
||||
* @return array{entries: array<string, ConfigLexiconEntry>, aliases: array<string, string>, strictness: ConfigLexiconStrictness}
|
||||
*/
|
||||
public function getConfigDetailsFromLexicon(string $appId): array {
|
||||
if (!array_key_exists($appId, $this->configLexiconDetails)) {
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ use OCP\DB\QueryBuilder\IQueryBuilder;
|
|||
use OCP\IConfig;
|
||||
use OCP\IDBConnection;
|
||||
use OCP\Security\ICrypto;
|
||||
use OCP\Server;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
/**
|
||||
|
|
@ -62,7 +63,7 @@ class UserConfig implements IUserConfig {
|
|||
private array $fastLoaded = [];
|
||||
/** @var array<string, boolean> ['user_id' => bool] */
|
||||
private array $lazyLoaded = [];
|
||||
/** @var array<array-key, array{entries: array<array-key, ConfigLexiconEntry>, aliases: array<array-key, string>, strictness: ConfigLexiconStrictness}> ['app_id' => ['strictness' => ConfigLexiconStrictness, 'entries' => ['config_key' => ConfigLexiconEntry[]]] */
|
||||
/** @var array<string, array{entries: array<string, ConfigLexiconEntry>, aliases: array<string, string>, strictness: ConfigLexiconStrictness}> ['app_id' => ['strictness' => ConfigLexiconStrictness, 'entries' => ['config_key' => ConfigLexiconEntry[]]] */
|
||||
private array $configLexiconDetails = [];
|
||||
private bool $ignoreLexiconAliases = false;
|
||||
|
||||
|
|
@ -759,11 +760,9 @@ class UserConfig implements IUserConfig {
|
|||
|
||||
// in case the key was modified while running matchAndApplyLexiconDefinition() we are
|
||||
// interested to check options in case a modification of the value is needed
|
||||
if ($origKey !== $key) {
|
||||
$lexiconEntry = $this->getLexiconEntry($app, $key);
|
||||
if ($type === ValueType::BOOL && $lexiconEntry?->hasOption(ConfigLexiconEntry::RENAME_INVERT_BOOLEAN)) {
|
||||
$value = (in_array(strtolower($value), ['1', 'true', 'yes', 'on'])) ? '0' : '1';
|
||||
}
|
||||
if ($origKey !== $key && $type === ValueType::BOOL) {
|
||||
$configManager = Server::get(ConfigManager::class);
|
||||
$value = ($configManager->convertToBool($value, $this->getLexiconEntry($app, $key))) ? '1' : '0';
|
||||
}
|
||||
|
||||
return $value;
|
||||
|
|
@ -1989,7 +1988,7 @@ class UserConfig implements IUserConfig {
|
|||
* @param string $appId
|
||||
* @internal
|
||||
*
|
||||
* @return array{entries: array<array-key, ConfigLexiconEntry>, aliases: array<array-key, string>, strictness: ConfigLexiconStrictness}
|
||||
* @return array{entries: array<string, ConfigLexiconEntry>, aliases: array<string, string>, strictness: ConfigLexiconStrictness}
|
||||
*/
|
||||
public function getConfigDetailsFromLexicon(string $appId): array {
|
||||
if (!array_key_exists($appId, $this->configLexiconDetails)) {
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ class ConfigKeyMigration implements IRepairStep {
|
|||
}
|
||||
|
||||
public function getName(): string {
|
||||
return 'Initiate config keys migration';
|
||||
return 'Migrate config keys';
|
||||
}
|
||||
|
||||
public function run(IOutput $output) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue