remove existing calendars from proxy remote

This commit is contained in:
Julien Fastré 2022-07-02 14:42:54 +02:00
parent 3df06e1eba
commit 2d71ba9078
2 changed files with 11 additions and 2 deletions

View File

@ -20,6 +20,7 @@ use Chill\CalendarBundle\RemoteCalendar\Connector\MSGraph\OnBehalfOfUserHttpClie
use Chill\CalendarBundle\RemoteCalendar\Connector\MSGraph\OnBehalfOfUserTokenStorage;
use Chill\CalendarBundle\RemoteCalendar\Connector\MSGraph\RemoteEventConverter;
use Chill\CalendarBundle\Repository\CalendarRangeRepository;
use Chill\CalendarBundle\Repository\CalendarRepository;
use Chill\MainBundle\Entity\User;
use DateTimeImmutable;
use Exception;
@ -38,6 +39,8 @@ class MSGraphRemoteCalendarConnector implements RemoteCalendarConnectorInterface
private CalendarRangeRepository $calendarRangeRepository;
private CalendarRepository $calendarRepository;
private LoggerInterface $logger;
private MachineHttpClient $machineHttpClient;
@ -55,6 +58,7 @@ class MSGraphRemoteCalendarConnector implements RemoteCalendarConnectorInterface
private OnBehalfOfUserHttpClient $userHttpClient;
public function __construct(
CalendarRepository $calendarRepository,
CalendarRangeRepository $calendarRangeRepository,
MachineHttpClient $machineHttpClient,
MapCalendarToUser $mapCalendarToUser,
@ -65,6 +69,7 @@ class MSGraphRemoteCalendarConnector implements RemoteCalendarConnectorInterface
TranslatorInterface $translator,
UrlGeneratorInterface $urlGenerator
) {
$this->calendarRepository = $calendarRepository;
$this->calendarRangeRepository = $calendarRangeRepository;
$this->machineHttpClient = $machineHttpClient;
$this->mapCalendarToUser = $mapCalendarToUser;
@ -157,6 +162,7 @@ class MSGraphRemoteCalendarConnector implements RemoteCalendarConnectorInterface
$ids = array_map(static function ($item) { return $item['id']; }, $bareEvents['value']);
$existingIdsInRange = $this->calendarRangeRepository->findRemoteIdsPresent($ids);
$existingIdsInCalendar = $this->calendarRepository->findRemoteIdsPresent($ids);
return array_values(
array_map(
@ -166,8 +172,8 @@ class MSGraphRemoteCalendarConnector implements RemoteCalendarConnectorInterface
// filter all event to keep only the one not in range
array_filter(
$bareEvents['value'],
static function ($item) use ($existingIdsInRange) {
return (!$existingIdsInRange[$item['id']]) ?? true;
static function ($item) use ($existingIdsInRange, $existingIdsInCalendar) {
return ((!$existingIdsInRange[$item['id']]) ?? true) && ((!$existingIdsInCalendar[$item['id']]) ?? true);
}
)
)

View File

@ -25,11 +25,14 @@ use function count;
class CalendarRepository implements ObjectRepository
{
private EntityManagerInterface $em;
private EntityRepository $repository;
public function __construct(EntityManagerInterface $entityManager)
{
$this->repository = $entityManager->getRepository(Calendar::class);
$this->em = $entityManager;
}
public function countByAccompanyingPeriod(AccompanyingPeriod $period): int