Skip to content

Commit d246d73

Browse files
committed
fix(identify-method): normalize identify_methods when stored as wrong type
When the Nextcloud provisioning API is used to set the identify_methods config key, it always writes using setValueString(), causing a type conflict when LibreSign later reads the key with getValueArray(). Catch AppConfigTypeConflictException in getSavedSettings(), read the raw string value, delete the mistyped key and re-store it as an array type. This allows invalid string values stored via provisioning API to be transparently normalized on the next read. Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
1 parent 11f1ab1 commit d246d73

1 file changed

Lines changed: 20 additions & 1 deletion

File tree

lib/Service/IdentifyMethod/IdentifyService.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use OCA\Libresign\Service\SessionService;
1818
use OCP\AppFramework\Utility\ITimeFactory;
1919
use OCP\EventDispatcher\IEventDispatcher;
20+
use OCP\Exceptions\AppConfigTypeConflictException;
2021
use OCP\Files\IRootFolder;
2122
use OCP\IAppConfig;
2223
use OCP\IL10N;
@@ -131,7 +132,25 @@ public function getSavedSettings(): array {
131132
}
132133

133134
$this->getAppConfig()->clearCache(true);
134-
$this->savedSettings = $this->getAppConfig()->getValueArray(Application::APP_ID, 'identify_methods', []);
135+
try {
136+
$this->savedSettings = $this->getAppConfig()->getValueArray(Application::APP_ID, 'identify_methods', []);
137+
} catch (AppConfigTypeConflictException) {
138+
// Key was stored with wrong type (e.g., string written by the provisioning API).
139+
// Normalize it: read the raw string, delete the key, and re-store as array type.
140+
try {
141+
$raw = $this->getAppConfig()->getValueString(Application::APP_ID, 'identify_methods', '');
142+
} catch (AppConfigTypeConflictException) {
143+
$raw = '';
144+
}
145+
$this->getAppConfig()->deleteKey(Application::APP_ID, 'identify_methods');
146+
$decoded = json_decode($raw, true);
147+
if (is_array($decoded)) {
148+
$this->getAppConfig()->setValueArray(Application::APP_ID, 'identify_methods', $decoded);
149+
$this->savedSettings = $decoded;
150+
} else {
151+
$this->savedSettings = [];
152+
}
153+
}
135154

136155
return $this->savedSettings;
137156
}

0 commit comments

Comments
 (0)