Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
synclocaldatasection.php
1<?php
2
4
19
20
22{
26 public function export(SyncEventMap $syncEventMap, SyncSectionMap $syncSectionMap)
27 {
28 // $syncEventMap = new SyncEventMap();
30 foreach ($syncSectionMap as $syncSection)
31 {
32 if ($syncSection->getSectionConnection()->getVendorSectionId() !== null)
33 {
34 GoogleApiPush::setBlockPush(GoogleApiPush::TYPE_SECTION, $syncSection->getSection()->getId());
35 if (
36 $events = \CCalendarEvent::getLocalBatchEvent(
37 $syncSection->getSection()->getOwner()->getId(),
38 $syncSection->getSection()->getId(),
39 $this->getSyncTimestamp())
40 )
41 {
42 $syncedEvents = (new GoogleApiBatch())
43 ->syncLocalEvents(
44 $events,
45 $syncSection->getSection()->getOwner()->getId(),
46 $syncSection->getSectionConnection()->getVendorSectionId()
47 );
48
49 $this->updateEventsBatch($syncedEvents);
50
51 continue;
52 }
53
54 if (
55 $recurrentEvents = \CCalendarEvent::getLocalBatchRecurrentEvent(
56 $syncSection->getSection()->getOwner()->getId(),
57 $syncSection->getSection()->getId(),
58 $this->getSyncTimestamp())
59 )
60 {
61
62 $syncedEvents = (new GoogleApiBatch())->syncLocalEvents(
63 $recurrentEvents,
64 $syncSection->getSection()->getOwner()->getId(),
65 $syncSection->getSectionConnection()->getVendorSectionId()
66 );
67 $this->updateEventsBatch($syncedEvents);
68
69 continue;
70 }
71
72 if (
73 $instances = \CCalendarEvent::getLocalBatchInstances(
74 $syncSection->getSection()->getOwner()->getId(),
75 $syncSection->getSection()->getId(),
76 $this->getSyncTimestamp())
77 )
78 {
79 $syncedInstances = (new GoogleApiBatch())->syncLocalInstances(
80 $instances,
81 $syncSection->getSection()->getOwner()->getId(),
82 $syncSection->getSectionConnection()->getVendorSectionId()
83 );
84
85 $this->updateEventsBatch($syncedInstances);
86
87 continue;
88 }
89
90 GoogleApiPush::setUnblockPush(GoogleApiPush::TYPE_SECTION, $syncSection->getSection()->getId());
91
92 // $pushOptionEnabled = \COption::GetOptionString('calendar', 'sync_by_push', false);
93 // if ($pushOptionEnabled || \CCalendar::IsBitrix24())
94 // {
95 // GoogleApiPush::deletePushChannel(['ENTITY_TYPE' => 'SECTION', 'ENTITY_ID' => $syncSection->getSection()->getId()]);
96 // GoogleApiPush::checkSectionsPush(
97 // [$syncSection->getSection()],
98 // $syncSection->getSection()->getOwner()->getId(),
99 // $syncSection->getSectionConnection()->getConnection()->getId()
100 // );
101 // }
102 }
103 }
104
105 // todo move to DataExchangeManager::exchange
106 // Util::addPullEvent(
107 // 'process_sync_connection',
108 // (int)$section['OWNER_ID'],
109 // [
110 // 'vendorName' => 'google',
111 // 'stage' => 'events_created',
112 // ]
113 // );
114 }
115
119 private function updateEventsBatch(array $eventsBatch): void
120 {
121 \CCalendarEvent::updateBatchEventFields($eventsBatch, ['DAV_XML_ID', 'G_EVENT_ID', 'CAL_DAV_LABEL', 'ORIGINAL_DATE_FROM', 'SYNC_STATUS']);
122 }
123
128 private function getSyncTimestamp(): int
129 {
130 return (new Date())->sub(ImportManager::SYNC_EVENTS_DATE_INTERVAL)->getTimestamp();
131 }
132}