Skip to content

Commit d161e07

Browse files
Merge pull request #52832 from nextcloud/feat/noid/lexicon-migrate-keys
feat(lexicon): migrate config key/value
2 parents abced23 + d860cfd commit d161e07

File tree

23 files changed

+605
-126
lines changed

23 files changed

+605
-126
lines changed

core/Command/Config/App/Base.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@
77
*/
88
namespace OC\Core\Command\Config\App;
99

10+
use OC\Config\ConfigManager;
1011
use OCP\IAppConfig;
1112
use Stecman\Component\Symfony\Console\BashCompletion\CompletionContext;
1213

1314
abstract class Base extends \OC\Core\Command\Base {
1415
public function __construct(
1516
protected IAppConfig $appConfig,
17+
protected readonly ConfigManager $configManager,
1618
) {
1719
parent::__construct();
1820
}

core/Command/Config/App/SetConfig.php

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
namespace OC\Core\Command\Config\App;
1010

1111
use OC\AppConfig;
12-
use OCP\Exceptions\AppConfigIncorrectTypeException;
1312
use OCP\Exceptions\AppConfigUnknownKeyException;
1413
use OCP\IAppConfig;
1514
use Symfony\Component\Console\Helper\QuestionHelper;
@@ -161,7 +160,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int
161160
}
162161

163162
$value = (string)$input->getOption('value');
164-
165163
switch ($type) {
166164
case IAppConfig::VALUE_MIXED:
167165
$updated = $this->appConfig->setValueMixed($appName, $configName, $value, $lazy, $sensitive);
@@ -172,34 +170,19 @@ protected function execute(InputInterface $input, OutputInterface $output): int
172170
break;
173171

174172
case IAppConfig::VALUE_INT:
175-
if ($value !== ((string)((int)$value))) {
176-
throw new AppConfigIncorrectTypeException('Value is not an integer');
177-
}
178-
$updated = $this->appConfig->setValueInt($appName, $configName, (int)$value, $lazy, $sensitive);
173+
$updated = $this->appConfig->setValueInt($appName, $configName, $this->configManager->convertToInt($value), $lazy, $sensitive);
179174
break;
180175

181176
case IAppConfig::VALUE_FLOAT:
182-
if ($value !== ((string)((float)$value))) {
183-
throw new AppConfigIncorrectTypeException('Value is not a float');
184-
}
185-
$updated = $this->appConfig->setValueFloat($appName, $configName, (float)$value, $lazy, $sensitive);
177+
$updated = $this->appConfig->setValueFloat($appName, $configName, $this->configManager->convertToFloat($value), $lazy, $sensitive);
186178
break;
187179

188180
case IAppConfig::VALUE_BOOL:
189-
if (in_array(strtolower($value), ['true', '1', 'on', 'yes'])) {
190-
$valueBool = true;
191-
} elseif (in_array(strtolower($value), ['false', '0', 'off', 'no'])) {
192-
$valueBool = false;
193-
} else {
194-
throw new AppConfigIncorrectTypeException('Value is not a boolean, please use \'true\' or \'false\'');
195-
}
196-
$updated = $this->appConfig->setValueBool($appName, $configName, $valueBool, $lazy);
181+
$updated = $this->appConfig->setValueBool($appName, $configName, $this->configManager->convertToBool($value), $lazy);
197182
break;
198183

199184
case IAppConfig::VALUE_ARRAY:
200-
$valueArray = json_decode($value, true, flags: JSON_THROW_ON_ERROR);
201-
$valueArray = (is_array($valueArray)) ? $valueArray : throw new AppConfigIncorrectTypeException('Value is not an array');
202-
$updated = $this->appConfig->setValueArray($appName, $configName, $valueArray, $lazy, $sensitive);
185+
$updated = $this->appConfig->setValueArray($appName, $configName, $this->configManager->convertToArray($value), $lazy, $sensitive);
203186
break;
204187
}
205188
}

core/Command/Config/ListConfigs.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*/
88
namespace OC\Core\Command\Config;
99

10+
use OC\Config\ConfigManager;
1011
use OC\Core\Command\Base;
1112
use OC\SystemConfig;
1213
use OCP\IAppConfig;
@@ -22,6 +23,7 @@ class ListConfigs extends Base {
2223
public function __construct(
2324
protected SystemConfig $systemConfig,
2425
protected IAppConfig $appConfig,
26+
protected ConfigManager $configManager,
2527
) {
2628
parent::__construct();
2729
}
@@ -44,13 +46,18 @@ protected function configure() {
4446
InputOption::VALUE_NONE,
4547
'Use this option when you want to include sensitive configs like passwords, salts, ...'
4648
)
49+
->addOption('migrate', null, InputOption::VALUE_NONE, 'Rename config keys of all enabled apps, based on ConfigLexicon')
4750
;
4851
}
4952

5053
protected function execute(InputInterface $input, OutputInterface $output): int {
5154
$app = $input->getArgument('app');
5255
$noSensitiveValues = !$input->getOption('private');
5356

57+
if ($input->getOption('migrate')) {
58+
$this->configManager->migrateConfigLexiconKeys(($app === 'all') ? null : $app);
59+
}
60+
5461
if (!is_string($app)) {
5562
$output->writeln('<error>Invalid app value given</error>');
5663
return 1;

lib/composer/composer/autoload_classmap.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1190,6 +1190,7 @@
11901190
'OC\\Comments\\Manager' => $baseDir . '/lib/private/Comments/Manager.php',
11911191
'OC\\Comments\\ManagerFactory' => $baseDir . '/lib/private/Comments/ManagerFactory.php',
11921192
'OC\\Config' => $baseDir . '/lib/private/Config.php',
1193+
'OC\\Config\\ConfigManager' => $baseDir . '/lib/private/Config/ConfigManager.php',
11931194
'OC\\Config\\Lexicon\\CoreConfigLexicon' => $baseDir . '/lib/private/Config/Lexicon/CoreConfigLexicon.php',
11941195
'OC\\Config\\UserConfig' => $baseDir . '/lib/private/Config/UserConfig.php',
11951196
'OC\\Console\\Application' => $baseDir . '/lib/private/Console/Application.php',
@@ -1901,6 +1902,7 @@
19011902
'OC\\Repair\\ClearGeneratedAvatarCache' => $baseDir . '/lib/private/Repair/ClearGeneratedAvatarCache.php',
19021903
'OC\\Repair\\ClearGeneratedAvatarCacheJob' => $baseDir . '/lib/private/Repair/ClearGeneratedAvatarCacheJob.php',
19031904
'OC\\Repair\\Collation' => $baseDir . '/lib/private/Repair/Collation.php',
1905+
'OC\\Repair\\ConfigKeyMigration' => $baseDir . '/lib/private/Repair/ConfigKeyMigration.php',
19041906
'OC\\Repair\\Events\\RepairAdvanceEvent' => $baseDir . '/lib/private/Repair/Events/RepairAdvanceEvent.php',
19051907
'OC\\Repair\\Events\\RepairErrorEvent' => $baseDir . '/lib/private/Repair/Events/RepairErrorEvent.php',
19061908
'OC\\Repair\\Events\\RepairFinishEvent' => $baseDir . '/lib/private/Repair/Events/RepairFinishEvent.php',

lib/composer/composer/autoload_static.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1231,6 +1231,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
12311231
'OC\\Comments\\Manager' => __DIR__ . '/../../..' . '/lib/private/Comments/Manager.php',
12321232
'OC\\Comments\\ManagerFactory' => __DIR__ . '/../../..' . '/lib/private/Comments/ManagerFactory.php',
12331233
'OC\\Config' => __DIR__ . '/../../..' . '/lib/private/Config.php',
1234+
'OC\\Config\\ConfigManager' => __DIR__ . '/../../..' . '/lib/private/Config/ConfigManager.php',
12341235
'OC\\Config\\Lexicon\\CoreConfigLexicon' => __DIR__ . '/../../..' . '/lib/private/Config/Lexicon/CoreConfigLexicon.php',
12351236
'OC\\Config\\UserConfig' => __DIR__ . '/../../..' . '/lib/private/Config/UserConfig.php',
12361237
'OC\\Console\\Application' => __DIR__ . '/../../..' . '/lib/private/Console/Application.php',
@@ -1942,6 +1943,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
19421943
'OC\\Repair\\ClearGeneratedAvatarCache' => __DIR__ . '/../../..' . '/lib/private/Repair/ClearGeneratedAvatarCache.php',
19431944
'OC\\Repair\\ClearGeneratedAvatarCacheJob' => __DIR__ . '/../../..' . '/lib/private/Repair/ClearGeneratedAvatarCacheJob.php',
19441945
'OC\\Repair\\Collation' => __DIR__ . '/../../..' . '/lib/private/Repair/Collation.php',
1946+
'OC\\Repair\\ConfigKeyMigration' => __DIR__ . '/../../..' . '/lib/private/Repair/ConfigKeyMigration.php',
19451947
'OC\\Repair\\Events\\RepairAdvanceEvent' => __DIR__ . '/../../..' . '/lib/private/Repair/Events/RepairAdvanceEvent.php',
19461948
'OC\\Repair\\Events\\RepairErrorEvent' => __DIR__ . '/../../..' . '/lib/private/Repair/Events/RepairErrorEvent.php',
19471949
'OC\\Repair\\Events\\RepairFinishEvent' => __DIR__ . '/../../..' . '/lib/private/Repair/Events/RepairFinishEvent.php',

lib/private/App/AppManager.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
use OC\AppConfig;
1010
use OC\AppFramework\Bootstrap\Coordinator;
11+
use OC\Config\ConfigManager;
1112
use OCP\Activity\IManager as IActivityManager;
1213
use OCP\App\AppPathNotFoundException;
1314
use OCP\App\Events\AppDisableEvent;
@@ -27,6 +28,7 @@
2728
use OCP\IURLGenerator;
2829
use OCP\IUser;
2930
use OCP\IUserSession;
31+
use OCP\Server;
3032
use OCP\ServerVersion;
3133
use OCP\Settings\IManager as ISettingsManager;
3234
use Psr\Log\LoggerInterface;
@@ -82,12 +84,13 @@ public function __construct(
8284
private IEventDispatcher $dispatcher,
8385
private LoggerInterface $logger,
8486
private ServerVersion $serverVersion,
87+
private ConfigManager $configManager,
8588
) {
8689
}
8790

8891
private function getNavigationManager(): INavigationManager {
8992
if ($this->navigationManager === null) {
90-
$this->navigationManager = \OCP\Server::get(INavigationManager::class);
93+
$this->navigationManager = Server::get(INavigationManager::class);
9194
}
9295
return $this->navigationManager;
9396
}
@@ -113,7 +116,7 @@ private function getAppConfig(): AppConfig {
113116
if (!$this->config->getSystemValueBool('installed', false)) {
114117
throw new \Exception('Nextcloud is not installed yet, AppConfig is not available');
115118
}
116-
$this->appConfig = \OCP\Server::get(AppConfig::class);
119+
$this->appConfig = Server::get(AppConfig::class);
117120
return $this->appConfig;
118121
}
119122

@@ -124,7 +127,7 @@ private function getUrlGenerator(): IURLGenerator {
124127
if (!$this->config->getSystemValueBool('installed', false)) {
125128
throw new \Exception('Nextcloud is not installed yet, AppConfig is not available');
126129
}
127-
$this->urlGenerator = \OCP\Server::get(IURLGenerator::class);
130+
$this->urlGenerator = Server::get(IURLGenerator::class);
128131
return $this->urlGenerator;
129132
}
130133

@@ -459,7 +462,7 @@ public function loadApp(string $app): void {
459462
]);
460463
}
461464

462-
$coordinator = \OCP\Server::get(Coordinator::class);
465+
$coordinator = Server::get(Coordinator::class);
463466
$coordinator->bootApp($app);
464467

465468
$eventLogger->start("bootstrap:load_app:$app:info", "Load info.xml for $app and register any services defined in it");
@@ -568,6 +571,8 @@ public function enableApp(string $appId, bool $forceEnable = false): void {
568571
ManagerEvent::EVENT_APP_ENABLE, $appId
569572
));
570573
$this->clearAppsCache();
574+
575+
$this->configManager->migrateConfigLexiconKeys($appId);
571576
}
572577

573578
/**
@@ -626,6 +631,8 @@ public function enableAppForGroups(string $appId, array $groups, bool $forceEnab
626631
ManagerEvent::EVENT_APP_ENABLE_FOR_GROUPS, $appId, $groups
627632
));
628633
$this->clearAppsCache();
634+
635+
$this->configManager->migrateConfigLexiconKeys($appId);
629636
}
630637

631638
/**

0 commit comments

Comments
 (0)