28 private Mappers\Event $eventMapper;
29 private Mappers\EventConnection $eventConnectionMapper;
33 $helper = ServiceLocator::getInstance()->get(
'calendar.service.mappers.factory');
34 $this->eventMapper = $helper->getEvent();
35 $this->eventConnectionMapper = $helper->getEventConnection();
44 $this->eventMapper->delete($syncEvent->getEvent());
45 $this->eventConnectionMapper->delete($syncEvent->getEventConnection());
55 public function getSyncEventCollectionByVendorIdList(
56 array $vendorEventIdList,
58 ): Sync\Entities\SyncEventMap
62 if (empty($vendorEventIdList))
67 $query1 = EventConnectionTable::query()
69 ->where(
'CONNECTION_ID', $connectionId)
70 ->whereIn(
'VENDOR_EVENT_ID', $vendorEventIdList)
72 $query2 = EventConnectionTable::query()
74 ->where(
'CONNECTION_ID', $connectionId)
75 ->whereIn(
'RECURRENCE_ID', $vendorEventIdList)
78 $query1->unionAll($query2);
79 $result = $query1->exec()->fetchAll();
81 $idList = array_map(
static function($item) {
return (
int)$item[
'ID'];}, $result);
89 [
'ID',
'in', $idList],
91 $query = ConditionTree::createFromArray($filter);
92 $eventConnectionMap = $this->eventConnectionMapper->getMap($query);
94 $impatientExportSyncEventList = [];
97 foreach ($eventConnectionMap as $eventConnection)
99 $syncEvent =
new SyncEvent();
101 ->setEventConnection($eventConnection)
102 ->setEvent($eventConnection->getEvent())
103 ->setAction($eventConnection->getLastSyncStatus())
106 if ($syncEvent->isInstance())
109 if ($masterSyncEvent = $syncEventMap->getItem($syncEvent->getVendorRecurrenceId()))
111 $masterSyncEvent->addInstance($syncEvent);
115 $impatientExportSyncEventList[$syncEvent->getVendorRecurrenceId()][$eventConnection->getVendorEventId()] = $syncEvent;
120 $syncEvent->isRecurrence()
121 && $instanceList = ($impatientExportSyncEventList[$syncEvent->getVendorEventId()] ??
null)
124 $syncEvent->addInstanceList($instanceList);
129 $eventConnection->getVendorEventId()
133 if ($impatientExportSyncEventList)
135 foreach ($impatientExportSyncEventList as $syncEventList)
137 $syncEventMap->addItems($syncEventList);
141 return $syncEventMap;
156 public function getSyncEventMapBySyncSectionIdCollectionForExport(
157 array $sectionIdList,
160 ): ?Sync\Entities\SyncEventMap
162 Loader::includeModule(
'dav');
170 $eventDb = EventTable::query()
173 'EVENT_CONNECTION.*',
174 'EVENT_CONNECTION.CONNECTION',
175 'EVENT_CONNECTION.EVENT',
177 ->where(
'OWNER_ID', $userId)
178 ->where(
'CAL_TYPE', Dictionary::EVENT_TYPE[
'user'])
179 ->where(
'DELETED',
'N')
180 ->where(
'DATE_TO_TS_UTC',
'>', $timestamp)
182 ->where(Query::filter()
184 ->whereNot(
'MEETING_STATUS',
'N')
185 ->whereNull(
'MEETING_STATUS')
187 ->whereIn(
'SECTION_ID', $sectionIdList)
188 ->registerRuntimeField(
'EVENT_CONNECTION',
191 EventConnectionTable::getEntity(),
192 Join::on(
'ref.EVENT_ID',
'this.ID')
193 ->where(
'ref.CONNECTION_ID', $connectionId)
195 [
'join_type' => Join::TYPE_LEFT]
202 $map =
new Sync\Entities\SyncEventMap();
203 $impatientSyncEventInstanceList = [];
205 while ($eventDM = $eventDb->fetchObject())
207 $action = Sync\Dictionary::SYNC_EVENT_ACTION[
'create'];
208 $syncEvent =
new Sync\Entities\SyncEvent();
210 $event = (
new EventBuilderFromEntityObject($eventDM))->build();
211 $syncEvent->setEvent($event);
214 if ($eventConnectionDM = $eventDM->get(
'EVENT_CONNECTION'))
216 $eventConnection = (
new Sync\Builders\BuilderEventConnectionFromDM($eventConnectionDM))->build();
217 $eventConnection->setEvent($event);
218 $syncEvent->setEventConnection($eventConnection);
222 && ($eventConnection->getLastSyncStatus() !== Sync\Dictionary::SYNC_EVENT_ACTION[
'success'])
225 $action = $eventConnection->getLastSyncStatus();
227 elseif ($event->getVersion() > $eventConnection->getVersion())
229 $action = Sync\Dictionary::SYNC_EVENT_ACTION[
'update'];
233 $action = Sync\Dictionary::SYNC_EVENT_ACTION[
'success'];
237 if ($syncEvent->isInstance())
239 $syncEvent->setAction($action);
241 $masterEvent = $map->getItem($event->getUid());
252 $masterEvent->addInstance($syncEvent);
257 $impatientSyncEventInstanceList[$event->getUid()][] = $syncEvent;
261 if ($instanceList = ($impatientSyncEventInstanceList[$event->getUid()] ??
null))
263 $syncEvent->addInstanceList($instanceList);
264 unset($impatientSyncEventInstanceList[$event->getUid()]);
267 && $this->hasCandidatesForUpdate($instanceList)
270 $action = Sync\Dictionary::SYNC_EVENT_ACTION[
'update'];
273 $syncEvent->setAction($action);
274 $map->add($syncEvent, $event->getUid());
286 private function hasCandidatesForUpdate(array $list): bool
288 return (
bool)array_filter($list,
function (SyncEvent $syncEvent) {