19 private $mapperFactory;
29 $this->importManager = $factory->getIncomingEventManager();
30 $this->syncSectionCollection = $syncSectionCollection;
32 $this->mapperFactory = ServiceLocator::getInstance()->get(
'calendar.service.mappers.factory');
44 foreach ($this->syncSectionCollection as $syncSection)
47 $syncSection->getSectionConnection() ===
null
48 || !$syncSection->getSectionConnection()->isActive()
56 $result = $this->importManager->
getEvents($syncSection);
58 if ($result->isSuccess())
60 $this->handleCalendarChange(($result->getData()[
'externalSyncEventMap'])->getCollection());
61 $this->externalEventMap->addItems(($result->getData()[
'externalSyncEventMap'])->getCollection());
63 ->getSectionConnection()
64 ->setLastSyncDate(
new Core\Base\
Date())
65 ->setSyncToken($this->importManager->getSyncToken())
66 ->setPageToken($this->importManager->getPageToken())
67 ->setLastSyncStatus($this->importManager->getStatus())
68 ->setVersionId($this->importManager->getEtag())
70 $syncSection->setSectionConnection(
71 $this->saveSectionConnection($syncSection->getSectionConnection())
75 catch (Sync\Exceptions\NotFoundException $e)
77 $syncSection->getSectionConnection()
80 $syncSection->setSectionConnection(
81 $this->saveSectionConnection($syncSection->getSectionConnection())
84 catch (Sync\Exceptions\AuthException | Sync\Exceptions\RemoteAccountException $e)
86 $syncSection->getSectionConnection()
88 $syncSection->setSectionConnection(
89 $this->saveSectionConnection($syncSection->getSectionConnection())
105 private function saveSectionConnection(Sync\Connection\SectionConnection $link): Sync\Connection\SectionConnection
107 $mapper = $this->mapperFactory->getSectionConnection();
108 return $link->getId()
109 ? $mapper->update($link)
110 : $mapper->create($link)
119 return $this->externalEventMap;
125 private function handleCalendarChange(array $collection)
127 $handledCollection = $this->externalEventMap->
getCollection();
133 foreach ($collection as $key => $value)
136 array_key_exists($key, $handledCollection)
137 && $value->getAction() ===
'save'
140 $this->externalEventMap->remove($key);
141 $this->externalEventMap->add($value, $key);