Skip to content

Commit 5cb24c2

Browse files
committed
Recieve multiple users from backend for user sync
Recieve multiple users from the backend for user sync instead of checking for single user. From the received users check if the user to be synced is available in the list. Signed-off-by: Sujith H <sharidasan@owncloud.com>
1 parent cf40428 commit 5cb24c2

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

core/Command/User/SyncBackend.php

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -252,15 +252,23 @@ private function syncSingleUser(
252252
$missingAccountsAction
253253
) {
254254
$output->writeln("Syncing $uid ...");
255-
$users = $backend->getUsers($uid, 2);
256-
if (\count($users) > 1) {
257-
throw new \LengthException("Multiple users returned from backend for: $uid. Cancelling sync.");
255+
$users = $backend->getUsers($uid);
256+
$userToSync = null;
257+
foreach ($users as $user) {
258+
if ($backend->getDisplayName($user) === $uid) {
259+
if ($userToSync === null) {
260+
$userToSync = $user;
261+
} else {
262+
throw new \LengthException("Multiple users returned from backend for: $uid. Cancelling sync.");
263+
}
264+
}
258265
}
259266

260267
$dummy = new Account(); // to prevent null pointer when writing messages
261-
if (\count($users) === 1) {
268+
269+
if ($userToSync !== null) {
262270
// Run the sync using the internal username if mapped
263-
$syncService->run($backend, new \ArrayIterator([$users[0]]), function () {
271+
$syncService->run($backend, new \ArrayIterator([$userToSync]), function () {
264272
});
265273
} else {
266274
// Not found

tests/lib/Command/User/SyncBackendTest.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,9 @@ public function testSingleUserSyncExistingUserException() {
276276
$outputInterface = $this->createMock(OutputInterface::class);
277277
$syncService = $this->createMock(SyncService::class);
278278

279-
$this->dummyBackend->method('getUsers')->willReturn(['existing-uid', 'should-explode']);
279+
$this->dummyBackend->method('getUsers')->willReturn(['existing-uid', 'existing-uid']);
280+
$this->dummyBackend->method('getDisplayName')
281+
->willReturn('existing-uid');
280282

281283
$missingAccountsAction = 'disable';
282284
$syncService->expects($this->never())->method('run');
@@ -297,6 +299,8 @@ public function testSingleUserSyncExistingUser() {
297299
$syncService = $this->createMock(SyncService::class);
298300

299301
$this->dummyBackend->method('getUsers')->willReturn(['existing-uid']);
302+
$this->dummyBackend->method('getDisplayName')
303+
->willReturn('existing-uid');
300304

301305
$missingAccountsAction = 'disable';
302306
$syncService->expects($this

0 commit comments

Comments
 (0)