diff --git a/lib/private/DB/MigrationService.php b/lib/private/DB/MigrationService.php index 013daa04a6d1..d38faa0443c6 100644 --- a/lib/private/DB/MigrationService.php +++ b/lib/private/DB/MigrationService.php @@ -349,6 +349,8 @@ public function migrate($to = 'latest') { /** * @param string $version + * @return mixed + * @throws \Exception */ protected function createInstance($version) { $class = $this->getClass($version); diff --git a/lib/private/User/SyncService.php b/lib/private/User/SyncService.php index a02f43a4f3c1..3e3683b1641d 100644 --- a/lib/private/User/SyncService.php +++ b/lib/private/User/SyncService.php @@ -105,12 +105,15 @@ public function run(\Closure $callback) { } $a = $this->setupAccount($a, $uid); $this->mapper->update($a); - // clean the user's preferences - $this->cleanPreferences($uid); } catch(DoesNotExistException $ex) { $a = $this->createNewAccount($uid); + $this->setupAccount($a, $uid); $this->mapper->insert($a); } + // clean the user's preferences + $this->cleanPreferences($uid); + + // call the callback $callback($uid); } $offset += $limit; @@ -122,7 +125,7 @@ public function run(\Closure $callback) { * @param string $uid * @return Account */ - private function setupAccount(Account $a, $uid) { + public function setupAccount(Account $a, $uid) { list($hasKey, $value) = $this->readUserConfig($uid, 'core', 'enabled'); if ($hasKey) { $a->setState(($value === 'true') ? Account::STATE_ENABLED : Account::STATE_DISABLED); @@ -171,7 +174,7 @@ private function createNewAccount($uid) { */ private function readUserConfig($uid, $app, $key) { $keys = $this->config->getUserKeys($uid, $app); - if (isset($keys[$key])) { + if (in_array($key, $keys)) { $enabled = $this->config->getUserValue($uid, $app, $key); return [true, $enabled]; } diff --git a/tests/lib/User/SyncServiceTest.php b/tests/lib/User/SyncServiceTest.php new file mode 100644 index 000000000000..f8aeb5995b7a --- /dev/null +++ b/tests/lib/User/SyncServiceTest.php @@ -0,0 +1,44 @@ +createMock(AccountMapper::class); + $backend = $this->createMock(UserInterface::class); + $config = $this->createMock(IConfig::class); + $logger = $this->createMock(ILogger::class); + + $config->expects($this->any())->method('getUserKeys')->willReturnMap([ + ['user1', 'core', []], + ['user1', 'login', []], + ['user1', 'settings', ['email']], + ['user1', 'files', []], + ]); + $config->expects($this->any())->method('getUserValue')->willReturnMap([ + ['user1', 'settings', 'email', '', 'foo@bar.net'], + ]); + + $s = new SyncService($mapper, $backend, $config, $logger); + $a = new Account(); + $s->setupAccount($a, 'user1'); + + $this->assertEquals('foo@bar.net', $a->getEmail()); + } +} \ No newline at end of file