Skip to content
This repository was archived by the owner on May 29, 2026. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions lib/Service/OrganizationSyncService.php
Original file line number Diff line number Diff line change
Expand Up @@ -1240,10 +1240,9 @@ private function processContactPerson(object $contactPerson, array &$stats): ?st
}

// Check if user already exists.
$userManager = $this->container->get('OCP\IUserManager');
$username = $email;
if (empty($existingUsername) === false) {
}
$userManager = $this->container->get('OCP\IUserManager');
// Use the stored username when available, otherwise fall back to email as username.
$username = (empty($existingUsername) === false) ? $existingUsername : $email;

$user = $userManager->get($username);

Expand All @@ -1268,18 +1267,18 @@ private function processContactPerson(object $contactPerson, array &$stats): ?st
'username' => $username,
]
);
}

} else {
$this->logger->error(
'OrganizationSyncService: Failed to create user account',
[
'contactId' => $contactPerson->getId(),
'username' => $username,
]
);
}
}//end if

// User exists, update username in contact if needed.
// Contact exists without a stored username — record the resolved username for future syncs.
if (empty($existingUsername) === true) {
$this->logger->debug(
'OrganizationSyncService: Updating contact person with username',
Expand All @@ -1291,7 +1290,7 @@ private function processContactPerson(object $contactPerson, array &$stats): ?st
$stats['usersUpdated']++;
}

return $username;
return $username;
} catch (\Exception $e) {
$this->logger->error(
'OrganizationSyncService: Failed to process contact person',
Expand Down