10
10
11
11
use OC \AppConfig ;
12
12
use OC \AppFramework \Middleware \Security \Exceptions \NotAdminException ;
13
+ use OC \Config \ConfigManager ;
13
14
use OCP \App \IAppManager ;
14
15
use OCP \AppFramework \Http ;
15
16
use OCP \AppFramework \Http \Attribute \NoAdminRequired ;
16
17
use OCP \AppFramework \Http \Attribute \PasswordConfirmationRequired ;
17
18
use OCP \AppFramework \Http \DataResponse ;
18
19
use OCP \AppFramework \OCSController ;
20
+ use OCP \Config \ValueType ;
19
21
use OCP \Exceptions \AppConfigUnknownKeyException ;
20
22
use OCP \IAppConfig ;
21
23
use OCP \IGroupManager ;
@@ -37,6 +39,7 @@ public function __construct(
37
39
private IGroupManager $ groupManager ,
38
40
private IManager $ settingManager ,
39
41
private IAppManager $ appManager ,
42
+ private readonly ConfigManager $ configManager ,
40
43
) {
41
44
parent ::__construct ($ appName , $ request );
42
45
}
@@ -130,19 +133,27 @@ public function setValue(string $app, string $key, string $value): DataResponse
130
133
}
131
134
132
135
$ type = null ;
133
- try {
134
- $ configDetails = $ this ->appConfig ->getDetails ($ app , $ key );
135
- $ type = $ configDetails ['type ' ];
136
- } catch (AppConfigUnknownKeyException ) {
136
+
137
+ // checking expected type from lexicon
138
+ $ keyDetails = $ this ->appConfig ->getKeyDetails ($ app , $ key );
139
+ if (array_key_exists ('valueType ' , $ keyDetails )) {
140
+ $ type = $ keyDetails ['valueType ' ];
141
+ } else {
142
+ // if no details from lexicon, get from eventual current value in database
143
+ try {
144
+ $ configDetails = $ this ->appConfig ->getDetails ($ app , $ key );
145
+ $ type = $ configDetails ['type ' ];
146
+ } catch (AppConfigUnknownKeyException ) {
147
+ }
137
148
}
138
149
139
150
/** @psalm-suppress InternalMethod */
140
151
match ($ type ) {
141
- IAppConfig::VALUE_BOOL => $ this ->appConfig ->setValueBool ($ app , $ key , ( bool ) $ value ),
142
- IAppConfig::VALUE_FLOAT => $ this ->appConfig ->setValueFloat ($ app , $ key , ( float ) $ value ),
143
- IAppConfig::VALUE_INT => $ this ->appConfig ->setValueInt ($ app , $ key , ( int ) $ value ),
144
- IAppConfig::VALUE_STRING => $ this ->appConfig ->setValueString ($ app , $ key , $ value ),
145
- IAppConfig::VALUE_ARRAY => $ this ->appConfig ->setValueArray ($ app , $ key , \json_decode ($ value, true )),
152
+ IAppConfig::VALUE_BOOL , ValueType:: BOOL => $ this ->appConfig ->setValueBool ($ app , $ key , $ this -> configManager -> convertToBool ( $ value) ),
153
+ IAppConfig::VALUE_FLOAT , ValueType:: FLOAT => $ this ->appConfig ->setValueFloat ($ app , $ key , $ this -> configManager -> convertToFloat ( $ value) ),
154
+ IAppConfig::VALUE_INT , ValueType:: INT => $ this ->appConfig ->setValueInt ($ app , $ key , $ this -> configManager -> convertToInt ( $ value) ),
155
+ IAppConfig::VALUE_STRING , ValueType:: STRING => $ this ->appConfig ->setValueString ($ app , $ key , $ value ),
156
+ IAppConfig::VALUE_ARRAY , ValueType:: ARRAY => $ this ->appConfig ->setValueArray ($ app , $ key , $ this -> configManager -> convertToArray ($ value )),
146
157
default => $ this ->appConfig ->setValueMixed ($ app , $ key , $ value ),
147
158
};
148
159
0 commit comments