Signed-off-by: Maxence Lange <maxence@artificial-owl.com>tags/v29.0.0beta1
@@ -27,12 +27,12 @@ declare(strict_types=1); | |||
*/ | |||
namespace OCA\Provisioning_API\Controller; | |||
use OC\AppConfig; | |||
use OC\AppFramework\Middleware\Security\Exceptions\NotAdminException; | |||
use OCP\AppFramework\Http; | |||
use OCP\AppFramework\Http\DataResponse; | |||
use OCP\AppFramework\OCSController; | |||
use OCP\IAppConfig; | |||
use OCP\IConfig; | |||
use OCP\IGroupManager; | |||
use OCP\IL10N; | |||
use OCP\IRequest; | |||
@@ -42,46 +42,17 @@ use OCP\Settings\IDelegatedSettings; | |||
use OCP\Settings\IManager; | |||
class AppConfigController extends OCSController { | |||
/** @var IConfig */ | |||
protected $config; | |||
/** @var IAppConfig */ | |||
protected $appConfig; | |||
/** @var IUserSession */ | |||
private $userSession; | |||
/** @var IL10N */ | |||
private $l10n; | |||
/** @var IGroupManager */ | |||
private $groupManager; | |||
/** @var IManager */ | |||
private $settingManager; | |||
/** | |||
* @param string $appName | |||
* @param IRequest $request | |||
* @param IConfig $config | |||
* @param IAppConfig $appConfig | |||
*/ | |||
public function __construct(string $appName, | |||
public function __construct( | |||
string $appName, | |||
IRequest $request, | |||
IConfig $config, | |||
IAppConfig $appConfig, | |||
IUserSession $userSession, | |||
IL10N $l10n, | |||
IGroupManager $groupManager, | |||
IManager $settingManager) { | |||
/** @var AppConfig */ | |||
private IAppConfig $appConfig, | |||
private IUserSession $userSession, | |||
private IL10N $l10n, | |||
private IGroupManager $groupManager, | |||
private IManager $settingManager, | |||
) { | |||
parent::__construct($appName, $request); | |||
$this->config = $config; | |||
$this->appConfig = $appConfig; | |||
$this->userSession = $userSession; | |||
$this->l10n = $l10n; | |||
$this->groupManager = $groupManager; | |||
$this->settingManager = $settingManager; | |||
} | |||
/** | |||
@@ -113,7 +84,7 @@ class AppConfigController extends OCSController { | |||
return new DataResponse(['data' => ['message' => $e->getMessage()]], Http::STATUS_FORBIDDEN); | |||
} | |||
return new DataResponse([ | |||
'data' => $this->config->getAppKeys($app), | |||
'data' => $this->appConfig->getKeys($app), | |||
]); | |||
} | |||
@@ -134,9 +105,10 @@ class AppConfigController extends OCSController { | |||
} catch (\InvalidArgumentException $e) { | |||
return new DataResponse(['data' => ['message' => $e->getMessage()]], Http::STATUS_FORBIDDEN); | |||
} | |||
return new DataResponse([ | |||
'data' => $this->config->getAppValue($app, $key, $defaultValue), | |||
]); | |||
/** @psalm-suppress InternalMethod */ | |||
$value = $this->appConfig->getValueMixed($app, $key, $defaultValue, null); | |||
return new DataResponse(['data' => $value]); | |||
} | |||
/** | |||
@@ -171,7 +143,8 @@ class AppConfigController extends OCSController { | |||
return new DataResponse(['data' => ['message' => $e->getMessage()]], Http::STATUS_FORBIDDEN); | |||
} | |||
$this->config->setAppValue($app, $key, $value); | |||
/** @psalm-suppress InternalMethod */ | |||
$this->appConfig->setValueMixed($app, $key, $value); | |||
return new DataResponse(); | |||
} | |||
@@ -195,7 +168,7 @@ class AppConfigController extends OCSController { | |||
return new DataResponse(['data' => ['message' => $e->getMessage()]], Http::STATUS_FORBIDDEN); | |||
} | |||
$this->config->deleteAppValue($app, $key); | |||
$this->appConfig->deleteKey($app, $key); | |||
return new DataResponse(); | |||
} | |||
@@ -231,7 +204,7 @@ class AppConfigController extends OCSController { | |||
if ($app === 'files' | |||
&& $key === 'default_quota' | |||
&& $value === 'none' | |||
&& $this->config->getAppValue('files', 'allow_unlimited_quota', '1') === '0') { | |||
&& $this->appConfig->getValueInt('files', 'allow_unlimited_quota', 1) === 0) { | |||
throw new \InvalidArgumentException('The given key can not be set, unlimited quota is forbidden on this instance'); | |||
} | |||
} |
@@ -137,15 +137,15 @@ class AppConfigControllerTest extends TestCase { | |||
->with($app) | |||
->willThrowException($throws); | |||
$this->config->expects($this->never()) | |||
->method('getAppKeys'); | |||
$this->appConfig->expects($this->never()) | |||
->method('getKeys'); | |||
} else { | |||
$api->expects($this->once()) | |||
->method('verifyAppId') | |||
->with($app); | |||
$this->config->expects($this->once()) | |||
->method('getAppKeys') | |||
$this->appConfig->expects($this->once()) | |||
->method('getKeys') | |||
->with($app) | |||
->willReturn($keys); | |||
} |
@@ -1,8 +1,11 @@ | |||
<?php | |||
declare(strict_types=1); | |||
/** | |||
* @copyright Copyright (c) 2016, ownCloud, Inc. | |||
* | |||
* @author Joas Schilling <coding@schilljs.com> | |||
* @author Maxence Lange <maxence@artificial-owl.com> | |||
* | |||
* @license AGPL-3.0 | |||
* | |||
@@ -21,7 +24,8 @@ | |||
*/ | |||
namespace OC\Core\Command\Config\App; | |||
use OCP\IConfig; | |||
use OCP\Exceptions\AppConfigUnknownKeyException; | |||
use OCP\IAppConfig; | |||
use Symfony\Component\Console\Input\InputArgument; | |||
use Symfony\Component\Console\Input\InputInterface; | |||
use Symfony\Component\Console\Input\InputOption; | |||
@@ -29,7 +33,7 @@ use Symfony\Component\Console\Output\OutputInterface; | |||
class GetConfig extends Base { | |||
public function __construct( | |||
protected IConfig $config, | |||
protected IAppConfig $appConfig, | |||
) { | |||
parent::__construct(); | |||
} | |||
@@ -50,6 +54,12 @@ class GetConfig extends Base { | |||
InputArgument::REQUIRED, | |||
'Name of the config to get' | |||
) | |||
->addOption( | |||
'details', | |||
null, | |||
InputOption::VALUE_NONE, | |||
'returns complete details about the app config value' | |||
) | |||
->addOption( | |||
'default-value', | |||
null, | |||
@@ -71,14 +81,32 @@ class GetConfig extends Base { | |||
$configName = $input->getArgument('name'); | |||
$defaultValue = $input->getOption('default-value'); | |||
if (!in_array($configName, $this->config->getAppKeys($appName)) && !$input->hasParameterOption('--default-value')) { | |||
return 1; | |||
if ($input->getOption('details')) { | |||
$details = $this->appConfig->getDetails($appName, $configName); | |||
$format = $input->getOption('output') ?? 'plain'; | |||
if ($format === 'json') { | |||
$output->writeln(json_encode($details)); | |||
} elseif ($format === 'json_pretty') { | |||
$output->writeln(json_encode($details, JSON_PRETTY_PRINT)); | |||
} else { | |||
$output->writeln('App: ' . $details['app'] ?? ''); | |||
$output->writeln('Config Key: ' . $details['key'] ?? ''); | |||
$output->writeln('Config Value: ' . $details['value'] ?? ''); | |||
$output->writeln('Value type: ' . $details['typeString'] ?? ''); | |||
$output->writeln('Lazy loaded: ' . (($details['lazy'] ?? false) ? 'Yes' : 'No')); | |||
$output->writeln('Sensitive: ' . (($details['sensitive'] ?? false) ? 'Yes' : 'No')); | |||
} | |||
return 0; | |||
} | |||
if (!in_array($configName, $this->config->getAppKeys($appName))) { | |||
try { | |||
$configValue = $this->appConfig->getDetails($appName, $configName)['value']; | |||
} catch (AppConfigUnknownKeyException $e) { | |||
if (!$input->hasParameterOption('--default-value')) { | |||
return 1; | |||
} | |||
$configValue = $defaultValue; | |||
} else { | |||
$configValue = $this->config->getAppValue($appName, $configName); | |||
} | |||
$this->writeMixedInOutputFormat($input, $output, $configValue); |
@@ -1,8 +1,11 @@ | |||
<?php | |||
declare(strict_types=1); | |||
/** | |||
* @copyright Copyright (c) 2016, ownCloud, Inc. | |||
* | |||
* @author Joas Schilling <coding@schilljs.com> | |||
* @author Maxence Lange <maxence@artificial-owl.com> | |||
* | |||
* @license AGPL-3.0 | |||
* | |||
@@ -21,15 +24,22 @@ | |||
*/ | |||
namespace OC\Core\Command\Config\App; | |||
use OCP\IConfig; | |||
use OC\AppConfig; | |||
use OCP\Exceptions\AppConfigIncorrectTypeException; | |||
use OCP\Exceptions\AppConfigUnknownKeyException; | |||
use OCP\IAppConfig; | |||
use Symfony\Component\Console\Input\InputArgument; | |||
use Symfony\Component\Console\Input\InputInterface; | |||
use Symfony\Component\Console\Input\InputOption; | |||
use Symfony\Component\Console\Output\OutputInterface; | |||
use Symfony\Component\Console\Question\Question; | |||
class SetConfig extends Base { | |||
private InputInterface $input; | |||
private OutputInterface $output; | |||
public function __construct( | |||
protected IConfig $config, | |||
protected IAppConfig $appConfig, | |||
) { | |||
parent::__construct(); | |||
} | |||
@@ -56,6 +66,25 @@ class SetConfig extends Base { | |||
InputOption::VALUE_REQUIRED, | |||
'The new value of the config' | |||
) | |||
->addOption( | |||
'type', | |||
null, | |||
InputOption::VALUE_REQUIRED, | |||
'Value type [string, integer, float, boolean, array]', | |||
'string' | |||
) | |||
->addOption( | |||
'lazy', | |||
null, | |||
InputOption::VALUE_NEGATABLE, | |||
'Set value as lazy loaded', | |||
) | |||
->addOption( | |||
'sensitive', | |||
null, | |||
InputOption::VALUE_NEGATABLE, | |||
'Set value as sensitive', | |||
) | |||
->addOption( | |||
'update-only', | |||
null, | |||
@@ -68,16 +97,179 @@ class SetConfig extends Base { | |||
protected function execute(InputInterface $input, OutputInterface $output): int { | |||
$appName = $input->getArgument('app'); | |||
$configName = $input->getArgument('name'); | |||
$this->input = $input; | |||
$this->output = $output; | |||
if (!($this->appConfig instanceof AppConfig)) { | |||
throw new \Exception('Only compatible with OC\AppConfig as it uses internal methods'); | |||
} | |||
if ($input->hasParameterOption('--update-only') && !$this->appConfig->hasKey($appName, $configName)) { | |||
$output->writeln( | |||
'<comment>Config value ' . $configName . ' for app ' . $appName | |||
. ' not updated, as it has not been set before.</comment>' | |||
); | |||
if (!in_array($configName, $this->config->getAppKeys($appName)) && $input->hasParameterOption('--update-only')) { | |||
$output->writeln('<comment>Config value ' . $configName . ' for app ' . $appName . ' not updated, as it has not been set before.</comment>'); | |||
return 1; | |||
} | |||
$configValue = $input->getOption('value'); | |||
$this->config->setAppValue($appName, $configName, $configValue); | |||
$type = $typeString = null; | |||
if ($input->hasParameterOption('--type')) { | |||
$typeString = $input->getOption('type'); | |||
$type = $this->appConfig->convertTypeToInt($typeString); | |||
} | |||
/** | |||
* If --Value is not specified, returns an exception if no value exists in database | |||
* compare with current status in database and displays a reminder that this can break things. | |||
* confirmation is required by admin, unless --no-interaction | |||
*/ | |||
$updated = false; | |||
if (!$input->hasParameterOption('--value')) { | |||
if (!$input->getOption('lazy') && $this->appConfig->isLazy($appName, $configName) && $this->ask('NOT LAZY')) { | |||
$updated = $this->appConfig->updateLazy($appName, $configName, false); | |||
} | |||
if ($input->getOption('lazy') && !$this->appConfig->isLazy($appName, $configName) && $this->ask('LAZY')) { | |||
$updated = $this->appConfig->updateLazy($appName, $configName, true) || $updated; | |||
} | |||
if (!$input->getOption('sensitive') && $this->appConfig->isSensitive($appName, $configName) && $this->ask('NOT SENSITIVE')) { | |||
$updated = $this->appConfig->updateSensitive($appName, $configName, false) || $updated; | |||
} | |||
if ($input->getOption('sensitive') && !$this->appConfig->isSensitive($appName, $configName) && $this->ask('SENSITIVE')) { | |||
$updated = $this->appConfig->updateSensitive($appName, $configName, true) || $updated; | |||
} | |||
if ($typeString !== null && $type !== $this->appConfig->getValueType($appName, $configName) && $this->ask($typeString)) { | |||
$updated = $this->appConfig->updateType($appName, $configName, $type) || $updated; | |||
} | |||
} else { | |||
/** | |||
* If --type is specified in the command line, we upgrade the type in database | |||
* after a confirmation from admin. | |||
* If not we get the type from current stored value or VALUE_MIXED as default. | |||
*/ | |||
try { | |||
$currType = $this->appConfig->getValueType($appName, $configName); | |||
if ($type === null || $type === $currType || !$this->ask($typeString)) { | |||
$type = $currType; | |||
} else { | |||
$updated = $this->appConfig->updateType($appName, $configName, $type); | |||
} | |||
} catch (AppConfigUnknownKeyException) { | |||
$type = $type ?? IAppConfig::VALUE_MIXED; | |||
} | |||
/** | |||
* if --lazy/--no-lazy option are set, compare with data stored in database. | |||
* If no data in database, or identical, continue. | |||
* If different, ask admin for confirmation. | |||
*/ | |||
$lazy = $input->getOption('lazy'); | |||
try { | |||
$currLazy = $this->appConfig->isLazy($appName, $configName); | |||
if ($lazy === null || $lazy === $currLazy || !$this->ask(($lazy) ? 'LAZY' : 'NOT LAZY')) { | |||
$lazy = $currLazy; | |||
} | |||
} catch (AppConfigUnknownKeyException) { | |||
$lazy = $lazy ?? false; | |||
} | |||
/** | |||
* same with sensitive status | |||
*/ | |||
$sensitive = $input->getOption('sensitive'); | |||
try { | |||
$currSensitive = $this->appConfig->isLazy($appName, $configName); | |||
if ($sensitive === null || $sensitive === $currSensitive || !$this->ask(($sensitive) ? 'LAZY' : 'NOT LAZY')) { | |||
$sensitive = $currSensitive; | |||
} | |||
} catch (AppConfigUnknownKeyException) { | |||
$sensitive = $sensitive ?? false; | |||
} | |||
$value = (string)$input->getOption('value'); | |||
switch ($type) { | |||
case IAppConfig::VALUE_MIXED: | |||
$updated = $this->appConfig->setValueMixed($appName, $configName, $value, $lazy, $sensitive); | |||
break; | |||
case IAppConfig::VALUE_STRING: | |||
$updated = $this->appConfig->setValueString($appName, $configName, $value, $lazy, $sensitive); | |||
break; | |||
case IAppConfig::VALUE_INT: | |||
if ($value !== ((string) ((int) $value))) { | |||
throw new AppConfigIncorrectTypeException('Value is not an integer'); | |||
} | |||
$updated = $this->appConfig->setValueInt($appName, $configName, (int)$value, $lazy, $sensitive); | |||
break; | |||
case IAppConfig::VALUE_FLOAT: | |||
if ($value !== ((string) ((float) $value))) { | |||
throw new AppConfigIncorrectTypeException('Value is not a float'); | |||
} | |||
$updated = $this->appConfig->setValueFloat($appName, $configName, (float)$value, $lazy, $sensitive); | |||
break; | |||
case IAppConfig::VALUE_BOOL: | |||
if (strtolower($value) === 'true') { | |||
$valueBool = true; | |||
} elseif (strtolower($value) === 'false') { | |||
$valueBool = false; | |||
} else { | |||
throw new AppConfigIncorrectTypeException('Value is not a boolean, please use \'true\' or \'false\''); | |||
} | |||
$updated = $this->appConfig->setValueBool($appName, $configName, $valueBool, $lazy); | |||
break; | |||
case IAppConfig::VALUE_ARRAY: | |||
$valueArray = json_decode($value, true, flags: JSON_THROW_ON_ERROR); | |||
$valueArray = (is_array($valueArray)) ? $valueArray : throw new AppConfigIncorrectTypeException('Value is not an array'); | |||
$updated = $this->appConfig->setValueArray($appName, $configName, $valueArray, $lazy, $sensitive); | |||
break; | |||
} | |||
} | |||
if ($updated) { | |||
$current = $this->appConfig->getDetails($appName, $configName); | |||
$output->writeln( | |||
sprintf( | |||
"<info>Config value '%s' for app '%s' is now set to '%s', stored as %s in %s</info>", | |||
$configName, | |||
$appName, | |||
$current['value'], | |||
$current['typeString'], | |||
$current['lazy'] ? 'lazy cache' : 'fast cache' | |||
) | |||
); | |||
} else { | |||
$output->writeln('<info>Config value were not updated</info>'); | |||
} | |||
$output->writeln('<info>Config value ' . $configName . ' for app ' . $appName . ' set to ' . $configValue . '</info>'); | |||
return 0; | |||
} | |||
private function ask(string $request): bool { | |||
$helper = $this->getHelper('question'); | |||
if ($this->input->getOption('no-interaction')) { | |||
return true; | |||
} | |||
$this->output->writeln(sprintf('You are about to set config value %s as <info>%s</info>', | |||
'<info>' . $this->input->getArgument('app') . '</info>/<info>' . $this->input->getArgument('name') . '</info>', | |||
strtoupper($request) | |||
)); | |||
$this->output->writeln(''); | |||
$this->output->writeln('<comment>This might break thing, affect performance on your instance or its security!</comment>'); | |||
$result = (strtolower((string)$helper->ask( | |||
$this->input, | |||
$this->output, | |||
new Question('<comment>Confirm this action by typing \'yes\'</comment>: '))) === 'yes'); | |||
$this->output->writeln(($result) ? 'done' : 'cancelled'); | |||
$this->output->writeln(''); | |||
return $result; | |||
} | |||
} |
@@ -91,9 +91,7 @@ class ListConfigs extends Base { | |||
default: | |||
$configs = [ | |||
'apps' => [ | |||
$app => $this->getAppConfigs($app, $noSensitiveValues), | |||
], | |||
'apps' => [$app => $this->getAppConfigs($app, $noSensitiveValues)], | |||
]; | |||
} | |||
@@ -107,7 +105,7 @@ class ListConfigs extends Base { | |||
* @param bool $noSensitiveValues | |||
* @return array | |||
*/ | |||
protected function getSystemConfigs($noSensitiveValues) { | |||
protected function getSystemConfigs(bool $noSensitiveValues): array { | |||
$keys = $this->systemConfig->getKeys(); | |||
$configs = []; | |||
@@ -133,7 +131,7 @@ class ListConfigs extends Base { | |||
* @param bool $noSensitiveValues | |||
* @return array | |||
*/ | |||
protected function getAppConfigs($app, $noSensitiveValues) { | |||
protected function getAppConfigs(string $app, bool $noSensitiveValues) { | |||
if ($noSensitiveValues) { | |||
return $this->appConfig->getFilteredValues($app, false); | |||
} else { |
@@ -35,7 +35,6 @@ namespace OC\Core\Command; | |||
use OC\Console\TimestampFormatter; | |||
use OC\DB\MigratorExecuteSqlEvent; | |||
use OC\Installer; | |||
use OC\Repair\Events\RepairAdvanceEvent; | |||
use OC\Repair\Events\RepairErrorEvent; | |||
use OC\Repair\Events\RepairFinishEvent; | |||
@@ -48,7 +47,6 @@ use OCP\EventDispatcher\Event; | |||
use OCP\EventDispatcher\IEventDispatcher; | |||
use OCP\IConfig; | |||
use OCP\Util; | |||
use Psr\Log\LoggerInterface; | |||
use Symfony\Component\Console\Command\Command; | |||
use Symfony\Component\Console\Helper\ProgressBar; | |||
use Symfony\Component\Console\Input\InputInterface; | |||
@@ -63,9 +61,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(); | |||
} | |||
@@ -91,12 +87,7 @@ class Upgrade extends Command { | |||
} | |||
$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); |
@@ -0,0 +1,63 @@ | |||
<?php | |||
declare(strict_types=1); | |||
/** | |||
* @copyright 2023 Maxence Lange <maxence@artificial-owl.com> | |||
* | |||
* @author Maxence Lange <maxence@artificial-owl.com> | |||
* | |||
* @license GNU AGPL version 3 or any later version | |||
* | |||
* This program is free software: you can redistribute it and/or modify | |||
* it under the terms of the GNU Affero General Public License as | |||
* published by the Free Software Foundation, either version 3 of the | |||
* License, or (at your option) any later version. | |||
* | |||
* This program is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
* GNU Affero General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU Affero General Public License | |||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
* | |||
*/ | |||
namespace OC\Core\Migrations; | |||
use Closure; | |||
use OCP\DB\ISchemaWrapper; | |||
use OCP\DB\Types; | |||
use OCP\Migration\IOutput; | |||
use OCP\Migration\SimpleMigrationStep; | |||
// 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(); | |||
if (!$schema->hasTable('appconfig')) { | |||
return null; | |||
} | |||
$table = $schema->getTable('appconfig'); | |||
if ($table->hasColumn('lazy')) { | |||
return null; | |||
} | |||
// type=2 means value is typed as MIXED | |||
$table->addColumn('type', Types::INTEGER, ['notnull' => true, 'default' => 2]); | |||
$table->addColumn('lazy', Types::BOOLEAN, ['notnull' => false, 'default' => false]); | |||
if ($table->hasIndex('appconfig_config_key_index')) { | |||
$table->dropIndex('appconfig_config_key_index'); | |||
} | |||
$table->addIndex(['lazy'], 'ac_lazy_i'); | |||
$table->addIndex(['appid', 'lazy'], 'ac_app_lazy_i'); | |||
$table->addIndex(['appid', 'lazy', 'configkey'], 'ac_app_lazy_key_i'); | |||
return $schema; | |||
} | |||
} |
@@ -97,10 +97,10 @@ if (\OC::$server->getConfig()->getSystemValue('installed', false)) { | |||
$application->add(\OC::$server->query(\OC\Core\Command\Broadcast\Test::class)); | |||
$application->add(new OC\Core\Command\Config\App\DeleteConfig(\OC::$server->getConfig())); | |||
$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(\OCP\Server::get(\OC\Core\Command\Config\App\GetConfig::class)); | |||
$application->add(\OCP\Server::get(\OC\Core\Command\Config\App\SetConfig::class)); | |||
$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())); | |||
@@ -171,7 +171,7 @@ if (\OC::$server->getConfig()->getSystemValue('installed', false)) { | |||
$application->add(new OC\Core\Command\Maintenance\UpdateHtaccess()); | |||
$application->add(new OC\Core\Command\Maintenance\UpdateTheme(\OC::$server->getMimeTypeDetector(), \OC::$server->getMemCacheFactory())); | |||
$application->add(new OC\Core\Command\Upgrade(\OC::$server->getConfig(), \OC::$server->get(LoggerInterface::class), \OC::$server->query(\OC\Installer::class))); | |||
$application->add(new OC\Core\Command\Upgrade(\OC::$server->getConfig())); | |||
$application->add(new OC\Core\Command\Maintenance\Repair( | |||
new \OC\Repair([], \OC::$server->get(\OCP\EventDispatcher\IEventDispatcher::class), \OC::$server->get(LoggerInterface::class)), | |||
\OC::$server->getConfig(), |
@@ -273,6 +273,10 @@ return array( | |||
'OCP\\EventDispatcher\\GenericEvent' => $baseDir . '/lib/public/EventDispatcher/GenericEvent.php', | |||
'OCP\\EventDispatcher\\IEventDispatcher' => $baseDir . '/lib/public/EventDispatcher/IEventDispatcher.php', | |||
'OCP\\EventDispatcher\\IEventListener' => $baseDir . '/lib/public/EventDispatcher/IEventListener.php', | |||
'OCP\\Exceptions\\AppConfigException' => $baseDir . '/lib/public/Exceptions/AppConfigException.php', | |||
'OCP\\Exceptions\\AppConfigIncorrectTypeException' => $baseDir . '/lib/public/Exceptions/AppConfigIncorrectTypeException.php', | |||
'OCP\\Exceptions\\AppConfigTypeConflictException' => $baseDir . '/lib/public/Exceptions/AppConfigTypeConflictException.php', | |||
'OCP\\Exceptions\\AppConfigUnknownKeyException' => $baseDir . '/lib/public/Exceptions/AppConfigUnknownKeyException.php', | |||
'OCP\\Federation\\Events\\TrustedServerRemovedEvent' => $baseDir . '/lib/public/Federation/Events/TrustedServerRemovedEvent.php', | |||
'OCP\\Federation\\Exceptions\\ActionNotSupportedException' => $baseDir . '/lib/public/Federation/Exceptions/ActionNotSupportedException.php', | |||
'OCP\\Federation\\Exceptions\\AuthenticationFailedException' => $baseDir . '/lib/public/Federation/Exceptions/AuthenticationFailedException.php', | |||
@@ -1237,6 +1241,7 @@ return array( | |||
'OC\\Core\\Migrations\\Version28000Date20230906104802' => $baseDir . '/core/Migrations/Version28000Date20230906104802.php', | |||
'OC\\Core\\Migrations\\Version28000Date20231004103301' => $baseDir . '/core/Migrations/Version28000Date20231004103301.php', | |||
'OC\\Core\\Migrations\\Version28000Date20231103104802' => $baseDir . '/core/Migrations/Version28000Date20231103104802.php', | |||
'OC\\Core\\Migrations\\Version29000Date20231126110901' => $baseDir . '/core/Migrations/Version29000Date20231126110901.php', | |||
'OC\\Core\\Migrations\\Version29000Date20231213104850' => $baseDir . '/core/Migrations/Version29000Date20231213104850.php', | |||
'OC\\Core\\Notification\\CoreNotifier' => $baseDir . '/core/Notification/CoreNotifier.php', | |||
'OC\\Core\\Service\\LoginFlowV2Service' => $baseDir . '/core/Service/LoginFlowV2Service.php', |
@@ -306,6 +306,10 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2 | |||
'OCP\\EventDispatcher\\GenericEvent' => __DIR__ . '/../../..' . '/lib/public/EventDispatcher/GenericEvent.php', | |||
'OCP\\EventDispatcher\\IEventDispatcher' => __DIR__ . '/../../..' . '/lib/public/EventDispatcher/IEventDispatcher.php', | |||
'OCP\\EventDispatcher\\IEventListener' => __DIR__ . '/../../..' . '/lib/public/EventDispatcher/IEventListener.php', | |||
'OCP\\Exceptions\\AppConfigException' => __DIR__ . '/../../..' . '/lib/public/Exceptions/AppConfigException.php', | |||
'OCP\\Exceptions\\AppConfigIncorrectTypeException' => __DIR__ . '/../../..' . '/lib/public/Exceptions/AppConfigIncorrectTypeException.php', | |||
'OCP\\Exceptions\\AppConfigTypeConflictException' => __DIR__ . '/../../..' . '/lib/public/Exceptions/AppConfigTypeConflictException.php', | |||
'OCP\\Exceptions\\AppConfigUnknownKeyException' => __DIR__ . '/../../..' . '/lib/public/Exceptions/AppConfigUnknownKeyException.php', | |||
'OCP\\Federation\\Events\\TrustedServerRemovedEvent' => __DIR__ . '/../../..' . '/lib/public/Federation/Events/TrustedServerRemovedEvent.php', | |||
'OCP\\Federation\\Exceptions\\ActionNotSupportedException' => __DIR__ . '/../../..' . '/lib/public/Federation/Exceptions/ActionNotSupportedException.php', | |||
'OCP\\Federation\\Exceptions\\AuthenticationFailedException' => __DIR__ . '/../../..' . '/lib/public/Federation/Exceptions/AuthenticationFailedException.php', | |||
@@ -1270,6 +1274,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2 | |||
'OC\\Core\\Migrations\\Version28000Date20230906104802' => __DIR__ . '/../../..' . '/core/Migrations/Version28000Date20230906104802.php', | |||
'OC\\Core\\Migrations\\Version28000Date20231004103301' => __DIR__ . '/../../..' . '/core/Migrations/Version28000Date20231004103301.php', | |||
'OC\\Core\\Migrations\\Version28000Date20231103104802' => __DIR__ . '/../../..' . '/core/Migrations/Version28000Date20231103104802.php', | |||
'OC\\Core\\Migrations\\Version29000Date20231126110901' => __DIR__ . '/../../..' . '/core/Migrations/Version29000Date20231126110901.php', | |||
'OC\\Core\\Migrations\\Version29000Date20231213104850' => __DIR__ . '/../../..' . '/core/Migrations/Version29000Date20231213104850.php', | |||
'OC\\Core\\Notification\\CoreNotifier' => __DIR__ . '/../../..' . '/core/Notification/CoreNotifier.php', | |||
'OC\\Core\\Service\\LoginFlowV2Service' => __DIR__ . '/../../..' . '/core/Service/LoginFlowV2Service.php', |
@@ -43,7 +43,6 @@ use OCP\PreConditionNotMetException; | |||
* Class to combine all the configuration options ownCloud offers | |||
*/ | |||
class AllConfig implements IConfig { | |||
private SystemConfig $systemConfig; | |||
private ?IDBConnection $connection = null; | |||
/** | |||
@@ -68,9 +67,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; | |||
} | |||
/** | |||
@@ -190,6 +190,7 @@ class AllConfig implements IConfig { | |||
* | |||
* @param string $appName the appName that we stored the value under | |||
* @return string[] the keys stored for the app | |||
* @deprecated 29.0.0 Use {@see IAppConfig} directly | |||
*/ | |||
public function getAppKeys($appName) { | |||
return \OC::$server->get(AppConfig::class)->getKeys($appName); | |||
@@ -201,6 +202,7 @@ class AllConfig implements IConfig { | |||
* @param string $appName the appName that we want to store the value under | |||
* @param string $key the key of the value, under which will be saved | |||
* @param string|float|int $value the value that should be stored | |||
* @deprecated 29.0.0 Use {@see IAppConfig} directly | |||
*/ | |||
public function setAppValue($appName, $key, $value) { | |||
\OC::$server->get(AppConfig::class)->setValue($appName, $key, $value); | |||
@@ -213,6 +215,7 @@ class AllConfig implements IConfig { | |||
* @param string $key the key of the value, under which it was saved | |||
* @param string $default the default value to be returned if the value isn't set | |||
* @return string the saved value | |||
* @deprecated 29.0.0 Use {@see IAppConfig} directly | |||
*/ | |||
public function getAppValue($appName, $key, $default = '') { | |||
return \OC::$server->get(AppConfig::class)->getValue($appName, $key, $default); | |||
@@ -223,6 +226,7 @@ class AllConfig implements IConfig { | |||
* | |||
* @param string $appName the appName that we stored the value under | |||
* @param string $key the key of the value, under which it was saved | |||
* @deprecated 29.0.0 Use {@see IAppConfig} directly | |||
*/ | |||
public function deleteAppValue($appName, $key) { | |||
\OC::$server->get(AppConfig::class)->deleteKey($appName, $key); | |||
@@ -232,6 +236,7 @@ class AllConfig implements IConfig { | |||
* Removes all keys in appconfig belonging to the app | |||
* | |||
* @param string $appName the appName the configs are stored under | |||
* @deprecated 29.0.0 Use {@see IAppConfig} directly | |||
*/ | |||
public function deleteAppValues($appName) { | |||
\OC::$server->get(AppConfig::class)->deleteApp($appName); |
@@ -124,11 +124,9 @@ class SystemConfig { | |||
], | |||
]; | |||
/** @var Config */ | |||
private $config; | |||
public function __construct(Config $config) { | |||
$this->config = $config; | |||
public function __construct( | |||
private Config $config, | |||
) { | |||
} | |||
/** |
@@ -63,6 +63,7 @@ use OCP\App\IAppManager; | |||
use OCP\App\ManagerEvent; | |||
use OCP\Authentication\IAlternativeLogin; | |||
use OCP\EventDispatcher\IEventDispatcher; | |||
use OCP\IAppConfig; | |||
use Psr\Container\ContainerExceptionInterface; | |||
use Psr\Log\LoggerInterface; | |||
@@ -730,8 +731,9 @@ class OC_App { | |||
static $versions; | |||
if (!$versions) { | |||
$appConfig = \OC::$server->getAppConfig(); | |||
$versions = $appConfig->getValues(false, 'installed_version'); | |||
/** @var IAppConfig $appConfig */ | |||
$appConfig = \OCP\Server::get(IAppConfig::class); | |||
$versions = $appConfig->searchValues('installed_version'); | |||
} | |||
return $versions; | |||
} |
@@ -0,0 +1,34 @@ | |||
<?php | |||
declare(strict_types=1); | |||
/** | |||
* @copyright 2023 Maxence Lange <maxence@artificial-owl.com> | |||
* | |||
* @author Maxence Lange <maxence@artificial-owl.com> | |||
* | |||
* @license GNU AGPL version 3 or any later version | |||
* | |||
* This program is free software: you can redistribute it and/or modify | |||
* it under the terms of the GNU Affero General Public License as | |||
* published by the Free Software Foundation, either version 3 of the | |||
* License, or (at your option) any later version. | |||
* | |||
* This program is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
* GNU Affero General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU Affero General Public License | |||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
* | |||
*/ | |||
namespace OCP\Exceptions; | |||
use Exception; | |||
/** | |||
* @since 29.0.0 | |||
*/ | |||
class AppConfigException extends Exception { | |||
} |
@@ -0,0 +1,32 @@ | |||
<?php | |||
declare(strict_types=1); | |||
/** | |||
* @copyright 2023 Maxence Lange <maxence@artificial-owl.com> | |||
* | |||
* @author Maxence Lange <maxence@artificial-owl.com> | |||
* | |||
* @license GNU AGPL version 3 or any later version | |||
* | |||
* This program is free software: you can redistribute it and/or modify | |||
* it under the terms of the GNU Affero General Public License as | |||
* published by the Free Software Foundation, either version 3 of the | |||
* License, or (at your option) any later version. | |||
* | |||
* This program is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
* GNU Affero General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU Affero General Public License | |||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
* | |||
*/ | |||
namespace OCP\Exceptions; | |||
/** | |||
* @since 29.0.0 | |||
*/ | |||
class AppConfigIncorrectTypeException extends AppConfigException { | |||
} |
@@ -0,0 +1,32 @@ | |||
<?php | |||
declare(strict_types=1); | |||
/** | |||
* @copyright 2023 Maxence Lange <maxence@artificial-owl.com> | |||
* | |||
* @author Maxence Lange <maxence@artificial-owl.com> | |||
* | |||
* @license GNU AGPL version 3 or any later version | |||
* | |||
* This program is free software: you can redistribute it and/or modify | |||
* it under the terms of the GNU Affero General Public License as | |||
* published by the Free Software Foundation, either version 3 of the | |||
* License, or (at your option) any later version. | |||
* | |||
* This program is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
* GNU Affero General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU Affero General Public License | |||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
* | |||
*/ | |||
namespace OCP\Exceptions; | |||
/** | |||
* @since 29.0.0 | |||
*/ | |||
class AppConfigTypeConflictException extends AppConfigException { | |||
} |
@@ -0,0 +1,32 @@ | |||
<?php | |||
declare(strict_types=1); | |||
/** | |||
* @copyright 2023 Maxence Lange <maxence@artificial-owl.com> | |||
* | |||
* @author Maxence Lange <maxence@artificial-owl.com> | |||
* | |||
* @license GNU AGPL version 3 or any later version | |||
* | |||
* This program is free software: you can redistribute it and/or modify | |||
* it under the terms of the GNU Affero General Public License as | |||
* published by the Free Software Foundation, either version 3 of the | |||
* License, or (at your option) any later version. | |||
* | |||
* This program is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
* GNU Affero General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU Affero General Public License | |||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
* | |||
*/ | |||
namespace OCP\Exceptions; | |||
/** | |||
* @since 29.0.0 | |||
*/ | |||
class AppConfigUnknownKeyException extends AppConfigException { | |||
} |
@@ -1,9 +1,12 @@ | |||
<?php | |||
declare(strict_types=1); | |||
/** | |||
* @copyright Copyright (c) 2016, ownCloud, Inc. | |||
* | |||
* @author Bart Visscher <bartv@thisnet.nl> | |||
* @author Joas Schilling <coding@schilljs.com> | |||
* @author Maxence Lange <maxence@artificial-owl.com> | |||
* @author Morris Jobke <hey@morrisjobke.de> | |||
* @author Robin Appelman <robin@icewind.nl> | |||
* @author Robin McCorkell <robin@mccorkell.me.uk> | |||
@@ -26,28 +29,537 @@ | |||
*/ | |||
namespace OCP; | |||
use OCP\Exceptions\AppConfigUnknownKeyException; | |||
/** | |||
* This class provides an easy way for apps to store config values in the | |||
* database. | |||
* | |||
* **Note:** since 29.0.0, it supports **lazy loading** | |||
* | |||
* ### What is lazy loading ? | |||
* | |||
* By default, app config values are all loaded in memory; but in order to avoid | |||
* loading useless config values in memory on each request on the cloud, it has | |||
* been made possible to set your config keys as lazy. | |||
* When set as lazy, the values will only be loaded in memory when needed. | |||
* In fact, the cloud will load all config set as lazy loaded when a first one | |||
* is requested. | |||
* | |||
* It is advised to set a config key as lazy when its value is only needed during | |||
* really specific request, in part of code that is not called frequently. | |||
* | |||
* **Note:** some methods from this class are marked with a warning about ignoring | |||
* lazy filtering, meaning it will load in memory all apps config values. use them | |||
* wisely and only in part of code called during specific request/action. | |||
* | |||
* @since 29.0.0 supports lazy loading | |||
* @since 7.0.0 | |||
*/ | |||
interface IAppConfig { | |||
public const VALUE_SENSITIVE = 1; | |||
public const VALUE_MIXED = 2; | |||
public const VALUE_STRING = 4; | |||
public const VALUE_INT = 8; | |||
public const VALUE_FLOAT = 16; | |||
public const VALUE_BOOL = 32; | |||
public const VALUE_ARRAY = 64; | |||
/** | |||
* check if a key is set in the appconfig | |||
* @param string $app | |||
* @param string $key | |||
* @return bool | |||
* Get list of all apps that have at least one config value stored in database | |||
* | |||
* **WARNING:** ignore lazy filtering, all config values are loaded from database | |||
* | |||
* @return string[] list of app ids | |||
* @since 7.0.0 | |||
*/ | |||
public function getApps(): array; | |||
/** | |||
* Returns all keys stored in database, related to an app. | |||
* Please note that the values are not returned. | |||
* | |||
* **WARNING:** ignore lazy filtering, all config values are loaded from database | |||
* | |||
* @param string $app id of the app | |||
* | |||
* @return string[] list of stored config keys | |||
* @since 29.0.0 | |||
*/ | |||
public function getKeys(string $app): array; | |||
/** | |||
* Check if a key exists in the list of stored config values. | |||
* | |||
* @param string $app id of the app | |||
* @param string $key config key | |||
* @param bool $lazy search within lazy loaded config | |||
* | |||
* @return bool TRUE if key exists | |||
* @since 29.0.0 Added the $lazy argument | |||
* @since 7.0.0 | |||
*/ | |||
public function hasKey($app, $key); | |||
public function hasKey(string $app, string $key, ?bool $lazy = false): bool; | |||
/** | |||
* best way to see if a value is set as sensitive (not displayed in report) | |||
* | |||
* @param string $app id of the app | |||
* @param string $key config key | |||
* @param bool|null $lazy search within lazy loaded config | |||
* | |||
* @return bool TRUE if value is sensitive | |||
* @throws AppConfigUnknownKeyException if config key is not known | |||
* @since 29.0.0 | |||
*/ | |||
public function isSensitive(string $app, string $key, ?bool $lazy = false): bool; | |||
/** | |||
* Returns if the config key stored in database is lazy loaded | |||
* | |||
* **WARNING:** ignore lazy filtering, all config values are loaded from database | |||
* | |||
* @param string $app id of the app | |||
* @param string $key config key | |||
* | |||
* @return bool TRUE if config is lazy loaded | |||
* @throws AppConfigUnknownKeyException if config key is not known | |||
* @see IAppConfig for details about lazy loading | |||
* @since 29.0.0 | |||
*/ | |||
public function isLazy(string $app, string $key): bool; | |||
/** | |||
* List all config values from an app with config key starting with $key. | |||
* Returns an array with config key as key, stored value as value. | |||
* | |||
* **WARNING:** ignore lazy filtering, all config values are loaded from database | |||
* | |||
* @param string $app id of the app | |||
* @param string $key config keys prefix to search, can be empty. | |||
* @param bool $filtered filter sensitive config values | |||
* | |||
* @return array<string, string> [configKey => configValue] | |||
* @since 29.0.0 | |||
*/ | |||
public function getAllValues(string $app, string $key = '', bool $filtered = false): array; | |||
/** | |||
* List all apps storing a specific config key and its stored value. | |||
* Returns an array with appId as key, stored value as value. | |||
* | |||
* @param string $key config key | |||
* @param bool $lazy search within lazy loaded config | |||
* | |||
* @return array<string, string> [appId => configValue] | |||
* @since 29.0.0 | |||
*/ | |||
public function searchValues(string $key, bool $lazy = false): array; | |||
/** | |||
* Get config value assigned to a config key. | |||
* If config key is not found in database, default value is returned. | |||
* If config key is set as lazy loaded, the $lazy argument needs to be set to TRUE. | |||
* | |||
* @param string $app id of the app | |||
* @param string $key config key | |||
* @param string $default default value | |||
* @param bool $lazy search within lazy loaded config | |||
* | |||
* @return string stored config value or $default if not set in database | |||
* @since 29.0.0 | |||
* @see IAppConfig for explanation about lazy loading | |||
* @see getValueInt() | |||
* @see getValueBigInt() | |||
* @see getValueFloat() | |||
* @see getValueBool() | |||
* @see getValueArray() | |||
*/ | |||
public function getValueString(string $app, string $key, string $default = '', bool $lazy = false): string; | |||
/** | |||
* Get config value assigned to a config key. | |||
* If config key is not found in database, default value is returned. | |||
* If config key is set as lazy loaded, the $lazy argument needs to be set to TRUE. | |||
* | |||
* @param string $app id of the app | |||
* @param string $key config key | |||
* @param int $default default value | |||
* @param bool $lazy search within lazy loaded config | |||
* | |||
* @return int stored config value or $default if not set in database | |||
* @since 29.0.0 | |||
* @see IAppConfig for explanation about lazy loading | |||
* @see getValueString() | |||
* @see getValueBigInt() | |||
* @see getValueFloat() | |||
* @see getValueBool() | |||
* @see getValueArray() | |||
*/ | |||
public function getValueInt(string $app, string $key, int $default = 0, bool $lazy = false): int; | |||
/** | |||
* Get config value assigned to a config key. | |||
* If config key is not found in database, default value is returned. | |||
* If config key is set as lazy loaded, the $lazy argument needs to be set to TRUE. | |||
* | |||
* @param string $app id of the app | |||
* @param string $key config key | |||
* @param int|float $default default value | |||
* @param bool $lazy search within lazy loaded config | |||
* | |||
* @return int|float stored config value or $default if not set in database | |||
* @since 29.0.0 | |||
* @see IAppConfig for explanation about lazy loading | |||
* @see getValueString() | |||
* @see getValueInt() | |||
* @see getValueFloat() | |||
* @see getValueBool() | |||
* @see getValueArray() | |||
*/ | |||
public function getValueBigInt(string $app, string $key, int|float $default = 0, bool $lazy = false): int|float; | |||
/** | |||
* Get config value assigned to a config key. | |||
* If config key is not found in database, default value is returned. | |||
* If config key is set as lazy loaded, the $lazy argument needs to be set to TRUE. | |||
* | |||
* @param string $app id of the app | |||
* @param string $key config key | |||
* @param float $default default value | |||
* @param bool $lazy search within lazy loaded config | |||
* | |||
* @return float stored config value or $default if not set in database | |||
* @since 29.0.0 | |||
* @see IAppConfig for explanation about lazy loading | |||
* @see getValueString() | |||
* @see getValueInt() | |||
* @see getValueBigInt() | |||
* @see getValueBool() | |||
* @see getValueArray() | |||
*/ | |||
public function getValueFloat(string $app, string $key, float $default = 0, bool $lazy = false): float; | |||
/** | |||
* Get config value assigned to a config key. | |||
* If config key is not found in database, default value is returned. | |||
* If config key is set as lazy loaded, the $lazy argument needs to be set to TRUE. | |||
* | |||
* @param string $app id of the app | |||
* @param string $key config key | |||
* @param bool $default default value | |||
* @param bool $lazy search within lazy loaded config | |||
* | |||
* @return bool stored config value or $default if not set in database | |||
* @since 29.0.0 | |||
* @see IAppConfig for explanation about lazy loading | |||
* @see getValueString() | |||
* @see getValueInt() | |||
* @see getValueBigInt() | |||
* @see getValueFloat() | |||
* @see getValueArray() | |||
*/ | |||
public function getValueBool(string $app, string $key, bool $default = false, bool $lazy = false): bool; | |||
/** | |||
* Get config value assigned to a config key. | |||
* If config key is not found in database, default value is returned. | |||
* If config key is set as lazy loaded, the $lazy argument needs to be set to TRUE. | |||
* | |||
* @param string $app id of the app | |||
* @param string $key config key | |||
* @param array $default default value | |||
* @param bool $lazy search within lazy loaded config | |||
* | |||
* @return array stored config value or $default if not set in database | |||
* @since 29.0.0 | |||
* @see IAppConfig for explanation about lazy loading | |||
* @see getValueString() | |||
* @see getValueInt() | |||
* @see getValueBigInt() | |||
* @see getValueFloat() | |||
* @see getValueBool() | |||
*/ | |||
public function getValueArray(string $app, string $key, array $default = [], bool $lazy = false): array; | |||
/** | |||
* returns the type of config value | |||
* | |||
* **WARNING:** ignore lazy filtering, all config values are loaded from database | |||
* | |||
* @param string $app id of the app | |||
* @param string $key config key | |||
* | |||
* @return int | |||
* @throws AppConfigUnknownKeyException | |||
* @since 29.0.0 | |||
* @see VALUE_STRING | |||
* @see VALUE_INT | |||
* @see VALUE_FLOAT | |||
* @see VALUE_BOOL | |||
* @see VALUE_ARRAY | |||
*/ | |||
public function getValueType(string $app, string $key): int; | |||
/** | |||
* Store a config key and its value in database | |||
* | |||
* If config key is already known with the exact same config value, the database is not updated. | |||
* If config key is not supposed to be read during the boot of the cloud, it is advised to set it as lazy loaded. | |||
* | |||
* If config value was previously stored as sensitive or lazy loaded, status cannot be altered without using {@see deleteKey()} first | |||
* | |||
* @param string $app id of the app | |||
* @param string $key config key | |||
* @param string $value config value | |||
* @param bool $sensitive if TRUE value will be hidden when listing config values. | |||
* @param bool $lazy set config as lazy loaded | |||
* | |||
* @return bool TRUE if value was different, therefor updated in database | |||
* @since 29.0.0 | |||
* @see IAppConfig for explanation about lazy grouping | |||
* @see setValueInt() | |||
* @see setValueBigInt() | |||
* @see setValueFloat() | |||
* @see setValueBool() | |||
* @see setValueArray() | |||
*/ | |||
public function setValueString(string $app, string $key, string $value, bool $lazy = false, bool $sensitive = false): bool; | |||
/** | |||
* Store a config key and its value in database | |||
* | |||
* If config key is already known with the exact same config value, the database is not updated. | |||
* If config key is not supposed to be read during the boot of the cloud, it is advised to set it as lazy loaded. | |||
* | |||
* If config value was previously stored as sensitive or lazy loaded, status cannot be altered without using {@see deleteKey()} first | |||
* | |||
* @param string $app id of the app | |||
* @param string $key config key | |||
* @param int $value config value | |||
* @param bool $sensitive if TRUE value will be hidden when listing config values. | |||
* @param bool $lazy set config as lazy loaded | |||
* | |||
* @return bool TRUE if value was different, therefor updated in database | |||
* @since 29.0.0 | |||
* @see IAppConfig for explanation about lazy grouping | |||
* @see setValueString() | |||
* @see setValueBigInt() | |||
* @see setValueFloat() | |||
* @see setValueBool() | |||
* @see setValueArray() | |||
*/ | |||
public function setValueInt(string $app, string $key, int $value, bool $lazy = false, bool $sensitive = false): bool; | |||
/** | |||
* Store a config key and its value in database | |||
* | |||
* If config key is already known with the exact same config value, the database is not updated. | |||
* If config key is not supposed to be read during the boot of the cloud, it is advised to set it as lazy loaded. | |||
* | |||
* If config value was previously stored as sensitive or lazy loaded, status cannot be altered without using {@see deleteKey()} first | |||
* | |||
* @param string $app id of the app | |||
* @param string $key config key | |||
* @param int|float $value config value | |||
* @param bool $sensitive if TRUE value will be hidden when listing config values. | |||
* @param bool $lazy set config as lazy loaded | |||
* | |||
* @return bool TRUE if value was different, therefor updated in database | |||
* @since 29.0.0 | |||
* @see IAppConfig for explanation about lazy grouping | |||
* @see setValueString() | |||
* @see setValueBigInt() | |||
* @see setValueFloat() | |||
* @see setValueBool() | |||
* @see setValueArray() | |||
*/ | |||
public function setValueBigInt(string $app, string $key, int|float $value, bool $lazy = false, bool $sensitive = false): bool; | |||
/** | |||
* Store a config key and its value in database | |||
* | |||
* If config key is already known with the exact same config value, the database is not updated. | |||
* If config key is not supposed to be read during the boot of the cloud, it is advised to set it as lazy loaded. | |||
* | |||
* If config value was previously stored as sensitive or lazy loaded, status cannot be altered without using {@see deleteKey()} first | |||
* | |||
* @param string $app id of the app | |||
* @param string $key config key | |||
* @param float $value config value | |||
* @param bool $sensitive if TRUE value will be hidden when listing config values. | |||
* @param bool $lazy set config as lazy loaded | |||
* | |||
* @return bool TRUE if value was different, therefor updated in database | |||
* @since 29.0.0 | |||
* @see IAppConfig for explanation about lazy grouping | |||
* @see setValueString() | |||
* @see setValueInt() | |||
* @see setValueBigInt() | |||
* @see setValueBool() | |||
* @see setValueArray() | |||
*/ | |||
public function setValueFloat(string $app, string $key, float $value, bool $lazy = false, bool $sensitive = false): bool; | |||
/** | |||
* Store a config key and its value in database | |||
* | |||
* If config key is already known with the exact same config value, the database is not updated. | |||
* If config key is not supposed to be read during the boot of the cloud, it is advised to set it as lazy loaded. | |||
* | |||
* If config value was previously stored as lazy loaded, status cannot be altered without using {@see deleteKey()} first | |||
* | |||
* @param string $app id of the app | |||
* @param string $key config key | |||
* @param bool $value config value | |||
* @param bool $lazy set config as lazy loaded | |||
* | |||
* @return bool TRUE if value was different, therefor updated in database | |||
* @since 29.0.0 | |||
* @see IAppConfig for explanation about lazy grouping | |||
* @see setValueString() | |||
* @see setValueInt() | |||
* @see setValueBigInt() | |||
* @see setValueFloat() | |||
* @see setValueArray() | |||
*/ | |||
public function setValueBool(string $app, string $key, bool $value, bool $lazy = false): bool; | |||
/** | |||
* Store a config key and its value in database | |||
* | |||
* If config key is already known with the exact same config value, the database is not updated. | |||
* If config key is not supposed to be read during the boot of the cloud, it is advised to set it as lazy loaded. | |||
* | |||
* If config value was previously stored as sensitive or lazy loaded, status cannot be altered without using {@see deleteKey()} first | |||
* | |||
* @param string $app id of the app | |||
* @param string $key config key | |||
* @param array $value config value | |||
* @param bool $sensitive if TRUE value will be hidden when listing config values. | |||
* @param bool $lazy set config as lazy loaded | |||
* | |||
* @return bool TRUE if value was different, therefor updated in database | |||
* @since 29.0.0 | |||
* @see IAppConfig for explanation about lazy grouping | |||
* @see setValueString() | |||
* @see setValueInt() | |||
* @see setValueBigInt() | |||
* @see setValueFloat() | |||
* @see setValueBool() | |||
*/ | |||
public function setValueArray(string $app, string $key, array $value, bool $lazy = false, bool $sensitive = false): bool; | |||
/** | |||
* switch sensitive status of a config value | |||
* | |||
* **WARNING:** ignore lazy filtering, all config values are loaded from database | |||
* | |||
* @param string $app id of the app | |||
* @param string $key config key | |||
* @param bool $sensitive TRUE to set as sensitive, FALSE to unset | |||
* | |||
* @return bool TRUE if database update were necessary | |||
* @since 29.0.0 | |||
*/ | |||
public function updateSensitive(string $app, string $key, bool $sensitive): bool; | |||
/** | |||
* switch lazy loading status of a config value | |||
* | |||
* @param string $app id of the app | |||
* @param string $key config key | |||
* @param bool $lazy TRUE to set as lazy loaded, FALSE to unset | |||
* | |||
* @return bool TRUE if database update was necessary | |||
* @since 29.0.0 | |||
*/ | |||
public function updateLazy(string $app, string $key, bool $lazy): bool; | |||
/** | |||
* returns an array contains details about a config value | |||
* | |||
* ``` | |||
* [ | |||
* "app" => "myapp", | |||
* "key" => "mykey", | |||
* "value" => "its_value", | |||
* "lazy" => false, | |||
* "type" => 4, | |||
* "typeString" => "string", | |||
* 'sensitive' => true | |||
* ] | |||
* ``` | |||
* | |||
* @param string $app id of the app | |||
* @param string $key config key | |||
* | |||
* @return array | |||
* @throws AppConfigUnknownKeyException if config key is not known in database | |||
* @since 29.0.0 | |||
*/ | |||
public function getDetails(string $app, string $key): array; | |||
/** | |||
* Convert string like 'string', 'integer', 'float', 'bool' or 'array' to | |||
* to bitflag {@see VALUE_STRING}, {@see VALUE_INT}, {@see VALUE_FLOAT}, | |||
* {@see VALUE_BOOL} and {@see VALUE_ARRAY} | |||
* | |||
* @param string $type | |||
* | |||
* @return int | |||
* @since 29.0.0 | |||
*/ | |||
public function convertTypeToInt(string $type): int; | |||
/** | |||
* Convert bitflag {@see VALUE_STRING}, {@see VALUE_INT}, {@see VALUE_FLOAT}, | |||
* {@see VALUE_BOOL} and {@see VALUE_ARRAY} to human-readable string | |||
* | |||
* @param int $type | |||
* | |||
* @return string | |||
* @since 29.0.0 | |||
*/ | |||
public function convertTypeToString(int $type): string; | |||
/** | |||
* Delete single config key from database. | |||
* | |||
* @param string $app id of the app | |||
* @param string $key config key | |||
* @since 29.0.0 | |||
*/ | |||
public function deleteKey(string $app, string $key): void; | |||
/** | |||
* delete all config keys linked to an app | |||
* | |||
* @param string $app id of the app | |||
* @since 29.0.0 | |||
*/ | |||
public function deleteApp(string $app): void; | |||
/** | |||
* Clear the cache. | |||
* | |||
* The cache will be rebuilt only the next time a config value is requested. | |||
* | |||
* @param bool $reload set to TRUE to refill cache instantly after clearing it | |||
* @since 29.0.0 | |||
*/ | |||
public function clearCache(bool $reload = false): void; | |||
/** | |||
* get multiply values, either the app or key can be used as wildcard by setting it to false | |||
* | |||
* @param string|false $key | |||
* @param string|false $app | |||
* | |||
* @return array|false | |||
* @since 7.0.0 | |||
* @deprecated 29.0.0 Use {@see getAllValues()} or {@see searchValues()} | |||
*/ | |||
public function getValues($app, $key); | |||
@@ -55,18 +567,10 @@ interface IAppConfig { | |||
* get all values of the app or and filters out sensitive data | |||
* | |||
* @param string $app | |||
* | |||
* @return array | |||
* @since 12.0.0 | |||
* @deprecated 29.0.0 Use {@see getAllValues()} or {@see searchValues()} | |||
*/ | |||
public function getFilteredValues($app); | |||
/** | |||
* Get all apps using the config | |||
* @return string[] an array of app ids | |||
* | |||
* This function returns a list of all apps that have at least one | |||
* entry in the appconfig table. | |||
* @since 7.0.0 | |||
*/ | |||
public function getApps(); | |||
} |
@@ -126,6 +126,7 @@ interface IConfig { | |||
* @param string $appName the appName that we stored the value under | |||
* @return string[] the keys stored for the app | |||
* @since 8.0.0 | |||
* @deprecated 29.0.0 Use {@see IAppConfig} directly | |||
*/ | |||
public function getAppKeys($appName); | |||
@@ -137,6 +138,7 @@ interface IConfig { | |||
* @param string $value the value that should be stored | |||
* @return void | |||
* @since 6.0.0 | |||
* @deprecated 29.0.0 Use {@see IAppConfig} directly | |||
*/ | |||
public function setAppValue($appName, $key, $value); | |||
@@ -146,8 +148,10 @@ interface IConfig { | |||
* @param string $appName the appName that we stored the value under | |||
* @param string $key the key of the value, under which it was saved | |||
* @param string $default the default value to be returned if the value isn't set | |||
* | |||
* @return string the saved value | |||
* @since 6.0.0 - parameter $default was added in 7.0.0 | |||
* @deprecated 29.0.0 Use {@see IAppConfig} directly | |||
*/ | |||
public function getAppValue($appName, $key, $default = ''); | |||
@@ -157,6 +161,7 @@ interface IConfig { | |||
* @param string $appName the appName that we stored the value under | |||
* @param string $key the key of the value, under which it was saved | |||
* @since 8.0.0 | |||
* @deprecated 29.0.0 Use {@see IAppConfig} directly | |||
*/ | |||
public function deleteAppValue($appName, $key); | |||
@@ -165,6 +170,7 @@ interface IConfig { | |||
* | |||
* @param string $appName the appName the configs are stored under | |||
* @since 8.0.0 | |||
* @deprecated 29.0.0 Use {@see IAppConfig} directly | |||
*/ | |||
public function deleteAppValues($appName); | |||
@@ -21,8 +21,9 @@ | |||
namespace Tests\Core\Command\Config\App; | |||
use OC\AppConfig; | |||
use OC\Core\Command\Config\App\GetConfig; | |||
use OCP\IConfig; | |||
use OCP\Exceptions\AppConfigUnknownKeyException; | |||
use Symfony\Component\Console\Input\InputInterface; | |||
use Symfony\Component\Console\Output\OutputInterface; | |||
use Test\TestCase; | |||
@@ -42,13 +43,13 @@ class GetConfigTest extends TestCase { | |||
protected function setUp(): void { | |||
parent::setUp(); | |||
$config = $this->config = $this->getMockBuilder(IConfig::class) | |||
$config = $this->config = $this->getMockBuilder(AppConfig::class) | |||
->disableOriginalConstructor() | |||
->getMock(); | |||
$this->consoleInput = $this->getMockBuilder(InputInterface::class)->getMock(); | |||
$this->consoleOutput = $this->getMockBuilder(OutputInterface::class)->getMock(); | |||
/** @var \OCP\IConfig $config */ | |||
/** @var \OCP\IAppConfig $config */ | |||
$this->command = new GetConfig($config); | |||
} | |||
@@ -108,20 +109,22 @@ class GetConfigTest extends TestCase { | |||
* @param string $expectedMessage | |||
*/ | |||
public function testGet($configName, $value, $configExists, $defaultValue, $hasDefault, $outputFormat, $expectedReturn, $expectedMessage) { | |||
$this->config->expects($this->atLeastOnce()) | |||
->method('getAppKeys') | |||
->with('app-name') | |||
->willReturn($configExists ? [$configName] : []); | |||
if (!$expectedReturn) { | |||
if ($configExists) { | |||
$this->config->expects($this->once()) | |||
->method('getAppValue') | |||
->method('getDetails') | |||
->with('app-name', $configName) | |||
->willReturn($value); | |||
->willReturn(['value' => $value]); | |||
} | |||
} | |||
if (!$configExists) { | |||
$this->config->expects($this->once()) | |||
->method('getDetails') | |||
->with('app-name', $configName) | |||
->willThrowException(new AppConfigUnknownKeyException()); | |||
} | |||
$this->consoleInput->expects($this->exactly(2)) | |||
->method('getArgument') | |||
->willReturnMap([ |
@@ -21,8 +21,10 @@ | |||
namespace Tests\Core\Command\Config\App; | |||
use OC\AppConfig; | |||
use OC\Core\Command\Config\App\SetConfig; | |||
use OCP\IConfig; | |||
use OCP\Exceptions\AppConfigUnknownKeyException; | |||
use OCP\IAppConfig; | |||
use Symfony\Component\Console\Input\InputInterface; | |||
use Symfony\Component\Console\Output\OutputInterface; | |||
use Test\TestCase; | |||
@@ -42,13 +44,13 @@ class SetConfigTest extends TestCase { | |||
protected function setUp(): void { | |||
parent::setUp(); | |||
$config = $this->config = $this->getMockBuilder(IConfig::class) | |||
$config = $this->config = $this->getMockBuilder(AppConfig::class) | |||
->disableOriginalConstructor() | |||
->getMock(); | |||
$this->consoleInput = $this->getMockBuilder(InputInterface::class)->getMock(); | |||
$this->consoleOutput = $this->getMockBuilder(OutputInterface::class)->getMock(); | |||
/** @var \OCP\IConfig $config */ | |||
/** @var \OCP\IAppConfig $config */ | |||
$this->command = new SetConfig($config); | |||
} | |||
@@ -85,14 +87,24 @@ class SetConfigTest extends TestCase { | |||
* @param string $expectedMessage | |||
*/ | |||
public function testSet($configName, $newValue, $configExists, $updateOnly, $updated, $expectedMessage) { | |||
$this->config->expects($this->once()) | |||
->method('getAppKeys') | |||
->with('app-name') | |||
->willReturn($configExists ? [$configName] : []); | |||
$this->config->expects($this->any()) | |||
->method('hasKey') | |||
->with('app-name', $configName) | |||
->willReturn($configExists); | |||
if (!$configExists) { | |||
$this->config->expects($this->any()) | |||
->method('getValueType') | |||
->willThrowException(new AppConfigUnknownKeyException()); | |||
} else { | |||
$this->config->expects($this->any()) | |||
->method('getValueType') | |||
->willReturn(IAppConfig::VALUE_MIXED); | |||
} | |||
if ($updated) { | |||
$this->config->expects($this->once()) | |||
->method('setAppValue') | |||
->method('setValueMixed') | |||
->with('app-name', $configName, $newValue); | |||
} | |||
@@ -104,13 +116,19 @@ class SetConfigTest extends TestCase { | |||
]); | |||
$this->consoleInput->expects($this->any()) | |||
->method('getOption') | |||
->with('value') | |||
->willReturn($newValue); | |||
->willReturnMap([ | |||
['value', $newValue], | |||
['lazy', null], | |||
['sensitive', null], | |||
['no-interaction', true], | |||
]); | |||
$this->consoleInput->expects($this->any()) | |||
->method('hasParameterOption') | |||
->with('--update-only') | |||
->willReturn($updateOnly); | |||
->willReturnMap([ | |||
['--type', false, false], | |||
['--value', false, true], | |||
['--update-only', false, $updateOnly] | |||
]); | |||
$this->consoleOutput->expects($this->any()) | |||
->method('writeln') | |||
->with($this->stringContains($expectedMessage)); |
@@ -10,8 +10,9 @@ | |||
namespace Test; | |||
use OC\AppConfig; | |||
use OC\DB\Connection; | |||
use OCP\IConfig; | |||
use OCP\IDBConnection; | |||
use Psr\Log\LoggerInterface; | |||
/** | |||
* Class AppConfigTest | |||
@@ -24,15 +25,17 @@ class AppConfigTest extends TestCase { | |||
/** @var \OCP\IAppConfig */ | |||
protected $appConfig; | |||
/** @var Connection */ | |||
protected $connection; | |||
protected IDBConnection $connection; | |||
private LoggerInterface $logger; | |||
protected $originalConfig; | |||
protected function setUp(): void { | |||
parent::setUp(); | |||
$this->connection = \OC::$server->get(Connection::class); | |||
$this->connection = \OC::$server->get(IDBConnection::class); | |||
$this->logger = \OC::$server->get(LoggerInterface::class); | |||
$sql = $this->connection->getQueryBuilder(); | |||
$sql->select('*') | |||
->from('appconfig'); | |||
@@ -44,20 +47,20 @@ class AppConfigTest extends TestCase { | |||
$sql->delete('appconfig'); | |||
$sql->execute(); | |||
$this->overwriteService(AppConfig::class, new \OC\AppConfig($this->connection)); | |||
$this->overwriteService(AppConfig::class, new \OC\AppConfig($this->connection, $this->logger)); | |||
$sql = $this->connection->getQueryBuilder(); | |||
$sql->insert('appconfig') | |||
->values([ | |||
'appid' => $sql->createParameter('appid'), | |||
'configkey' => $sql->createParameter('configkey'), | |||
'configvalue' => $sql->createParameter('configvalue'), | |||
'configvalue' => $sql->createParameter('configvalue') | |||
]); | |||
$sql->setParameters([ | |||
'appid' => 'testapp', | |||
'configkey' => 'enabled', | |||
'configvalue' => 'true', | |||
'configvalue' => 'true' | |||
])->execute(); | |||
$sql->setParameters([ | |||
'appid' => 'testapp', | |||
@@ -125,12 +128,16 @@ class AppConfigTest extends TestCase { | |||
'appid' => $sql->createParameter('appid'), | |||
'configkey' => $sql->createParameter('configkey'), | |||
'configvalue' => $sql->createParameter('configvalue'), | |||
'lazy' => $sql->createParameter('lazy'), | |||
'type' => $sql->createParameter('type'), | |||
]); | |||
foreach ($this->originalConfig as $configs) { | |||
$sql->setParameter('appid', $configs['appid']) | |||
->setParameter('configkey', $configs['configkey']) | |||
->setParameter('configvalue', $configs['configvalue']); | |||
->setParameter('configvalue', $configs['configvalue']) | |||
->setParameter('lazy', ($configs['lazy'] === '1') ? '1' : '0') | |||
->setParameter('type', $configs['type']); | |||
$sql->execute(); | |||
} | |||
@@ -139,7 +146,7 @@ class AppConfigTest extends TestCase { | |||
} | |||
public function testGetApps() { | |||
$config = new \OC\AppConfig(\OC::$server->get(Connection::class)); | |||
$config = new \OC\AppConfig(\OC::$server->get(IDBConnection::class), \OC::$server->get(LoggerInterface::class)); | |||
$this->assertEqualsCanonicalizing([ | |||
'anotherapp', | |||
@@ -150,7 +157,7 @@ class AppConfigTest extends TestCase { | |||
} | |||
public function testGetKeys() { | |||
$config = new \OC\AppConfig(\OC::$server->get(Connection::class)); | |||
$config = new \OC\AppConfig(\OC::$server->get(IDBConnection::class), \OC::$server->get(LoggerInterface::class)); | |||
$keys = $config->getKeys('testapp'); | |||
$this->assertEqualsCanonicalizing([ | |||
@@ -163,7 +170,7 @@ class AppConfigTest extends TestCase { | |||
} | |||
public function testGetValue() { | |||
$config = new \OC\AppConfig(\OC::$server->get(Connection::class)); | |||
$config = new \OC\AppConfig(\OC::$server->get(IDBConnection::class), \OC::$server->get(LoggerInterface::class)); | |||
$value = $config->getValue('testapp', 'installed_version'); | |||
$this->assertConfigKey('testapp', 'installed_version', $value); | |||
@@ -176,7 +183,7 @@ class AppConfigTest extends TestCase { | |||
} | |||
public function testHasKey() { | |||
$config = new \OC\AppConfig(\OC::$server->get(Connection::class)); | |||
$config = new \OC\AppConfig(\OC::$server->get(IDBConnection::class), \OC::$server->get(LoggerInterface::class)); | |||
$this->assertTrue($config->hasKey('testapp', 'installed_version')); | |||
$this->assertFalse($config->hasKey('testapp', 'nonexistant')); | |||
@@ -184,13 +191,13 @@ class AppConfigTest extends TestCase { | |||
} | |||
public function testSetValueUpdate() { | |||
$config = new \OC\AppConfig(\OC::$server->get(Connection::class)); | |||
$config = new \OC\AppConfig(\OC::$server->get(IDBConnection::class), \OC::$server->get(LoggerInterface::class)); | |||
$this->assertEquals('1.2.3', $config->getValue('testapp', 'installed_version')); | |||
$this->assertConfigKey('testapp', 'installed_version', '1.2.3'); | |||
$wasModified = $config->setValue('testapp', 'installed_version', '1.2.3'); | |||
if (!(\OC::$server->get(Connection::class) instanceof \OC\DB\OracleConnection)) { | |||
if (!(\OC::$server->get(IDBConnection::class) instanceof \OC\DB\OracleConnection)) { | |||
$this->assertFalse($wasModified); | |||
} | |||
@@ -208,7 +215,7 @@ class AppConfigTest extends TestCase { | |||
} | |||
public function testSetValueInsert() { | |||
$config = new \OC\AppConfig(\OC::$server->get(Connection::class)); | |||
$config = new \OC\AppConfig(\OC::$server->get(IDBConnection::class), \OC::$server->get(LoggerInterface::class)); | |||
$this->assertFalse($config->hasKey('someapp', 'somekey')); | |||
$this->assertNull($config->getValue('someapp', 'somekey')); | |||
@@ -220,13 +227,13 @@ class AppConfigTest extends TestCase { | |||
$this->assertConfigKey('someapp', 'somekey', 'somevalue'); | |||
$wasInserted = $config->setValue('someapp', 'somekey', 'somevalue'); | |||
if (!(\OC::$server->get(Connection::class) instanceof \OC\DB\OracleConnection)) { | |||
if (!(\OC::$server->get(IDBConnection::class) instanceof \OC\DB\OracleConnection)) { | |||
$this->assertFalse($wasInserted); | |||
} | |||
} | |||
public function testDeleteKey() { | |||
$config = new \OC\AppConfig(\OC::$server->get(Connection::class)); | |||
$config = new \OC\AppConfig(\OC::$server->get(IDBConnection::class), \OC::$server->get(LoggerInterface::class)); | |||
$this->assertTrue($config->hasKey('testapp', 'deletethis')); | |||
@@ -248,7 +255,7 @@ class AppConfigTest extends TestCase { | |||
} | |||
public function testDeleteApp() { | |||
$config = new \OC\AppConfig(\OC::$server->get(Connection::class)); | |||
$config = new \OC\AppConfig(\OC::$server->get(IDBConnection::class), \OC::$server->get(LoggerInterface::class)); | |||
$this->assertTrue($config->hasKey('someapp', 'otherkey')); | |||
@@ -268,7 +275,7 @@ class AppConfigTest extends TestCase { | |||
} | |||
public function testGetValuesNotAllowed() { | |||
$config = new \OC\AppConfig(\OC::$server->get(Connection::class)); | |||
$config = new \OC\AppConfig(\OC::$server->get(IDBConnection::class), \OC::$server->get(LoggerInterface::class)); | |||
$this->assertFalse($config->getValues('testapp', 'enabled')); | |||
@@ -276,7 +283,7 @@ class AppConfigTest extends TestCase { | |||
} | |||
public function testGetValues() { | |||
$config = new \OC\AppConfig(\OC::$server->get(Connection::class)); | |||
$config = new \OC\AppConfig(\OC::$server->get(IDBConnection::class), \OC::$server->get(LoggerInterface::class)); | |||
$sql = \OC::$server->getDatabaseConnection()->getQueryBuilder(); | |||
$sql->select(['configkey', 'configvalue']) | |||
@@ -310,20 +317,10 @@ class AppConfigTest extends TestCase { | |||
} | |||
public function testGetFilteredValues() { | |||
/** @var \OC\AppConfig|\PHPUnit\Framework\MockObject\MockObject $config */ | |||
$config = $this->getMockBuilder(\OC\AppConfig::class) | |||
->setConstructorArgs([\OC::$server->get(Connection::class)]) | |||
->setMethods(['getValues']) | |||
->getMock(); | |||
$config->expects($this->once()) | |||
->method('getValues') | |||
->with('user_ldap', false) | |||
->willReturn([ | |||
'ldap_agent_password' => 'secret', | |||
's42ldap_agent_password' => 'secret', | |||
'ldap_dn' => 'dn', | |||
]); | |||
$config = new \OC\AppConfig(\OC::$server->get(IDBConnection::class), \OC::$server->get(LoggerInterface::class)); | |||
$config->setValue('user_ldap', 'ldap_agent_password', 'secret'); | |||
$config->setValue('user_ldap', 's42ldap_agent_password', 'secret'); | |||
$config->setValue('user_ldap', 'ldap_dn', 'dn'); | |||
$values = $config->getFilteredValues('user_ldap'); | |||
$this->assertEquals([ | |||
@@ -334,8 +331,8 @@ class AppConfigTest extends TestCase { | |||
} | |||
public function testSettingConfigParallel() { | |||
$appConfig1 = new \OC\AppConfig(\OC::$server->get(Connection::class)); | |||
$appConfig2 = new \OC\AppConfig(\OC::$server->get(Connection::class)); | |||
$appConfig1 = new \OC\AppConfig(\OC::$server->get(IDBConnection::class), \OC::$server->get(LoggerInterface::class)); | |||
$appConfig2 = new \OC\AppConfig(\OC::$server->get(IDBConnection::class), \OC::$server->get(LoggerInterface::class)); | |||
$appConfig1->getValue('testapp', 'foo', 'v1'); | |||
$appConfig2->getValue('testapp', 'foo', 'v1'); | |||
@@ -50,6 +50,7 @@ class FunctionBuilderTest extends TestCase { | |||
if ($real) { | |||
$this->addDummyData(); | |||
$query->where($query->expr()->eq('appid', $query->createNamedParameter('group_concat'))); | |||
$query->orderBy('configkey', 'asc'); | |||
} | |||
$query->select($query->func()->concat(...$arguments)); |