40 private static array $outgoingManagersCache = [];
67 $this->isFullSync = !$this->factory->getConnection()->getToken();
70 $mapperHelper = ServiceLocator::getInstance()->get(
'calendar.service.mappers.factory');
71 $this->sectionConnectionMapper = $mapperHelper->getSectionConnection();
72 $this->sectionMapper = $mapperHelper->getSection();
73 $this->eventConnectionMapper = $mapperHelper->getEventConnection();
74 $this->eventMapper = $mapperHelper->getEvent();
78 $handlerMergeClass = Core\Handlers\HandlersMap::getHandler(
'syncEventMergeHandler');
79 $this->handlerMerge =
new $handlerMergeClass();
95 $pushManager->setBlockPush($push);
98 $this->exchangeSections();
100 $this->sendResult(MasterPushHandler::MASTER_STAGE[1]);
102 $this->blockSectionPush($this->syncSectionMap);
105 $this->exchangeEvents();
111 $this->unblockSectionPush($this->syncSectionMap);
114 $this->sendResult(MasterPushHandler::MASTER_STAGE[2]);
115 $this->sendResult(MasterPushHandler::MASTER_STAGE[3]);
118 ->updateConnection($this->factory->getConnection())
127 $pushManager->setUnblockPush($push);
133 private function sendResult(
string $stage): void
136 'vendorName' => $this->factory->getConnection()->getVendor()->getCode(),
137 'accountName' => $this->factory->getConnection()->getName(),
144 CCalendar::ClearCache();
160 $importEventManager = (
new ImportEventManager($this->factory, $this->syncSectionMap));
164 $this->prepareLocalSyncEventMapWithVendorEventId(
$syncEventMap);
166 $this->handleSectionsToLocalStorage($this->syncSectionMap);
197 $connection->setLastSyncTime(
new Core\
Base\
Date());
200 $accountType = $connection->getAccountType() === Sync\Google\Helper::GOOGLE_ACCOUNT_TYPE_API
202 : $connection->getAccountType()
208 'status' => $this->getSyncStatus($connection->getStatus()),
209 'type' => $accountType,
211 'id' => $connection->getId(),
221 private function getSyncStatus(?
string $status): bool
223 return $status && preg_match(
"/^\[(2\d\d|0)\][a-z0-9 _]*/i", $status);
236 $this->mergeSyncedSyncSectionsWithSavedSections($externalSyncSectionMap);
237 $this->handleSectionsToLocalStorage($externalSyncSectionMap);
238 $this->removeDeletedExternalSections($externalSyncSectionMap);
254 ?Sync\Entities\
SyncEvent $masterSyncEvent =
null
257 if ($syncEvent->getEventConnection() ===
null)
262 if ($masterSyncEvent !==
null)
264 $syncEvent->getEvent()->setRecurrenceId($masterSyncEvent->getId());
267 $this->mergeExternalEventWithLocalParams($syncEvent);
272 if ($syncEvent->getEvent()->getId() ===
null)
274 if ($syncEvent->isInstance())
276 if ($masterSyncEvent ===
null)
278 $masterSyncEvent = $this->getMasterSyncEvent($syncEvent);
280 if (!$masterSyncEvent)
290 if ($masterSyncEvent->getId() ===
null)
312 && $masterSyncEvent->getId()
313 && $syncEvent->isInstance()
325 public function filterUnchangedSections(
332 ($externalSyncSection = $externalSyncSectionMap->getItem($syncSection->getSectionConnection()
333 ->getVendorSectionId()))
334 && $syncSection->getSectionConnection()->getVersionId() !== $externalSyncSection->getSectionConnection()
338 $syncSection->getSectionConnection()->setVersionId($externalSyncSection->getSectionConnection()->getVersionId());
356 $masterSyncEvent = $this->getMasterSyncEvent($syncEvent);
357 if (!$masterSyncEvent)
362 $this->prepareExcludedDatesMasterEvent(
364 $syncEvent->getEvent()->getOriginalDateFrom()
367 if ($masterSyncEvent->getId() ===
null)
372 $this->updateMasterExdate($masterSyncEvent->getEvent());
373 $masterSyncEvent->setEvent($masterSyncEvent->getEvent());
375 $this->syncEventMap->updateItem($masterSyncEvent, $masterSyncEvent->getVendorEventId());
384 return (
new Core\
Event\Properties\MeetingDescription())
385 ->setHostName($owner->getFullName())
386 ->setMeetingCreator($owner->getId())
388 ->setLanguageId(($owner->getRoleEntity() instanceof Core\
Role\
User)
389 ? $owner->getRoleEntity()->getLanguageId()
393 ->setAllowInvite(
true)
407 $event = $syncEvent->getEvent();
410 if ($event->isInstance())
415 if ($event->isRecurrence())
417 $this->handleDeleteRecurrenceEvent($syncEvent);
420 if ($event->isSingle())
422 $this->handleDeleteSingleEvent($syncEvent);
425 $this->eventMapper->delete($event, [
426 'softDelete' =>
true,
427 'originalFrom' => $syncEvent->getEventConnection()->getConnection()->getVendor()->getCode(),
430 $this->eventConnectionMapper->delete($syncEvent->getEventConnection());
443 $event = $syncEvent->getEvent();
444 $event = $event->isNew()
445 ? $this->eventMapper->create($event, [
446 'originalFrom' => $this->factory->getServiceName(),
448 : $this->eventMapper->update($event, [
449 'originalFrom' => $this->factory->getServiceName(),
455 $syncEvent->setEvent($event);
456 $eventConnection = $syncEvent->getEventConnection();
457 if ($eventConnection)
461 ->setVersion($event->getVersion())
464 $eventConnection->getId()
465 ? $this->eventConnectionMapper->update($eventConnection)
466 : $this->eventConnectionMapper->create($eventConnection)
484 $this->prepareLocalSyncEventMapWithVendorEventId($externalEventMap);
485 $this->handleEventsToLocalStorage($externalEventMap);
494 CCalendarSect::SavePermissions(
495 $syncSection->getSection()->getId(),
496 CCalendarSect::GetDefaultAccess(
497 $syncSection->getSection()->getType(),
498 $syncSection->getSection()->getOwner()->getId()
510 private function exchangeSections(): void
517 $this->prepareSyncSectionBeforeExport(
518 $this->getFilteredSectionMapForExport($sectionImporter->getSyncSectionMap())
523 $this->handleExportedSections($sectionExporter->getSyncSectionMap());
525 $this->filterBrokenSyncSections();
534 private function handleExportedSections(Sync\Entities\SyncSectionMap
$syncSectionMap): void
549 private function exchangeEvents(): void
551 $eventImporter = (
new ImportEventManager($this->factory, $this->syncSectionMap))->
import();
554 $savedSyncEventMap = $this->getLocalEventsForExport();
556 if ($savedSyncEventMap)
558 (
new ExportEventManager($this->factory, $this->syncSectionMap))->export($savedSyncEventMap);
559 $this->updateExportedEvents($savedSyncEventMap);
562 $this->handleSectionsToLocalStorage($this->syncSectionMap);
571 private function handleExportedInstances(Sync\Entities\SyncEvent $syncEvent): void
574 foreach ($syncEvent->getInstanceMap() as $instance)
578 $this->handleExportedFailedSyncEvent($syncEvent);
582 if ($instanceEventConnection = $instance->getEventConnection())
584 $instanceEventConnection
585 ->setEvent($instance->getEvent())
586 ->setConnection($syncEvent->getEventConnection()->getConnection())
589 if ($instanceEventConnection->getId())
591 $this->eventConnectionMapper->update($instanceEventConnection);
595 $this->eventConnectionMapper->create($instanceEventConnection);
611 public function validateSyncEventChange(
612 Sync\Entities\SyncEvent $syncEvent,
613 Sync\Entities\SyncEvent $existsSyncEvent =
null
616 if (!$existsSyncEvent)
622 $syncEvent->getEventConnection() !==
null
624 ($syncEvent->getEventConnection()->getVendorVersionId() === $existsSyncEvent->getEventConnection()->getVendorVersionId())
625 || ($syncEvent->getEventConnection()->getEntityTag() === $existsSyncEvent->getEventConnection()->getEntityTag())
631 $syncEvent->getEventConnection()->getConnection()->getVendor()->getCode()
632 !== Sync\Google\Helper::GOOGLE_ACCOUNT_TYPE_API
634 || !$this->hasDifferentEventFields($syncEvent, $existsSyncEvent))
642 if ($existsSyncEvent->getEventId() !== $existsSyncEvent->getParentId())
658 if ($existsSyncEvent->getEvent()->getSpecialLabel() === ResourceBooking::EVENT_LABEL)
691 if ($syncEvent->isSingle() && $syncEvent->getEntityTag() !== $existsSyncEvent->getEntityTag())
696 if ($syncEvent->isRecurrence())
698 if ($syncEvent->getEntityTag() !== $existsSyncEvent->getEntityTag())
703 if ($syncEvent->hasInstances())
706 foreach ($syncEvent->getInstanceMap() as $key => $instance)
708 $existsInstanceMap = $existsSyncEvent->getInstanceMap();
710 if (!$existsInstanceMap)
716 $existsInstance = $existsInstanceMap->getItem($key);
718 if (!$existsInstance)
723 if ($existsInstance->getEntityTag() !== $instance->getEntityTag())
731 if ($syncEvent->isInstance())
739 private function hasDifferentEventFields(
740 Sync\Entities\SyncEvent $syncEvent,
741 Sync\Entities\SyncEvent $existSyncEvent
744 if (!$syncEvent->getEvent() && !$existSyncEvent->getEvent())
750 && !$existSyncEvent->getEvent()->isDeleted()
756 $comparator =
new EventCompareManager($syncEvent->getEvent(), $existSyncEvent->getEvent());
758 $diff = $comparator->getDiff();
759 $significantFields = [
765 'excludedDates' =>
true,
767 $significantDiff = array_intersect_key($diff, $significantFields);
769 return !empty($significantDiff);
779 $masterEvent = $masterSyncEvent->getEvent();
781 if ($exdateCollection ===
null)
784 $masterEvent->setExcludedDateCollection($exdateCollection);
787 if ($instance->getEvent()->getOriginalDateFrom() instanceof Core\
Base\
Date)
789 $exdateCollection->add(
790 (clone $instance->getEvent()->getOriginalDateFrom())
791 ->setDateTimeFormat(Core\
Event\Properties\ExcludedDatesCollection::EXCLUDED_DATE_FORMAT)
808 private function rollbackEvent(
809 Sync\Entities\
SyncEvent $existsExternalSyncEvent,
814 $muteNotice = $this->isNoticesMuted();
815 if ($existsExternalSyncEvent->getEvent()->isDeleted())
818 $syncStatus = Sync\Dictionary::SYNC_EVENT_ACTION[
'delete'];
822 $syncStatus = ($existsExternalSyncEvent->getEvent()->isRecurrence() || $syncEvent->getEvent()->isRecurrence())
824 : Sync\
Dictionary::SYNC_EVENT_ACTION[
'update']
827 $existsExternalSyncEvent->getEventConnection()
828 ->setLastSyncStatus($syncStatus)
829 ->setVersion($existsExternalSyncEvent->getEvent()->getVersion() - 1);
830 $this->eventConnectionMapper->update($existsExternalSyncEvent->getEventConnection());
834 $this->noticeUser($existsExternalSyncEvent, $messageCode);
841 private function isNoticesMuted(): bool
849 private function createPusher(): Sync\Handlers\MasterPushHandler
851 return new Sync\Handlers\MasterPushHandler(
852 $this->factory->getConnection()->getOwner(),
854 $this->factory->getConnection()->getName()
862 private function mergeSyncedSyncSectionsWithSavedSections(Sync\Entities\SyncSectionMap $externalSyncSectionMap): void
865 foreach ($externalSyncSectionMap as $key => $externalSyncSection)
867 if ($externalSyncSection->getSectionConnection() ===
null)
869 $externalSyncSectionMap->remove($key);
875 if ($savedSyncSection = $this->syncSectionMap->has(
876 $externalSyncSection->getSectionConnection()->getVendorSectionId()
879 $savedSyncSection = $this->syncSectionMap->getItem(
880 $externalSyncSection->getSectionConnection()->getVendorSectionId()
883 ->getSectionConnection()
884 ->setId($savedSyncSection->getSectionConnection()->getId())
885 ->setSyncToken($savedSyncSection->getSectionConnection()->getSyncToken())
886 ->setPageToken($savedSyncSection->getSectionConnection()->getPageToken())
889 $savedSection = $savedSyncSection->getSection();
892 ->setId($savedSection->getId())
893 ->setXmlId($savedSection->getXmlId())
894 ->setCreator($savedSection->getCreator())
895 ->setExternalType($savedSection->getExternalType())
896 ->setIsActive($savedSection->isActive())
897 ->setType($savedSection->getType())
899 if (empty($externalSyncSection->getSection()->getColor()))
901 $externalSyncSection->getSection()->setColor(
902 $savedSection->getColor()
903 ?: Core\Property\ColorHelper::getOurColorRandom()
906 if ($savedSection->isLocal())
908 $externalSyncSection->getSection()->setName($savedSection->getName());
918 private function handleSectionsToLocalStorage(Sync\Entities\SyncSectionMap
$syncSectionMap): void
923 if (!$this->validateSyncSectionBeforeSave($syncSection))
925 $this->updateFailedSyncSection($syncSection);
932 if ($syncSection->getSection()->isLocal())
934 $this->createLocalDeletedSection($syncSection);
938 $this->deleteSyncSectionFromLocalStorage($syncSection);
943 if ($syncSection->getSection()->isNew())
947 $this->sectionMapper->create($syncSection->getSection());
950 $this->sectionConnectionMapper->create(
951 $syncSection->getSectionConnection()->setSection($syncSection->getSection())
956 $this->sectionMapper->update($syncSection->getSection());
957 $sectionConnection = $syncSection->getSectionConnection();
958 $sectionConnection->setSection($syncSection->getSection());
960 $sectionConnection->isNew()
961 ? $this->sectionConnectionMapper->create($sectionConnection)
962 : $this->sectionConnectionMapper->update($sectionConnection)
968 $this->syncSectionMap->add($syncSection, $key);
976 private function removeDeletedExternalSections(Sync\Entities\SyncSectionMap $externalSectionMap): void
978 if (!$this->isFullSync)
983 $deleteCandidates = (
new Sync\Entities\SyncSectionMap(
984 array_diff_key($this->syncSectionMap->getCollection(), $externalSectionMap->getCollection()),
985 ))->getNonLocalSections();
988 foreach ($deleteCandidates as $syncSection)
991 ($syncSection->getSection() ===
null)
992 || ($syncSection->getSectionConnection() ===
null)
997 $this->deleteSyncSectionFromLocalStorage($syncSection);
1001 private function createLocalDeletedSection(Sync\Entities\SyncSection $syncSection)
1010 private function deleteSyncSectionFromLocalStorage(Sync\Entities\SyncSection $syncSection): void
1012 if ($syncSection->getSectionConnection()->getId() !==
null)
1014 $this->sectionConnectionMapper->delete($syncSection->getSectionConnection());
1015 $this->syncSectionMap->remove($syncSection->getSectionConnection()->getVendorSectionId());
1018 if ($syncSection->getSection()->getId() !==
null)
1020 $this->sectionMapper->delete($syncSection->getSection(), [
'softDelete' =>
false]);
1021 $this->syncSectionMap->remove($syncSection->getSection()->getId());
1029 private function getFilteredSectionMapForExport(
1030 Sync\Entities\SyncSectionMap $externalSectionMap
1031 ): Sync\Entities\SyncSectionMap
1033 return (
new Sync\Entities\SyncSectionMap(
1036 ? $this->syncSectionMap->getCollection()
1037 : $this->syncSectionMap
1038 ->getItemsByKeys(array_keys($externalSectionMap->getCollection()))
1040 $externalSectionMap->getCollection()
1042 ))->getLocalSections();
1053 $syncSectionList = $this->isFullSync
1055 : $this->syncSectionMap
1070 private function getLocalEventsForExport(): ?Sync\Entities\
SyncEventMap
1072 $sectionIdCollection = [];
1074 foreach ($this->syncSectionMap as $syncSection)
1076 $sectionIdCollection[] = $syncSection->getSection()->getId();
1084 return $this->syncEventFactory->getSyncEventMapBySyncSectionIdCollectionForExport(
1085 $sectionIdCollection,
1086 $this->factory->getConnection()->getOwner()->getId(),
1087 $this->factory->getConnection()->getId()
1099 private function handleEventsToLocalStorage(Sync\Entities\SyncEventMap $externalSyncEventMap): void
1102 foreach ($externalSyncEventMap as $key => $syncEvent)
1105 $existsExternalSyncEvent = $this->syncEventMap->getItem($key);
1107 if (!$this->validateSyncEventChange($syncEvent, $existsExternalSyncEvent))
1112 $masterSyncEvent = $this->getMasterSyncEvent($syncEvent);
1115 && ($syncEvent->isInstance() || $syncEvent->getVendorRecurrenceId())
1116 && $masterSyncEvent->getId() !== $masterSyncEvent->getParentId()
1122 $this->
handleSyncEvent($syncEvent, $syncEvent->getVendorEventId(), $masterSyncEvent);
1125 $existsExternalSyncEvent
1127 $syncEvent->isRecurrence()
1132 $this->removeDeprecatedInstances($existsExternalSyncEvent, $syncEvent);
1135 if ($syncEvent->hasInstances())
1137 $collection = $syncEvent->getInstanceMap()->getCollection();
1138 array_walk($collection, [$this,
'handleSyncEvent'], $syncEvent);
1141 $this->syncEventMap->updateItem($syncEvent, $syncEvent->getVendorEventId());
1153 private function getMasterSyncEvent(Sync\Entities\SyncEvent $syncEvent): ?Sync\Entities\SyncEvent
1156 $eventConnection = $syncEvent->getEventConnection();
1158 if ($eventConnection ===
null)
1160 throw new BaseException(
'you should set EventConnection in SyncEvent');
1163 if ($masterSyncEvent = $this->syncEventMap->getItem($eventConnection->getRecurrenceId()))
1165 return $masterSyncEvent;
1168 if ($eventConnection->getRecurrenceId())
1170 $recurrenceId[] = $eventConnection->getRecurrenceId();
1173 return $this->syncEventFactory->getSyncEventCollectionByVendorIdList(
1175 $this->factory->getConnection()->getId()
1184 private function prepareExcludedDatesMasterEvent(Sync\Entities\SyncEvent $masterSyncEvent, Core\Base\Date $excludedDate): void
1186 $masterEvent = $masterSyncEvent->getEvent();
1188 $date = clone $excludedDate;
1189 $date->format(Core\Event\Properties\ExcludedDatesCollection::EXCLUDED_DATE_FORMAT);
1191 if ($masterEvent->getExcludedDateCollection())
1193 $masterEvent->getExcludedDateCollection()->add($date);
1197 $masterEvent->setExcludedDateCollection(
new Core\Event\Properties\ExcludedDatesCollection([$date]));
1209 private function prepareNewEvent(Event $event, Sync\Entities\SyncSection $syncSection): void
1211 $section = $syncSection->getSection();
1212 $owner = $section->getOwner();
1213 if ($owner ===
null)
1215 throw new BaseException(
'section has not owner');
1219 ->setSection($syncSection->getSection())
1221 ->setCreator($owner)
1222 ->setEventHost($owner)
1225 ->setIsDeleted(
false)
1226 ->setCalendarType($owner->getType())
1241 public function handleMerge(
1242 Sync\Entities\SyncEventMap $localEventCollection,
1245 Sync\Entities\SyncEvent $syncEvent,
1246 ?Sync\Connection\EventConnection $eventConnection,
1247 Core\Event\Event $event,
1248 Sync\Entities\SyncSection $syncSection
1251 $mergedSyncEvent =
null;
1252 if ($localEventCollection->has($vendorId))
1255 $localEventCollection->getItem($vendorId),
1257 $localEventCollection->getItem($vendorId)->getEvent()->getId()
1259 $eventConnection->setId($localEventCollection->getItem($vendorId)->getEventConnection()->getId());
1262 $syncEvent->getEventConnection()
1263 && $localEventCollection->has($syncEvent->getEventConnection()
1264 ->getRecurrenceId())
1268 $masterSyncEvent = $localEventCollection->getItem($syncEvent->getEventConnection()->getRecurrenceId());
1274 $mergedSyncEvent->getEvent()->setRecurrenceId($masterSyncEvent->getEvent()->getId())
1277 if ($mergedSyncEvent !==
null)
1279 $event = $mergedSyncEvent->getEvent();
1283 $this->prepareNewEvent($event, $syncSection);
1293 private function mergeExternalEventWithLocalParams(Sync\Entities\SyncEvent $syncEvent): void
1296 if ($existsSyncEvent = $this->syncEventMap->getItem($syncEvent->getEventConnection()->getVendorEventId()))
1298 $this->mergeSyncEvent(
1301 $existsSyncEvent->getEventId(),
1302 $existsSyncEvent->getEventConnection()->getId()
1306 $syncEvent->isRecurrence()
1307 && $syncEvent->hasInstances()
1310 foreach ($syncEvent->getInstanceMap() as $instanceSyncEvent)
1313 $existsSyncEvent->hasInstances()
1314 && $instanceSyncEvent->getEvent()->getOriginalDateFrom()
1315 && $existsInstanceSyncEvent = $existsSyncEvent->getInstanceMap()->getItem(
1316 Sync\Entities\InstanceMap::getKeyByDate(
1317 $instanceSyncEvent->getEvent()->getOriginalDateFrom()
1322 $this->mergeSyncEvent(
1323 $existsInstanceSyncEvent,
1325 $existsInstanceSyncEvent->getEventId(),
1326 $existsInstanceSyncEvent->getEventConnection()->getId()
1331 $this->prepareNewSyncEvent($syncEvent);
1340 if ($existsMasterSyncEvent = $this->syncEventMap->getItem($syncEvent->getEventConnection()->getRecurrenceId()))
1343 $existsMasterSyncEvent->hasInstances()
1344 && $syncEvent->getEvent()->getOriginalDateFrom()
1345 && $existsInstanceSyncEvent = $existsMasterSyncEvent->getInstanceMap()->getItem(
1346 Sync\Entities\InstanceMap::getKeyByDate(
1347 $syncEvent->getEvent()->getOriginalDateFrom()
1352 $this->mergeSyncEvent(
1353 $existsInstanceSyncEvent,
1355 $existsInstanceSyncEvent->getEventId(),
1356 $existsInstanceSyncEvent->getEventConnection()->getId()
1362 $this->mergeSyncEvent($existsMasterSyncEvent, $syncEvent);
1369 $this->prepareNewSyncEvent($syncEvent);
1381 private function mergeSyncEvent(
1382 Sync\Entities\SyncEvent $existsSyncEvent,
1383 Sync\Entities\SyncEvent $externalSyncEvent,
1385 int $eventConnectionId =
null
1388 $handler =
new SyncEventMergeHandler();
1389 $handler($existsSyncEvent, $externalSyncEvent, $id, $eventConnectionId);
1396 private function prepareLocalSyncEventMapWithVendorEventId(Sync\Entities\SyncEventMap $externalSyncEventMap): void
1398 $vendorEventIdList = [];
1400 foreach ($externalSyncEventMap->getCollection() as $item)
1402 $vendorEventIdList[] = $item->getVendorEventId();
1403 if ($item->isInstance())
1405 $vendorEventIdList[] = $item->getVendorRecurrenceId();
1407 $this->importedLocalEventUidList[] = $item->getUid();
1410 $this->syncEventMap = $this->syncEventFactory->getSyncEventCollectionByVendorIdList(
1411 array_unique($vendorEventIdList),
1412 $this->factory->getConnection()->getId()
1420 private function prepareNewSyncEvent(Sync\Entities\SyncEvent $syncEvent): void
1429 private function updateExportedEvents(Sync\Entities\SyncEventMap $localEventMap): void
1432 foreach ($localEventMap as $syncEvent)
1436 $this->handleExportedFailedSyncEvent($syncEvent);
1440 if ($eventConnection = $syncEvent->getEventConnection())
1442 if ($eventConnection->getId())
1444 $this->eventConnectionMapper->update($eventConnection);
1448 $this->eventConnectionMapper->create($eventConnection);
1451 if ($syncEvent->hasInstances())
1453 $this->handleExportedInstances($syncEvent);
1463 private function updateMasterExdate(Event $masterEvent): void
1465 $handler =
new UpdateMasterExdateHandler();
1466 $handler($masterEvent);
1473 private function validateSyncSectionBeforeSave(Sync\Entities\SyncSection $syncSection): bool
1475 return $syncSection->getSection() && $syncSection->getSectionConnection();
1482 private function updateFailedSyncSection(Sync\Entities\SyncSection $syncSection): void
1490 private function filterBrokenSyncSections(): void
1496 foreach ($this->syncSectionMap as $key => $item)
1498 if ($item->getSectionConnection() ===
null)
1500 $this->syncSectionMap->remove($key);
1508 private function handleDeleteRecurrenceEvent(SyncEvent $syncEvent)
1516 private function handleDeleteSingleEvent(SyncEvent $syncEvent)
1528 private function handleExportedFailedSyncEvent(Sync\Entities\SyncEvent $syncEvent): void
1531 ($syncEvent->getEventConnection() ===
null)
1532 || ($syncEvent->getEventConnection()->getId() ===
null)
1538 $eventConnection = $syncEvent->getEventConnection();
1540 switch ($syncEvent->getAction())
1542 case Sync\Dictionary::SYNC_EVENT_ACTION[
'delete']:
1550 $this->eventConnectionMapper->update($eventConnection);
1563 private function blockSectionPush(Sync\Entities\SyncSectionMap
$syncSectionMap): void
1565 $pushManager =
new PushManager();
1569 $pushManager->setBlockPush(
1574 ($syncSection->getSectionConnection() !==
null)
1575 && ($syncSection->getSectionConnection()->getId() !==
null)
1578 $pushManager->setBlockPush(
1579 $pushManager->getPush(
1581 $syncSection->getSectionConnection()->getId()
1600 private function unblockSectionPush(Sync\Entities\SyncSectionMap
$syncSectionMap): void
1602 $pushManager =
new PushManager();
1606 $pushManager->setUnblockPush(
1610 if ($syncSection->getSectionConnection() !==
null
1611 && $syncSection->getSectionConnection()->getId() !==
null
1614 $pushManager->setUnblockPush(
1615 $pushManager->getPush(
1617 $syncSection->getSectionConnection()->getId()
1630 private function removeDeprecatedInstances(
1631 Sync\Entities\SyncEvent $existsExternalSyncEvent,
1632 Sync\Entities\SyncEvent $syncEvent
1635 if ($existsExternalSyncEvent->hasInstances())
1638 foreach ($existsExternalSyncEvent->getInstanceMap() as $key => $oldInstance)
1640 if (!$syncEvent->hasInstances() || empty($syncEvent->getInstanceMap()->getItem($key)))
1642 $this->eventConnectionMapper->delete($oldInstance->getEventConnection(), [
'softDelete' =>
false]);
1643 $this->eventMapper->delete($oldInstance->getEvent(), [
1644 'softDelete' =>
false,
1645 'originalFrom' => $syncEvent->getEventConnection()?->getConnection()->getVendor()->getCode(),
1646 'recursionMode' =>
'this',
1661 private function prepareSyncSectionBeforeExport(Sync\Entities\SyncSectionMap
$syncSectionMap): Sync\Entities\SyncSectionMap
1663 $syncSectionKeyIdList = [];
1667 if ($syncSection->getSectionConnection() ===
null)
1672 if (in_array($syncSection->getSection()->getId(), $syncSectionKeyIdList,
true))
1678 $syncSectionKeyIdList[$syncSection->getSectionConnection()->getVendorSectionId()] = $syncSection->getSection()->getId();
1681 $this->sectionConnectionMapper->delete($syncSection->getSectionConnection(), [
'softDelete' =>
false]);
1682 $this->syncSectionMap->remove($key);
1683 $syncSection->setSectionConnection(
null);
1687 if ($syncSectionKeyIdList)
1689 $syncEventMap = $this->syncEventFactory->getSyncEventMapBySyncSectionIdCollectionForExport(
1690 $syncSectionKeyIdList,
1691 $this->factory->getConnection()->getOwner()->getId(),
1692 $this->factory->getConnection()->getId()
1699 if ($syncEvent->getEventConnection() ===
null)
1704 $this->eventConnectionMapper->delete($syncEvent->getEventConnection(), [
'softDelete' =>
false]);
1720 private function noticeUser(Sync\Entities\SyncEvent $syncEvent,
string $messageCode =
'')
1722 if (Loader::includeModule(
'im') && Loader::includeModule(
'pull'))
1724 $path = CCalendar::GetPath(
1725 $syncEvent->getEvent()->getOwner()->getType(),
1726 $syncEvent->getEvent()->getOwner()->getId(),
1728 $uri = (
new Uri($path))
1729 ->deleteParams([
"action",
"sessid",
"bx_event_calendar_request",
"EVENT_ID",
"EVENT_DATE"])
1731 'EVENT_ID' => $syncEvent->getEvent()->getId()])
1735 $syncEvent->getEventConnection()->getConnection()->getOwner()->getId(),
1738 '#EVENT_URL#' => $uri->getUri(),
1739 '#EVENT_TITLE#' => $syncEvent->getEvent()->getName(),
1740 'EVENT_ID' => $syncEvent->getEvent()->getId(),
1758 $mapperFactory = ServiceLocator::getInstance()->get(
'calendar.service.mappers.factory');
1759 $links = $mapperFactory->getSectionConnection()->getMap([
1760 '=CONNECTION_ID' => $connection->getId(),
1764 $manager = $this->getOutgoingManager($connection);
1765 foreach ($links as $link)
1767 $manager->subscribeSection($link);
1770 $manager->subscribeConnection();
1780 private function getOutgoingManager(
Connection $connection)
1782 if (empty(static::$outgoingManagersCache[$connection->getId()]))
1784 static::$outgoingManagersCache[$connection->getId()] =
new OutgoingManager($connection);
1787 return static::$outgoingManagersCache[$connection->getId()];