Skip to content

Commit 0e94b76

Browse files
committed
merging lazyconfig with appconfig
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
1 parent 7a56c55 commit 0e94b76

14 files changed

Lines changed: 807 additions & 1118 deletions

File tree

core/Command/Config/ListConfigs.php

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
use OC\Core\Command\Base;
2626
use OC\SystemConfig;
2727
use OCP\IAppConfig;
28-
use OCP\ILazyConfig;
2928
use Stecman\Component\Symfony\Console\BashCompletion\CompletionContext;
3029
use Symfony\Component\Console\Input\InputArgument;
3130
use Symfony\Component\Console\Input\InputInterface;
@@ -38,7 +37,6 @@ class ListConfigs extends Base {
3837
public function __construct(
3938
protected SystemConfig $systemConfig,
4039
protected IAppConfig $appConfig,
41-
protected ILazyConfig $lazyConfig,
4240
) {
4341
parent::__construct();
4442
}
@@ -85,20 +83,15 @@ protected function execute(InputInterface $input, OutputInterface $output): int
8583
$configs = [
8684
'system' => $this->getSystemConfigs($noSensitiveValues),
8785
'apps' => [],
88-
'lazy' => [],
8986
];
9087
foreach ($apps as $appName) {
9188
$configs['apps'][$appName] = $this->getAppConfigs($appName, $noSensitiveValues);
9289
}
93-
foreach($this->lazyConfig->getApps() as $appId) {
94-
$configs['lazy'][$appId] = $this->getLazyConfigs($appId, $noSensitiveValues);
95-
}
9690
break;
9791

9892
default:
9993
$configs = [
10094
'apps' => [$app => $this->getAppConfigs($app, $noSensitiveValues)],
101-
'lazy' => [$app => $this->getLazyConfigs($app, $noSensitiveValues)]
10295
];
10396
}
10497

@@ -138,22 +131,15 @@ protected function getSystemConfigs(bool $noSensitiveValues): array {
138131
* @param bool $noSensitiveValues
139132
* @return array
140133
*/
141-
protected function getAppConfigs(string $app, bool $noSensitiveValues): array {
134+
protected function getAppConfigs(string $app, bool $noSensitiveValues) {
135+
// return $this->appConfig->getAllValues($app, filtered: $noSensitiveValues);
142136
if ($noSensitiveValues) {
143137
return $this->appConfig->getFilteredValues($app);
144138
} else {
145139
return $this->appConfig->getValues($app, false);
146140
}
147141
}
148142

149-
protected function getLazyConfigs(string $app, bool $noSensitiveValues): array {
150-
if ($noSensitiveValues) {
151-
return $this->lazyConfig->getFilteredValues($app);
152-
} else {
153-
return $this->lazyConfig->getValues($app);
154-
}
155-
}
156-
157143
/**
158144
* @param string $argumentName
159145
* @param CompletionContext $context

core/Command/Upgrade.php

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
use OC\Updater;
4747
use OCP\EventDispatcher\Event;
4848
use OCP\EventDispatcher\IEventDispatcher;
49+
use OCP\IAppConfig;
4950
use OCP\IConfig;
5051
use OCP\Util;
5152
use Psr\Log\LoggerInterface;
@@ -63,9 +64,7 @@ class Upgrade extends Command {
6364
public const ERROR_FAILURE = 5;
6465

6566
public function __construct(
66-
private IConfig $config,
67-
private LoggerInterface $logger,
68-
private Installer $installer,
67+
private IConfig $config
6968
) {
7069
parent::__construct();
7170
}
@@ -91,12 +90,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
9190
}
9291

9392
$self = $this;
94-
$updater = new Updater(
95-
$this->config,
96-
\OC::$server->getIntegrityCodeChecker(),
97-
$this->logger,
98-
$this->installer
99-
);
93+
$updater = \OCP\Server::get(Updater::class);
10094

10195
/** @var IEventDispatcher $dispatcher */
10296
$dispatcher = \OC::$server->get(IEventDispatcher::class);

core/Migrations/Version29000Date20231126110901.php

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,30 +31,31 @@
3131
use OCP\Migration\IOutput;
3232
use OCP\Migration\SimpleMigrationStep;
3333

34-
// Create new tables for the ILazyConfig API (lazyconfig).
34+
// Create new field in appconfig for the new IAppConfig API, including lazy grouping.
3535
class Version29000Date20231126110901 extends SimpleMigrationStep {
3636
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
3737
/** @var ISchemaWrapper $schema */
3838
$schema = $schemaClosure();
39-
$updated = false;
40-
41-
if (!$schema->hasTable('appconfig_lazy')) {
42-
$table = $schema->createTable('appconfig_lazy');
43-
$table->addColumn('app_id', Types::STRING, ['length' => 32]);
44-
$table->addColumn('extra', Types::STRING, ['length' => 32]);
45-
$table->addColumn('config_key', Types::STRING, ['length' => 64]);
46-
$table->addColumn('config_value', Types::TEXT);
47-
48-
$table->setPrimaryKey(['app_id', 'config_key'], 'lazy_app_prim');
49-
$table->addIndex(['app_id', 'extra'], 'lazy_app_id_i');
50-
$table->addIndex(['app_id', 'extra', 'config_key'], 'lazy_app_id_key_i');
51-
$updated = true;
39+
40+
if (!$schema->hasTable('appconfig')) {
41+
return null;
5242
}
5343

54-
if (!$updated) {
44+
$table = $schema->getTable('appconfig');
45+
if ($table->hasColumn('lazy_group')) {
5546
return null;
5647
}
5748

49+
$table->addColumn('lazy_group', Types::STRING, ['length' => 32, 'default' => '']);
50+
$table->addColumn('sensitive', Types::SMALLINT, ['length' => 1, 'default' => '0']);
51+
52+
if ($table->hasIndex('appconfig_config_key_index')) {
53+
$table->dropIndex('appconfig_config_key_index');
54+
}
55+
56+
$table->addIndex(['appid', 'lazy_group'], 'ac_app_lazy_i');
57+
$table->addIndex(['appid', 'lazy_group', 'config_key'], 'ac_app_lazy_key_i');
58+
5859
return $schema;
5960
}
6061
}

core/ajax/update.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,14 @@
4040
use OC\Repair\Events\RepairWarningEvent;
4141
use OCP\EventDispatcher\Event;
4242
use OCP\EventDispatcher\IEventDispatcher;
43+
use OCP\IAppConfig;
44+
use OCP\IConfig;
4345
use OCP\IEventSource;
4446
use OCP\IEventSourceFactory;
4547
use OCP\IL10N;
4648
use OCP\ILogger;
4749
use OCP\L10N\IFactory;
50+
use OCP\Server;
4851

4952
if (!str_contains(@ini_get('disable_functions'), 'set_time_limit')) {
5053
@set_time_limit(0);
@@ -112,9 +115,10 @@ public function handleRepairFeedback(Event $event): void {
112115
\OC_User::setIncognitoMode(true);
113116

114117
$logger = \OC::$server->get(\Psr\Log\LoggerInterface::class);
115-
$config = \OC::$server->getConfig();
118+
$config = Server::get(IConfig::class);
116119
$updater = new \OC\Updater(
117120
$config,
121+
Server::get(IAppConfig::class),
118122
\OC::$server->getIntegrityCodeChecker(),
119123
$logger,
120124
\OC::$server->query(\OC\Installer::class)

lib/private/AllConfig.php

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,13 @@
3636
use OCP\DB\QueryBuilder\IQueryBuilder;
3737
use OCP\IConfig;
3838
use OCP\IDBConnection;
39-
use OCP\ILazyConfig;
4039
use OCP\PreConditionNotMetException;
4140

4241
/**
4342
* Class to combine all the configuration options ownCloud offers
4443
*/
4544
class AllConfig implements IConfig {
4645
private ?IDBConnection $connection = null;
47-
private ?ILazyConfig $lazyConfig = null;
4846

4947
/**
5048
* 3 dimensional array with the following structure:
@@ -548,38 +546,4 @@ public function getUsersForUserValueCaseInsensitive($appName, $key, $value) {
548546
public function getSystemConfig() {
549547
return $this->systemConfig;
550548
}
551-
552-
public function getLazyConfig(): ILazyConfig {
553-
if ($this->lazyConfig === null) {
554-
$this->lazyConfig = \OCP\Server::get(ILazyConfig::class);
555-
}
556-
557-
return $this->lazyConfig;
558-
}
559-
560-
/**
561-
* export AppConfig keys/values into LazyConfig
562-
*
563-
* $this->config->exportToLazy('my_app', [
564-
* 'first-config' => 'default_value',
565-
* 'my-other-config' => 12,
566-
* 'boolean-flag' => '0'
567-
* ]);
568-
*
569-
* @param string $app
570-
* @param array $configKeys an array with keys to export as index, default as value
571-
* @since 29.0.0
572-
*/
573-
public function exportToLazy(string $app, array $configKeys): void {
574-
foreach ($configKeys as $key => $default) {
575-
$value = $this->getAppValue($app, $key, (string)$default);
576-
if ($this->getLazyConfig()->hasKey($app, $key)
577-
|| $default === $value) {
578-
continue;
579-
}
580-
581-
$this->getLazyConfig()->setValueString($app, $key, $value);
582-
$this->deleteAppValue($app, $key);
583-
}
584-
}
585549
}

0 commit comments

Comments
 (0)