mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-21 07:03:49 +00:00
first bootstrap for handling calendar range sync frommsgraph
This commit is contained in:
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Chill\CalendarBundle\Messenger\Handler;
|
||||
|
||||
use Chill\CalendarBundle\Messenger\Message\MSGraphChangeNotificationMessage;
|
||||
use Chill\CalendarBundle\RemoteCalendar\Connector\MSGraph\MapCalendarToUser;
|
||||
use Chill\CalendarBundle\RemoteCalendar\Connector\MSGraph\RemoteToLocalSync\CalendarRangeSyncer;
|
||||
use Chill\CalendarBundle\Repository\CalendarRangeRepository;
|
||||
use Chill\CalendarBundle\Repository\CalendarRepository;
|
||||
use Chill\CalendarBundle\Repository\InviteRepository;
|
||||
use Chill\MainBundle\Repository\UserRepository;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Component\Messenger\Handler\MessageHandlerInterface;
|
||||
|
||||
/**
|
||||
* @AsMessageHandler
|
||||
*/
|
||||
class MSGraphChangeNotificationHandler implements MessageHandlerInterface
|
||||
{
|
||||
private CalendarRangeRepository $calendarRangeRepository;
|
||||
|
||||
private CalendarRangeSyncer $calendarRangeSyncer;
|
||||
|
||||
private CalendarRepository $calendarRepository;
|
||||
|
||||
private EntityManagerInterface $em;
|
||||
|
||||
private InviteRepository $inviteRepository;
|
||||
|
||||
private LoggerInterface $logger;
|
||||
|
||||
private MapCalendarToUser $mapCalendarToUser;
|
||||
|
||||
private UserRepository $userRepository;
|
||||
|
||||
public function __invoke(MSGraphChangeNotificationMessage $changeNotificationMessage): void
|
||||
{
|
||||
$user = $this->userRepository->find($changeNotificationMessage->getUserId());
|
||||
|
||||
if (null === $user) {
|
||||
$this->logger->warning(__CLASS__ . ' notification concern non-existent user, skipping');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($changeNotificationMessage->getContent()['value'] as $notification) {
|
||||
$secret = $this->mapCalendarToUser->getSubscriptionSecret($user);
|
||||
|
||||
if ($secret !== ($notification['clientState'] ?? -1)) {
|
||||
$this->logger->warning(__CLASS__ . ' could not validate secret, skipping');
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$remoteId = $notification['resourceData']['id'];
|
||||
|
||||
// is this a calendar range ?
|
||||
if (null !== $calendarRange = $this->calendarRangeRepository->findOneBy(['remoteId' => $remoteId])) {
|
||||
$this->calendarRangeSyncer->handleCalendarRangeSync($calendarRange, $notification, $user);
|
||||
$this->em->flush();
|
||||
} elseif (null !== $calendar = $this->calendarRepository->findOneBy(['remoteId' => $remoteId])) {
|
||||
$this->remoteToLocalSyncer->handleCalendarSync($calendar, $notification, $user);
|
||||
$this->em->flush();
|
||||
} elseif (null !== $invite = $this->inviteRepository->findOneBy(['remoteId' => $remoteId])) {
|
||||
$this->remoteToLocalSyncer->handleInviteSync($invite, $notification, $user);
|
||||
$this->em->flush();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user