Skip to content

Commit

Permalink
merging lazyconfig with appconfig
Browse files Browse the repository at this point in the history
Signed-off-by: Maxence Lange <[email protected]>
  • Loading branch information
ArtificialOwl committed Nov 29, 2023
1 parent 7a56c55 commit 0e94b76
Show file tree
Hide file tree
Showing 14 changed files with 807 additions and 1,118 deletions.
18 changes: 2 additions & 16 deletions core/Command/Config/ListConfigs.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
use OC\Core\Command\Base;
use OC\SystemConfig;
use OCP\IAppConfig;
use OCP\ILazyConfig;
use Stecman\Component\Symfony\Console\BashCompletion\CompletionContext;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
Expand All @@ -38,7 +37,6 @@ class ListConfigs extends Base {
public function __construct(
protected SystemConfig $systemConfig,
protected IAppConfig $appConfig,
protected ILazyConfig $lazyConfig,
) {
parent::__construct();
}
Expand Down Expand Up @@ -85,20 +83,15 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$configs = [
'system' => $this->getSystemConfigs($noSensitiveValues),
'apps' => [],
'lazy' => [],
];
foreach ($apps as $appName) {
$configs['apps'][$appName] = $this->getAppConfigs($appName, $noSensitiveValues);
}
foreach($this->lazyConfig->getApps() as $appId) {
$configs['lazy'][$appId] = $this->getLazyConfigs($appId, $noSensitiveValues);
}
break;

default:
$configs = [
'apps' => [$app => $this->getAppConfigs($app, $noSensitiveValues)],
'lazy' => [$app => $this->getLazyConfigs($app, $noSensitiveValues)]
];
}

Expand Down Expand Up @@ -138,22 +131,15 @@ protected function getSystemConfigs(bool $noSensitiveValues): array {
* @param bool $noSensitiveValues
* @return array
*/
protected function getAppConfigs(string $app, bool $noSensitiveValues): array {
protected function getAppConfigs(string $app, bool $noSensitiveValues) {
// return $this->appConfig->getAllValues($app, filtered: $noSensitiveValues);
if ($noSensitiveValues) {
return $this->appConfig->getFilteredValues($app);

Check notice

Code scanning / Psalm

DeprecatedMethod Note

The method OCP\IAppConfig::getFilteredValues has been marked as deprecated
} else {
return $this->appConfig->getValues($app, false);
}
}

protected function getLazyConfigs(string $app, bool $noSensitiveValues): array {
if ($noSensitiveValues) {
return $this->lazyConfig->getFilteredValues($app);
} else {
return $this->lazyConfig->getValues($app);
}
}

/**
* @param string $argumentName
* @param CompletionContext $context
Expand Down
12 changes: 3 additions & 9 deletions core/Command/Upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
use OC\Updater;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\IAppConfig;
use OCP\IConfig;
use OCP\Util;
use Psr\Log\LoggerInterface;
Expand All @@ -63,9 +64,7 @@ class Upgrade extends Command {
public const ERROR_FAILURE = 5;

public function __construct(
private IConfig $config,
private LoggerInterface $logger,
private Installer $installer,
private IConfig $config
) {
parent::__construct();
}
Expand All @@ -91,12 +90,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
}

$self = $this;
$updater = new Updater(
$this->config,
\OC::$server->getIntegrityCodeChecker(),
$this->logger,
$this->installer
);
$updater = \OCP\Server::get(Updater::class);

/** @var IEventDispatcher $dispatcher */
$dispatcher = \OC::$server->get(IEventDispatcher::class);
Expand Down
31 changes: 16 additions & 15 deletions core/Migrations/Version29000Date20231126110901.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,30 +31,31 @@
use OCP\Migration\IOutput;
use OCP\Migration\SimpleMigrationStep;

// Create new tables for the ILazyConfig API (lazyconfig).
// Create new field in appconfig for the new IAppConfig API, including lazy grouping.
class Version29000Date20231126110901 extends SimpleMigrationStep {
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
/** @var ISchemaWrapper $schema */
$schema = $schemaClosure();
$updated = false;

if (!$schema->hasTable('appconfig_lazy')) {
$table = $schema->createTable('appconfig_lazy');
$table->addColumn('app_id', Types::STRING, ['length' => 32]);
$table->addColumn('extra', Types::STRING, ['length' => 32]);
$table->addColumn('config_key', Types::STRING, ['length' => 64]);
$table->addColumn('config_value', Types::TEXT);

$table->setPrimaryKey(['app_id', 'config_key'], 'lazy_app_prim');
$table->addIndex(['app_id', 'extra'], 'lazy_app_id_i');
$table->addIndex(['app_id', 'extra', 'config_key'], 'lazy_app_id_key_i');
$updated = true;

if (!$schema->hasTable('appconfig')) {
return null;
}

if (!$updated) {
$table = $schema->getTable('appconfig');
if ($table->hasColumn('lazy_group')) {
return null;
}

$table->addColumn('lazy_group', Types::STRING, ['length' => 32, 'default' => '']);
$table->addColumn('sensitive', Types::SMALLINT, ['length' => 1, 'default' => '0']);

if ($table->hasIndex('appconfig_config_key_index')) {
$table->dropIndex('appconfig_config_key_index');
}

$table->addIndex(['appid', 'lazy_group'], 'ac_app_lazy_i');
$table->addIndex(['appid', 'lazy_group', 'config_key'], 'ac_app_lazy_key_i');

return $schema;
}
}
6 changes: 5 additions & 1 deletion core/ajax/update.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,14 @@
use OC\Repair\Events\RepairWarningEvent;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\IAppConfig;
use OCP\IConfig;
use OCP\IEventSource;
use OCP\IEventSourceFactory;
use OCP\IL10N;
use OCP\ILogger;
use OCP\L10N\IFactory;
use OCP\Server;

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

$logger = \OC::$server->get(\Psr\Log\LoggerInterface::class);
$config = \OC::$server->getConfig();
$config = Server::get(IConfig::class);
$updater = new \OC\Updater(
$config,
Server::get(IAppConfig::class),
\OC::$server->getIntegrityCodeChecker(),
$logger,
\OC::$server->query(\OC\Installer::class)
Expand Down
36 changes: 0 additions & 36 deletions lib/private/AllConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,13 @@
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IConfig;
use OCP\IDBConnection;
use OCP\ILazyConfig;
use OCP\PreConditionNotMetException;

/**
* Class to combine all the configuration options ownCloud offers
*/
class AllConfig implements IConfig {
private ?IDBConnection $connection = null;
private ?ILazyConfig $lazyConfig = null;

/**
* 3 dimensional array with the following structure:
Expand Down Expand Up @@ -548,38 +546,4 @@ public function getUsersForUserValueCaseInsensitive($appName, $key, $value) {
public function getSystemConfig() {
return $this->systemConfig;
}

public function getLazyConfig(): ILazyConfig {
if ($this->lazyConfig === null) {
$this->lazyConfig = \OCP\Server::get(ILazyConfig::class);
}

return $this->lazyConfig;
}

/**
* export AppConfig keys/values into LazyConfig
*
* $this->config->exportToLazy('my_app', [
* 'first-config' => 'default_value',
* 'my-other-config' => 12,
* 'boolean-flag' => '0'
* ]);
*
* @param string $app
* @param array $configKeys an array with keys to export as index, default as value
* @since 29.0.0
*/
public function exportToLazy(string $app, array $configKeys): void {
foreach ($configKeys as $key => $default) {
$value = $this->getAppValue($app, $key, (string)$default);
if ($this->getLazyConfig()->hasKey($app, $key)
|| $default === $value) {
continue;
}

$this->getLazyConfig()->setValueString($app, $key, $value);
$this->deleteAppValue($app, $key);
}
}
}
Loading

0 comments on commit 0e94b76

Please sign in to comment.