mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-25 09:03:48 +00:00
wip: synchro of calendar range
This commit is contained in:
@@ -11,6 +11,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace Chill\CalendarBundle\RemoteCalendar\Connector;
|
||||
|
||||
use Chill\CalendarBundle\Entity\CalendarRange;
|
||||
use Chill\CalendarBundle\RemoteCalendar\Connector\MSGraph\MachineHttpClient;
|
||||
use Chill\CalendarBundle\RemoteCalendar\Connector\MSGraph\MapCalendarToUser;
|
||||
use Chill\CalendarBundle\RemoteCalendar\Connector\MSGraph\OnBehalfOfUserHttpClient;
|
||||
@@ -18,6 +19,7 @@ use Chill\CalendarBundle\RemoteCalendar\Connector\MSGraph\OnBehalfOfUserTokenSto
|
||||
use Chill\CalendarBundle\RemoteCalendar\Connector\MSGraph\RemoteEventConverter;
|
||||
use Chill\MainBundle\Entity\User;
|
||||
use DateTimeImmutable;
|
||||
use Exception;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Component\HttpFoundation\RedirectResponse;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
@@ -105,6 +107,56 @@ class MSGraphRemoteCalendarConnector implements RemoteCalendarConnectorInterface
|
||||
}
|
||||
}
|
||||
|
||||
public function syncCalendarRange(CalendarRange $calendarRange): void
|
||||
{
|
||||
if ($calendarRange->hasRemoteId()) {
|
||||
throw new Exception('update existing not implemented');
|
||||
}
|
||||
$this->createRemoteCalendarRange($calendarRange);
|
||||
}
|
||||
|
||||
private function createRemoteCalendarRange(CalendarRange $calendarRange): void
|
||||
{
|
||||
$userId = $this->mapCalendarToUser->getUserId($calendarRange->getUser());
|
||||
$calendarId = $this->mapCalendarToUser->getCalendarId($calendarRange->getUser());
|
||||
|
||||
if (null === $userId || null === $calendarId) {
|
||||
$this->logger->warning('user does not have userId nor calendarId', [
|
||||
'user_id' => $calendarRange->getUser()->getId(),
|
||||
'calendar_range_id' => $calendarRange->getId(),
|
||||
]);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$eventData = $this->remoteEventConverter->calendarRangeToEvent($calendarRange);
|
||||
|
||||
try {
|
||||
$event = $this->machineHttpClient->request(
|
||||
'POST',
|
||||
'users/' . $userId . '/calendar/events',
|
||||
[
|
||||
'json' => $eventData,
|
||||
]
|
||||
)->toArray();
|
||||
} catch (ClientExceptionInterface $e) {
|
||||
$this->logger->warning('could not save calendar range to remote', [
|
||||
'exception' => $e->getTraceAsString(),
|
||||
'calendarRangeId' => $calendarRange->getId(),
|
||||
]);
|
||||
|
||||
throw $e;
|
||||
}
|
||||
|
||||
dump($event);
|
||||
|
||||
$calendarRange->setRemoteId($event['id'])
|
||||
->addRemoteAttributes([
|
||||
'lastModifiedDateTime' => (DateTimeImmutable::createFromFormat(RemoteEventConverter::REMOTE_DATETIMEZONE_FORMAT, $event['lastModifiedDateTime']))->getTimestamp(),
|
||||
'changeKey' => $event['changeKey'],
|
||||
]);
|
||||
}
|
||||
|
||||
private function getScheduleTimesForUser(User $user, DateTimeImmutable $startDate, DateTimeImmutable $endDate): array
|
||||
{
|
||||
$userId = $this->mapCalendarToUser->getUserId($user);
|
||||
|
Reference in New Issue
Block a user