|
21 | 21 | use OCP\AppFramework\Db\DoesNotExistException; |
22 | 22 | use OCP\BackgroundJob\IJobList; |
23 | 23 | use OCP\Cache\CappedMemoryCache; |
| 24 | +use OCP\Config\IUserConfig; |
| 25 | +use OCP\Config\ValueType; |
24 | 26 | use OCP\Files\File; |
25 | 27 | use OCP\Files\IRootFolder; |
26 | 28 | use OCP\Files\NotFoundException; |
@@ -314,9 +316,50 @@ protected function importAppsSettings(IUser $user, |
314 | 316 | $output->writeln('Importing settings from settings.json…'); |
315 | 317 |
|
316 | 318 | $data = json_decode($importSource->getFileContents('settings.json'), true, 512, JSON_THROW_ON_ERROR); |
317 | | - foreach ($data as $app => $values) { |
318 | | - foreach ($values as $key => $value) { |
319 | | - $this->config->setUserValue($user->getUID(), $app, $key, $value); |
| 319 | + |
| 320 | + if (interface_exists(IUserConfig::class)) { |
| 321 | + /* |
| 322 | + * Starting with 32, we have to use the correct type |
| 323 | + * When dropping support for <32, IUserConfig should be injected instead |
| 324 | + */ |
| 325 | + $userConfig = \OCP\Server::get(IUserConfig::class); |
| 326 | + $userId = $user->getUID(); |
| 327 | + foreach ($data as $app => $values) { |
| 328 | + foreach ($values as $key => $value) { |
| 329 | + $type = $userConfig->getValueType($userId, $app, $key); |
| 330 | + switch ($type) { |
| 331 | + default: |
| 332 | + case ValueType::MIXED: |
| 333 | + $this->config->setUserValue($userId, $app, $key, $value); |
| 334 | + break; |
| 335 | + case ValueType::STRING: |
| 336 | + $userConfig->setValueString($userId, $app, $key, $value); |
| 337 | + break; |
| 338 | + case ValueType::INT: |
| 339 | + $userConfig->setValueInt($userId, $app, $key, (int)$value); |
| 340 | + break; |
| 341 | + case ValueType::FLOAT: |
| 342 | + $userConfig->setValueFloat($userId, $app, $key, (float)$value); |
| 343 | + break; |
| 344 | + case ValueType::BOOL: |
| 345 | + if (is_string($value)) { |
| 346 | + $value = in_array(strtolower($value), ['1', 'true', 'yes', 'on']); |
| 347 | + } elseif (!is_bool($value)) { |
| 348 | + $value = (bool)$value; |
| 349 | + } |
| 350 | + $userConfig->setValueBool($userId, $app, $key, $value); |
| 351 | + break; |
| 352 | + case ValueType::ARRAY: |
| 353 | + $userConfig->setValueArray($userId, $app, $key, $value); |
| 354 | + break; |
| 355 | + } |
| 356 | + } |
| 357 | + } |
| 358 | + } else { |
| 359 | + foreach ($data as $app => $values) { |
| 360 | + foreach ($values as $key => $value) { |
| 361 | + $this->config->setUserValue($user->getUID(), $app, $key, $value); |
| 362 | + } |
320 | 363 | } |
321 | 364 | } |
322 | 365 | } |
|
0 commit comments