1010
1111use OC \AppConfig ;
1212use OC \AppFramework \Middleware \Security \Exceptions \NotAdminException ;
13+ use OC \Config \ConfigManager ;
1314use OCP \App \IAppManager ;
1415use OCP \AppFramework \Http ;
1516use OCP \AppFramework \Http \Attribute \NoAdminRequired ;
1617use OCP \AppFramework \Http \Attribute \PasswordConfirmationRequired ;
1718use OCP \AppFramework \Http \DataResponse ;
1819use OCP \AppFramework \OCSController ;
20+ use OCP \Config \ValueType ;
1921use OCP \Exceptions \AppConfigUnknownKeyException ;
2022use OCP \IAppConfig ;
2123use OCP \IGroupManager ;
@@ -37,6 +39,7 @@ public function __construct(
3739 private IGroupManager $ groupManager ,
3840 private IManager $ settingManager ,
3941 private IAppManager $ appManager ,
42+ private readonly ConfigManager $ configManager ,
4043 ) {
4144 parent ::__construct ($ appName , $ request );
4245 }
@@ -130,19 +133,27 @@ public function setValue(string $app, string $key, string $value): DataResponse
130133 }
131134
132135 $ 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+ }
137148 }
138149
139150 /** @psalm-suppress InternalMethod */
140151 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 )),
146157 default => $ this ->appConfig ->setValueMixed ($ app , $ key , $ value ),
147158 };
148159
0 commit comments