- Модуль: calendar
- Путь к файлу: ~/bitrix/modules/calendar/lib/sync/managers/incomingmanager.php
- Класс: BitrixCalendarSyncManagersIncomingManager
- Вызов: IncomingManager::importSections
public function importSections(): Result
{
// In this case we can guess, they were deleted on the vendor side.
$resultData = [
'links' => [
'updated' => [],
'imported' => [],
'skipped' => [],
],
'vendorSections' => [],
];
$result = new Result();
$getResult = $this->getFactory()->getIncomingSectionManager()->getSections();
if ($getResult->isSuccess())
{
$sections = $getResult->getData()['externalSyncSectionMap'];
$mapper = $this->mapperFactory->getSection();
/** @var SyncSection $syncSection */
foreach ($sections as $syncSection)
{
$link = null;
try {
if ($link = $this->getSectionLinkByVendorId($syncSection->getSectionConnection()->getVendorSectionId()))
{
$resultData['linkedSectionIds'][] = $link->getSection()->getId();
if (!$link->isActive())
{
$resultData['links']['skipped'][] = $link;
continue;
}
if (
!empty($syncSection->getAction() === 'updated')
&& $syncSection->getSection()->getDateModified() > $link->getSection()->getDateModified()
)
{
$section = $this->mergeSections($link->getSection(), $syncSection->getSection());
$mapper->update($section, [
'originalFrom' => $this->connection->getVendor()->getCode(),
]);
(new CoreMappersSectionConnection())->update($link);
$resultData['importedSectionIds'][] = $link->getSection()->getId();
$resultData['links']['updated'][] = $link;
}
}
else
{
$link = $this->importSectionSimple(
$syncSection->getSection(),
$syncSection->getSectionConnection()->getVendorSectionId(),
$syncSection->getSectionConnection()->getVersionId() ?? null,
$syncSection->getSectionConnection()->isPrimary() ?? null,
);
$resultData['links']['imported'][] = $link;
}
if (!empty($link))
{
$resultData['importedSectionIds'][] = $link->getSection()->getId();
}
}
catch (SystemException $e)
{
$resultData['sections'][$syncSection['id']] = Dictionary::SYNC_STATUS['failed'];
}
}
return $result->setData($resultData);
}
else
{
$result->addErrors($getResult->getErrors());
return $result;
}
}