File tree Expand file tree Collapse file tree 2 files changed +18
-6
lines changed
Expand file tree Collapse file tree 2 files changed +18
-6
lines changed Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments