fix: sync all teamer data on login

This commit is contained in:
Björn Fromme
2026-03-15 12:42:28 +01:00
parent 317142afc9
commit 24d02c0776
2 changed files with 333 additions and 1 deletions
+61 -1
View File
@@ -44,10 +44,62 @@ class UserDataHandler
// Check if user is already present in local database
$repository = $this->entityManager->getRepository(User::class);
return $repository->findOneBy([
$user = $repository->findOneBy([
'busProAddressId' => $profileResponse->getAddressId(),
'busProPersonId' => $profileResponse->getPersonId(),
]);
if (null !== $user) {
return $user;
}
$email = $profileResponse->getCommunication()?->getEmail();
if (true === empty($email)) {
return null;
}
$users = $repository->findBy([
'email' => $email,
]);
if (1 !== count($users)) {
if (1 < count($users)) {
$this->logger->warning('Unable to match local user by email: multiple users found', [
'email' => $email,
'count' => count($users),
]);
}
return null;
}
/** @var User $user */
$user = $users[0];
$addressId = $profileResponse->getAddressId();
$personId = $profileResponse->getPersonId();
if (null === $addressId || null === $personId) {
$this->logger->warning('Skip BusPro ID refresh: profile response missing IDs', [
'user_id' => $user->getId(),
'user_email' => $user->getEmail(),
'bus_pro_address_id' => $addressId,
'bus_pro_person_id' => $personId,
]);
return $user;
}
$user
->setBusProAddressId($addressId)
->setBusProPersonId($personId)
;
$this->logger->info('Refresh BusPro IDs for existing local user', [
'user_id' => $user->getId(),
'user_email' => $user->getEmail(),
]);
return $user;
}
public function createLocalUser(
@@ -98,6 +150,8 @@ class UserDataHandler
array $hotelCodes = [],
): void {
$user
->setFirstName($profileResponse->getFirstName())
->setLastName($profileResponse->getName())
->setEmail($profileResponse->getCommunication()->getEmail())
->setRoles($roles)
->setHotelCodes($hotelCodes)
@@ -114,6 +168,12 @@ class UserDataHandler
$teamer = $user->getTeamer();
}
$teamer
->setFirstName($profileResponse->getFirstName())
->setLastName($profileResponse->getName())
->setAcademicTitle($profileResponse->getTitle())
->setSalutation($profileResponse->getSalutation())
->setGender($profileResponse->getGender())
->setDateOfBirth($profileResponse->getDateOfBirth())
->setAddress($address)
->setCommunication($communication)
->setCrmSelections($crmSelections)