3namespace Bitrix\Calendar\Sync\Office365;
5use Bitrix\Calendar\Core\Base\BaseException;
6use Bitrix\Calendar\Core\Section\Section;
7use Bitrix\Calendar\Sync;
8use Bitrix\Calendar\Sync\Builders\BuilderConnectionFromDM;
9use Bitrix\Calendar\Sync\Connection\SectionConnection;
10use Bitrix\Calendar\Sync\Entities\SyncSection;
11use Bitrix\Calendar\Sync\Exceptions\ApiException;
12use Bitrix\Calendar\Sync\Exceptions\AuthException;
13use Bitrix\Calendar\Sync\Exceptions\ConflictException;
14use Bitrix\Calendar\Sync\Exceptions\NotFoundException;
15use Bitrix\Calendar\Sync\Exceptions\RemoteAccountException;
16use Bitrix\Calendar\Sync\Internals\HasContextTrait;
17use Bitrix\Calendar\Sync\Managers\IncomingManager;
18use Bitrix\Calendar\Sync\Managers\SectionManagerInterface;
19use Bitrix\Calendar\Sync\Office365\Converter\ColorConverter;
20use Bitrix\Calendar\Sync\Office365\Dto\SectionDto;
21use Bitrix\Calendar\Sync\Push\Push;
22use Bitrix\Calendar\Sync\Util\Result;
23use Bitrix\Calendar\Sync\Util\SectionContext;
24use Bitrix\Dav\Internals\DavConnectionTable;
25use Bitrix\Main\ArgumentException;
26use Bitrix\Main\ArgumentNullException;
28use Bitrix\Main\Loader;
29use Bitrix\Main\LoaderException;
30use Bitrix\Main\Localization\Loc;
31use Bitrix\Main\SystemException;
32use Bitrix\Main\Type\DateTime;
40 private const IMPORT_SECTIONS_LIMIT = 10;
45 parent::__construct(
$context->getConnection());
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
116 return Loc::getMessage(
'EC_CALENDAR_BITRIX24_NAME')
130 $sectionLink =
$context->getSectionConnection();
133 'name' => $this->getSectionName($sectionLink->getSection()),
134 'id' =>
$context->getSectionConnection()->getVendorSectionId(),
141 if ($sectionLink->isPrimary())
145 $sectionDto = $this->context->getVendorSyncService()->updateSection($dto);
147 'id' => $sectionDto->id,
148 'version' => $sectionDto->changeKey,
149 'sectionConnection' => $sectionLink,
167 $sectionLink =
$context->getSectionConnection();
170 'id' => $sectionLink->getVendorSectionId(),
174 $this->context->getVendorSyncService()->deleteSection($dto);
176 'sectionConnection' => $sectionLink,
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);
237 return DateTime::createFromPhp($phpDateTime);
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.'));
295 'EXPIRES' => DateTime::createFromPhp(
new \
DateTime(
$data[
'expirationDateTime'])),
305 $agentName = __METHOD__ .
'();';
309 if (!Loader::includeModule(
'dav') || !Loader::includeModule(
'calendar'))
313 $connectionsEO = DavConnectionTable::query()
315 ->addFilter(
'=ACCOUNT_TYPE', [Helper::ACCOUNT_TYPE])
316 ->addFilter(
'=IS_DELETED',
'N')
317 ->addOrder(
'SYNCHRONIZED')
318 ->setLimit(self::IMPORT_SECTIONS_LIMIT)
321 while ($connectionEO = $connectionsEO->fetchObject())
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.',
361 return [Helper::ACCOUNT_TYPE];
static toOffice(?string $color=null)
static updateSectionsAgent()
getAvailableExternalType()
__construct(Office365Context $context)
create(Section $section, SectionContext $context)
update(Section $section, SectionContext $context)
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
$_SERVER["DOCUMENT_ROOT"]
IncludeModuleLangFile($filepath, $lang=false, $bReturnArray=false)