Skip to content

Commit

Permalink
ILazyConfig
Browse files Browse the repository at this point in the history
Signed-off-by: Maxence Lange <[email protected]>
  • Loading branch information
ArtificialOwl committed Nov 26, 2023
1 parent 371aa1b commit adf08fd
Show file tree
Hide file tree
Showing 7 changed files with 431 additions and 14 deletions.
23 changes: 18 additions & 5 deletions core/Command/Config/ListConfigs.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
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 @@ -37,6 +38,7 @@ class ListConfigs extends Base {
public function __construct(
protected SystemConfig $systemConfig,
protected IAppConfig $appConfig,
protected ILazyConfig $lazyConfig,
) {
parent::__construct();
}
Expand Down Expand Up @@ -83,17 +85,20 @@ 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) {

Check failure on line 93 in core/Command/Config/ListConfigs.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

UndefinedInterfaceMethod

core/Command/Config/ListConfigs.php:93:32: UndefinedInterfaceMethod: Method OCP\ILazyConfig::getApps does not exist (see https://psalm.dev/181)

Check failure

Code scanning / Psalm

UndefinedInterfaceMethod Error

Method OCP\ILazyConfig::getApps does not exist
$configs['lazy'][$appId] = $this->getLazyConfigs($appId, $noSensitiveValues);
}
break;

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

Expand Down Expand Up @@ -133,14 +138,22 @@ protected function getSystemConfigs($noSensitiveValues) {
* @param bool $noSensitiveValues
* @return array
*/
protected function getAppConfigs($app, $noSensitiveValues) {
protected function getAppConfigs(string $app, bool $noSensitiveValues): array {
if ($noSensitiveValues) {
return $this->appConfig->getFilteredValues($app, false);
return $this->appConfig->getFilteredValues($app);
} 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
2 changes: 1 addition & 1 deletion core/register_command.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
$application->add(new OC\Core\Command\Config\App\GetConfig(\OC::$server->getConfig()));
$application->add(new OC\Core\Command\Config\App\SetConfig(\OC::$server->getConfig()));
$application->add(new OC\Core\Command\Config\Import(\OC::$server->getConfig()));
$application->add(new OC\Core\Command\Config\ListConfigs(\OC::$server->getSystemConfig(), \OC::$server->getAppConfig()));
$application->add(\OCP\Server::get(\OC\Core\Command\Config\ListConfigs::class));
$application->add(new OC\Core\Command\Config\System\DeleteConfig(\OC::$server->getSystemConfig()));
$application->add(new OC\Core\Command\Config\System\GetConfig(\OC::$server->getSystemConfig()));
$application->add(new OC\Core\Command\Config\System\SetConfig(\OC::$server->getSystemConfig()));
Expand Down
16 changes: 13 additions & 3 deletions lib/private/AllConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,15 @@
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 SystemConfig $systemConfig;
private ?IDBConnection $connection = null;
private ?ILazyConfig $lazyConfig = null;

/**
* 3 dimensional array with the following structure:
Expand All @@ -67,9 +68,10 @@ class AllConfig implements IConfig {
*/
private CappedMemoryCache $userCache;

public function __construct(SystemConfig $systemConfig) {
public function __construct(
private SystemConfig $systemConfig
) {
$this->userCache = new CappedMemoryCache();
$this->systemConfig = $systemConfig;
}

/**
Expand Down Expand Up @@ -546,4 +548,12 @@ 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;
}
}
Loading

0 comments on commit adf08fd

Please sign in to comment.