16use Bitrix\Calendar\Sync\Internals\HasContextTrait;
24use Bitrix\Dav\Internals\DavConnectionTable;
40 private const IMPORT_SECTIONS_LIMIT = 10;
44 $this->context = $context;
69 'name' => $this->getSectionName($section),
72 $sectionDto = $this->context->getVendorSyncService()->createSection($dto);
73 if (!empty($sectionDto->id) && !empty($sectionDto->changeKey))
76 ->setSection($section)
77 ->setConnection($this->connection)
78 ->setVendorSectionId($sectionDto->id)
79 ->setVersionId($sectionDto->changeKey)
85 ->setSection($section)
86 ->setSectionConnection($sectionConnection)
91 $sectionDto->id => $syncSection,
92 'id' => $sectionDto->id,
93 'version' => $sectionDto->changeKey,
94 'syncSection' => $syncSection,
99 $result->addError(
new Error(
'Error of create section into Office365'));
110 private function getSectionName(
Section $section): string
114 IncludeModuleLangFile($_SERVER[
'DOCUMENT_ROOT'] . BX_ROOT .
'/modules/calendar/classes/general/calendar.php');
133 'name' => $this->getSectionName($sectionLink->getSection()),
141 if ($sectionLink->isPrimary())
145 $sectionDto = $this->context->getVendorSyncService()->updateSection($dto);
147 'id' => $sectionDto->id,
148 'version' => $sectionDto->changeKey,
149 'sectionConnection' => $sectionLink,
158 $result->addError(
new Error($e->getMessage()));
167 $sectionLink = $context->getSectionConnection();
170 'id' => $sectionLink->getVendorSectionId(),
174 $this->context->getVendorSyncService()->deleteSection($dto);
176 'sectionConnection' => $sectionLink,
181 $result->addError(
new Error($e->getMessage()));
206 $converter = $this->context->getConverter();
207 $sections = $this->context->getVendorSyncService()->getSections();
208 foreach ($sections as $sectionDto)
210 if ($sectionDto->canShare)
213 'section' => $converter->convertSection($sectionDto),
214 'id' => $sectionDto->id,
215 'version' => $sectionDto->changeKey,
216 'is_primary' => $sectionDto->isDefaultCalendar,
234 $makeDateTime =
static function (
string $date)
236 $phpDateTime = new \DateTime($date);
263 $data = $this->context->getVendorSyncService()->subscribeSection($link);
268 'CHANNEL_ID' => $data[
'channelId'],
269 'RESOURCE_ID' => $data[
'id'],
270 'EXPIRES' => $makeDateTime($data[
'expirationDateTime']),
275 $result->addError(
new Error(
'Error of create subscription.'));
292 $data = $this->context->getVendorSyncService()->resubscribe($push->
getResourceId());
305 $agentName = __METHOD__ .
'();';
309 if (!Loader::includeModule(
'dav') || !Loader::includeModule(
'calendar'))
313 $connectionsEO = DavConnectionTable::query()
316 ->addFilter(
'=IS_DELETED',
'N')
317 ->addOrder(
'SYNCHRONIZED')
318 ->setLimit(self::IMPORT_SECTIONS_LIMIT)
321 while ($connectionEO = $connectionsEO->fetchObject())
327 $result = $manager->importSections();
328 if ($result->isSuccess())
330 DavConnectionTable::update($connectionEO->getId(), [
332 'LAST_RESULT' =>
'[200] OK',
337 DavConnectionTable::update($connectionEO->getId(), [
339 'LAST_RESULT' =>
'[400] Error.',
345 DavConnectionTable::update($connectionEO->getId(), [
347 'LAST_RESULT' =>
'[400] Error.',
static toOffice(?string $color=null)
static updateSectionsAgent()
getAvailableExternalType()
__construct(Office365Context $context)
create(Section $section, SectionContext $context)
update(Section $section, SectionContext $context)
static getMessage($code, $replace=null, $language=null)
static createFromPhp(\DateTime $datetime)