From 46ced9df22af2be4fddcc5fc57789a7bd2e38faa Mon Sep 17 00:00:00 2001 From: Maxence Lange Date: Fri, 29 Aug 2025 11:41:08 -0100 Subject: [PATCH] fix(lexicon): send single notice/warning when using unknown config key Signed-off-by: Maxence Lange --- lib/private/AppConfig.php | 20 +++++++++++++------- lib/private/Config/UserConfig.php | 18 +++++++++++++----- 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/lib/private/AppConfig.php b/lib/private/AppConfig.php index a78baee859a8a..50fa23e516e5f 100644 --- a/lib/private/AppConfig.php +++ b/lib/private/AppConfig.php @@ -69,6 +69,8 @@ class AppConfig implements IAppConfig { /** @var array, aliases: array, strictness: Strictness}> ['app_id' => ['strictness' => ConfigLexiconStrictness, 'entries' => ['config_key' => ConfigLexiconEntry[]]] */ private array $configLexiconDetails = []; private bool $ignoreLexiconAliases = false; + private array $strictnessApplied = []; + /** @var ?array */ private ?array $appVersionsCache = null; private ?ICache $localCache = null; @@ -1698,7 +1700,7 @@ private function matchAndApplyLexiconDefinition( } if (!array_key_exists($key, $configDetails['entries'])) { - return $this->applyLexiconStrictness($configDetails['strictness'], 'The app config key ' . $app . '/' . $key . ' is not defined in the config lexicon'); + return $this->applyLexiconStrictness($configDetails['strictness'], $app . '/' . $key); } // if lazy is NULL, we ignore all check on the type/lazyness/default from Lexicon @@ -1743,22 +1745,26 @@ private function matchAndApplyLexiconDefinition( * @throws AppConfigUnknownKeyException if strictness implies exception * @see \OCP\Config\Lexicon\ILexicon::getStrictness() */ - private function applyLexiconStrictness( - ?Strictness $strictness, - string $line = '', - ): bool { + private function applyLexiconStrictness(?Strictness $strictness, string $configAppKey): bool { if ($strictness === null) { return true; } + $line = 'The app config key ' . $configAppKey . ' is not defined in the config lexicon'; switch ($strictness) { case Strictness::IGNORE: return true; case Strictness::NOTICE: - $this->logger->notice($line); + if (!in_array($configAppKey, $this->strictnessApplied, true)) { + $this->strictnessApplied[] = $configAppKey; + $this->logger->notice($line); + } return true; case Strictness::WARNING: - $this->logger->warning($line); + if (!in_array($configAppKey, $this->strictnessApplied, true)) { + $this->strictnessApplied[] = $configAppKey; + $this->logger->warning($line); + } return false; } diff --git a/lib/private/Config/UserConfig.php b/lib/private/Config/UserConfig.php index 3a78d91ee766e..d0d19561e2dc3 100644 --- a/lib/private/Config/UserConfig.php +++ b/lib/private/Config/UserConfig.php @@ -66,6 +66,7 @@ class UserConfig implements IUserConfig { /** @var array, aliases: array, strictness: Strictness}> ['app_id' => ['strictness' => ConfigLexiconStrictness, 'entries' => ['config_key' => ConfigLexiconEntry[]]] */ private array $configLexiconDetails = []; private bool $ignoreLexiconAliases = false; + private array $strictnessApplied = []; public function __construct( protected IDBConnection $connection, @@ -1903,7 +1904,7 @@ private function matchAndApplyLexiconDefinition( } if (!array_key_exists($key, $configDetails['entries'])) { - return $this->applyLexiconStrictness($configDetails['strictness'], 'The user config key ' . $app . '/' . $key . ' is not defined in the config lexicon'); + return $this->applyLexiconStrictness($configDetails['strictness'], $app . '/' . $key); } // if lazy is NULL, we ignore all check on the type/lazyness/default from Lexicon @@ -1970,21 +1971,28 @@ private function getSystemDefault(string $appId, Entry $configValue): ?string { * * @return bool TRUE if conflict can be fully ignored * @throws UnknownKeyException - *@see ILexicon::getStrictness() + * @see ILexicon::getStrictness() */ - private function applyLexiconStrictness(?Strictness $strictness, string $line = ''): bool { + private function applyLexiconStrictness(?Strictness $strictness, string $configAppKey): bool { if ($strictness === null) { return true; } + $line = 'The user config key ' . $configAppKey . ' is not defined in the config lexicon'; switch ($strictness) { case Strictness::IGNORE: return true; case Strictness::NOTICE: - $this->logger->notice($line); + if (!in_array($configAppKey, $this->strictnessApplied, true)) { + $this->strictnessApplied[] = $configAppKey; + $this->logger->notice($line); + } return true; case Strictness::WARNING: - $this->logger->warning($line); + if (!in_array($configAppKey, $this->strictnessApplied, true)) { + $this->strictnessApplied[] = $configAppKey; + $this->logger->warning($line); + } return false; case Strictness::EXCEPTION: throw new UnknownKeyException($line);