Skip to content

Commit 991427d

Browse files
committed
fix: Fix settings import when a setting is typed
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
1 parent 07afdc7 commit 991427d

1 file changed

Lines changed: 46 additions & 3 deletions

File tree

lib/Service/UserMigrationService.php

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
use OCP\AppFramework\Db\DoesNotExistException;
2222
use OCP\BackgroundJob\IJobList;
2323
use OCP\Cache\CappedMemoryCache;
24+
use OCP\Config\IUserConfig;
25+
use OCP\Config\ValueType;
2426
use OCP\Files\File;
2527
use OCP\Files\IRootFolder;
2628
use OCP\Files\NotFoundException;
@@ -314,9 +316,50 @@ protected function importAppsSettings(IUser $user,
314316
$output->writeln('Importing settings from settings.json…');
315317

316318
$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+
}
320363
}
321364
}
322365
}

0 commit comments

Comments
 (0)