Skip to content

Commit

Permalink
fix(lexicon): syntax
Browse files Browse the repository at this point in the history
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
  • Loading branch information
ArtificialOwl committed Jan 9, 2025
1 parent a098636 commit e65fb5c
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 23 deletions.
9 changes: 1 addition & 8 deletions lib/private/Config/Lexicon/CoreConfigLexicon.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-only
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

namespace OC\Config\Lexicon;
Expand All @@ -17,19 +17,13 @@
* ConfigLexicon for 'core' app/user configs
*/
class CoreConfigLexicon implements IConfigLexicon {
/**
* @inheritDoc
* @return ConfigLexiconStrictness
* @since 31.0.0
*/
public function getStrictness(): ConfigLexiconStrictness {
return ConfigLexiconStrictness::IGNORE;
}

/**
* @inheritDoc
* @return ConfigLexiconEntry[]
* @since 31.0.0
*/
public function getAppConfigs(): array {
return [
Expand All @@ -40,7 +34,6 @@ public function getAppConfigs(): array {
/**
* @inheritDoc
* @return ConfigLexiconEntry[]
* @since 31.0.0
*/
public function getUserConfigs(): array {
return [
Expand Down
41 changes: 27 additions & 14 deletions lib/private/Config/UserConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,8 @@ public function isLazy(string $userId, string $app, string $key): bool {
// there is a huge probability the non-lazy config are already loaded
// meaning that we can start by only checking if a current non-lazy key exists
if ($this->hasKey($userId, $app, $key, false)) {
return false; // meaning key is not lazy.
// meaning key is not lazy.
return false;
}

// as key is not found as non-lazy, we load and search in the lazy config
Expand Down Expand Up @@ -264,7 +265,8 @@ public function getValues(
$values = array_filter(
$this->formatAppValues($userId, $app, ($this->fastCache[$userId][$app] ?? []) + ($this->lazyCache[$userId][$app] ?? []), $filtered),
function (string $key) use ($prefix): bool {
return str_starts_with($key, $prefix); // filter values based on $prefix
// filter values based on $prefix
return str_starts_with($key, $prefix);
}, ARRAY_FILTER_USE_KEY
);

Expand Down Expand Up @@ -713,7 +715,8 @@ private function getTypedValue(
): string {
$this->assertParams($userId, $app, $key);
if (!$this->matchAndApplyLexiconDefinition($userId, $app, $key, $lazy, $type, default: $default)) {
return $default; // returns default if strictness of lexicon is set to WARNING (block and report)
// returns default if strictness of lexicon is set to WARNING (block and report)
return $default;
}
$this->loadConfig($userId, $lazy);

Expand Down Expand Up @@ -1048,7 +1051,8 @@ private function setTypedValue(
): bool {
$this->assertParams($userId, $app, $key);
if (!$this->matchAndApplyLexiconDefinition($userId, $app, $key, $lazy, $type, $flags)) {
return false; // returns false as database is not updated
// returns false as database is not updated
return false;
}
$this->loadConfig($userId, $lazy);

Expand Down Expand Up @@ -1101,7 +1105,8 @@ private function setTypedValue(
$inserted = true;
} catch (DBException $e) {
if ($e->getReason() !== DBException::REASON_UNIQUE_CONSTRAINT_VIOLATION) {
throw $e; // TODO: throw exception or just log and returns false !?
// TODO: throw exception or just log and returns false !?
throw $e;
}
}
}
Expand Down Expand Up @@ -1196,7 +1201,8 @@ private function setTypedValue(
public function updateType(string $userId, string $app, string $key, ValueType $type = ValueType::MIXED): bool {
$this->assertParams($userId, $app, $key);
$this->loadConfigAll($userId);
$this->isLazy($userId, $app, $key); // confirm key exists
// confirm key exists
$this->isLazy($userId, $app, $key);

$update = $this->connection->getQueryBuilder();
$update->update('preferences')
Expand Down Expand Up @@ -1288,7 +1294,8 @@ public function updateGlobalSensitive(string $app, string $key, bool $sensitive)
}
}

$this->clearCacheAll(); // we clear all cache
// we clear all cache
$this->clearCacheAll();
}

/**
Expand Down Expand Up @@ -1371,7 +1378,8 @@ public function updateGlobalIndexed(string $app, string $key, bool $indexed): vo
}
}

$this->clearCacheAll(); // we clear all cache
// we clear all cache
$this->clearCacheAll();
}

/**
Expand Down Expand Up @@ -1794,6 +1802,14 @@ private function convertTypedValue(string $value, ValueType $type): string|int|f
}


/**
* will change referenced $value with the decrypted value in case of encrypted (sensitive value)
*
* @param string $userId
* @param string $app
* @param string $key
* @param string $value
*/
private function decryptSensitiveValue(string $userId, string $app, string $key, string &$value): void {
if (!$this->isFlagged(self::FLAG_SENSITIVE, $this->valueDetails[$userId][$app][$key]['flags'] ?? 0)) {
return;
Expand Down Expand Up @@ -1821,6 +1837,7 @@ private function decryptSensitiveValue(string $userId, string $app, string $key,
*
* @throws UnknownKeyException
* @throws TypeConflictException
* @return bool FALSE if conflict with defined lexicon were observed in the process
*/
private function matchAndApplyLexiconDefinition(
string $userId,
Expand Down Expand Up @@ -1874,16 +1891,12 @@ private function matchAndApplyLexiconDefinition(
* ],
*
* The entry is converted to string to fit the expected type when managing default value
*
* @param string $appId
* @param ConfigLexiconEntry $configValue
*
* @return string|null
*/
private function getSystemDefault(string $appId, ConfigLexiconEntry $configValue): ?string {
$default = $this->config->getSystemValue('lexicon.default.userconfig', [])[$appId][$configValue->getKey()] ?? null;
if ($default === null) {
return null; // no system default, using default default.
// no system default, using default default.
return null;
}

return $configValue->convertToString($default);
Expand Down
2 changes: 1 addition & 1 deletion lib/unstable/Config/Lexicon/ConfigLexiconEntry.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-only
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

namespace NCU\Config\Lexicon;
Expand Down

0 comments on commit e65fb5c

Please sign in to comment.