mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
remove existing calendars from proxy remote
This commit is contained in:
parent
3df06e1eba
commit
2d71ba9078
@ -20,6 +20,7 @@ use Chill\CalendarBundle\RemoteCalendar\Connector\MSGraph\OnBehalfOfUserHttpClie
|
|||||||
use Chill\CalendarBundle\RemoteCalendar\Connector\MSGraph\OnBehalfOfUserTokenStorage;
|
use Chill\CalendarBundle\RemoteCalendar\Connector\MSGraph\OnBehalfOfUserTokenStorage;
|
||||||
use Chill\CalendarBundle\RemoteCalendar\Connector\MSGraph\RemoteEventConverter;
|
use Chill\CalendarBundle\RemoteCalendar\Connector\MSGraph\RemoteEventConverter;
|
||||||
use Chill\CalendarBundle\Repository\CalendarRangeRepository;
|
use Chill\CalendarBundle\Repository\CalendarRangeRepository;
|
||||||
|
use Chill\CalendarBundle\Repository\CalendarRepository;
|
||||||
use Chill\MainBundle\Entity\User;
|
use Chill\MainBundle\Entity\User;
|
||||||
use DateTimeImmutable;
|
use DateTimeImmutable;
|
||||||
use Exception;
|
use Exception;
|
||||||
@ -38,6 +39,8 @@ class MSGraphRemoteCalendarConnector implements RemoteCalendarConnectorInterface
|
|||||||
|
|
||||||
private CalendarRangeRepository $calendarRangeRepository;
|
private CalendarRangeRepository $calendarRangeRepository;
|
||||||
|
|
||||||
|
private CalendarRepository $calendarRepository;
|
||||||
|
|
||||||
private LoggerInterface $logger;
|
private LoggerInterface $logger;
|
||||||
|
|
||||||
private MachineHttpClient $machineHttpClient;
|
private MachineHttpClient $machineHttpClient;
|
||||||
@ -55,6 +58,7 @@ class MSGraphRemoteCalendarConnector implements RemoteCalendarConnectorInterface
|
|||||||
private OnBehalfOfUserHttpClient $userHttpClient;
|
private OnBehalfOfUserHttpClient $userHttpClient;
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
|
CalendarRepository $calendarRepository,
|
||||||
CalendarRangeRepository $calendarRangeRepository,
|
CalendarRangeRepository $calendarRangeRepository,
|
||||||
MachineHttpClient $machineHttpClient,
|
MachineHttpClient $machineHttpClient,
|
||||||
MapCalendarToUser $mapCalendarToUser,
|
MapCalendarToUser $mapCalendarToUser,
|
||||||
@ -65,6 +69,7 @@ class MSGraphRemoteCalendarConnector implements RemoteCalendarConnectorInterface
|
|||||||
TranslatorInterface $translator,
|
TranslatorInterface $translator,
|
||||||
UrlGeneratorInterface $urlGenerator
|
UrlGeneratorInterface $urlGenerator
|
||||||
) {
|
) {
|
||||||
|
$this->calendarRepository = $calendarRepository;
|
||||||
$this->calendarRangeRepository = $calendarRangeRepository;
|
$this->calendarRangeRepository = $calendarRangeRepository;
|
||||||
$this->machineHttpClient = $machineHttpClient;
|
$this->machineHttpClient = $machineHttpClient;
|
||||||
$this->mapCalendarToUser = $mapCalendarToUser;
|
$this->mapCalendarToUser = $mapCalendarToUser;
|
||||||
@ -157,6 +162,7 @@ class MSGraphRemoteCalendarConnector implements RemoteCalendarConnectorInterface
|
|||||||
|
|
||||||
$ids = array_map(static function ($item) { return $item['id']; }, $bareEvents['value']);
|
$ids = array_map(static function ($item) { return $item['id']; }, $bareEvents['value']);
|
||||||
$existingIdsInRange = $this->calendarRangeRepository->findRemoteIdsPresent($ids);
|
$existingIdsInRange = $this->calendarRangeRepository->findRemoteIdsPresent($ids);
|
||||||
|
$existingIdsInCalendar = $this->calendarRepository->findRemoteIdsPresent($ids);
|
||||||
|
|
||||||
return array_values(
|
return array_values(
|
||||||
array_map(
|
array_map(
|
||||||
@ -166,8 +172,8 @@ class MSGraphRemoteCalendarConnector implements RemoteCalendarConnectorInterface
|
|||||||
// filter all event to keep only the one not in range
|
// filter all event to keep only the one not in range
|
||||||
array_filter(
|
array_filter(
|
||||||
$bareEvents['value'],
|
$bareEvents['value'],
|
||||||
static function ($item) use ($existingIdsInRange) {
|
static function ($item) use ($existingIdsInRange, $existingIdsInCalendar) {
|
||||||
return (!$existingIdsInRange[$item['id']]) ?? true;
|
return ((!$existingIdsInRange[$item['id']]) ?? true) && ((!$existingIdsInCalendar[$item['id']]) ?? true);
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
@ -25,11 +25,14 @@ use function count;
|
|||||||
|
|
||||||
class CalendarRepository implements ObjectRepository
|
class CalendarRepository implements ObjectRepository
|
||||||
{
|
{
|
||||||
|
private EntityManagerInterface $em;
|
||||||
|
|
||||||
private EntityRepository $repository;
|
private EntityRepository $repository;
|
||||||
|
|
||||||
public function __construct(EntityManagerInterface $entityManager)
|
public function __construct(EntityManagerInterface $entityManager)
|
||||||
{
|
{
|
||||||
$this->repository = $entityManager->getRepository(Calendar::class);
|
$this->repository = $entityManager->getRepository(Calendar::class);
|
||||||
|
$this->em = $entityManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function countByAccompanyingPeriod(AccompanyingPeriod $period): int
|
public function countByAccompanyingPeriod(AccompanyingPeriod $period): int
|
||||||
|
Loading…
x
Reference in New Issue
Block a user