check for user email before writing msgraph metadata

This commit is contained in:
Julien Fastré 2022-07-06 21:36:37 +02:00
parent c8028b8e60
commit f72c0576ef

View File

@ -130,6 +130,10 @@ class MapCalendarToUser
public function hasUserId(User $user): bool public function hasUserId(User $user): bool
{ {
if (null === $user->getEmail() || '' === $user->getEmail()) {
return false;
}
if (!array_key_exists(self::METADATA_KEY, $user->getAttributes())) { if (!array_key_exists(self::METADATA_KEY, $user->getAttributes())) {
return false; return false;
} }
@ -139,6 +143,10 @@ class MapCalendarToUser
public function writeMetadata(User $user): User public function writeMetadata(User $user): User
{ {
if (null === $user->getEmail() OR '' === $user->getEmail()) {
return $user;
}
if (null === $userData = $this->getUserByEmail($user->getEmailCanonical())) { if (null === $userData = $this->getUserByEmail($user->getEmailCanonical())) {
$this->logger->warning('[MapCalendarToUser] could not find user on msgraph', ['userId' => $user->getId(), 'email' => $user->getEmailCanonical()]); $this->logger->warning('[MapCalendarToUser] could not find user on msgraph', ['userId' => $user->getId(), 'email' => $user->getEmailCanonical()]);