• Модуль: calendar
  • Путь к файлу: ~/bitrix/modules/calendar/lib/sync/office365/sectionmanager.php
  • Класс: BitrixCalendarSyncOffice365SectionManager
  • Вызов: SectionManager::updateSectionsAgent
static function updateSectionsAgent(): string
{
	$agentName = __METHOD__ . '();';

	try
	{
		if (!Loader::includeModule('dav') || !Loader::includeModule('calendar'))
		{
			throw new SystemException('Module not found');
		}
		$connectionsEO = DavConnectionTable::query()
			->setSelect(['*'])
			->addFilter('=ACCOUNT_TYPE', [Helper::ACCOUNT_TYPE])
			->addFilter('=IS_DELETED', 'N')
			->addOrder('SYNCHRONIZED')
			->setLimit(self::IMPORT_SECTIONS_LIMIT)
			->exec();

		while ($connectionEO = $connectionsEO->fetchObject())
		{
			try
			{
				$connection = (new BuilderConnectionFromDM($connectionEO))->build();
				$manager    = new IncomingManager($connection);
				$result = $manager->importSections();
				if ($result->isSuccess())
				{
					DavConnectionTable::update($connectionEO->getId(), [
						'SYNCHRONIZED' => new DateTime(),
						'LAST_RESULT'  => '[200] OK',
					]);
				}
				else
				{
					DavConnectionTable::update($connectionEO->getId(), [
						'SYNCHRONIZED' => new DateTime(),
						'LAST_RESULT'  => '[400] Error.',
					]);
				}
			}
			catch (Exception $e)
			{
				DavConnectionTable::update($connectionEO->getId(), [
					'SYNCHRONIZED' => new DateTime(),
					'LAST_RESULT'  => '[400] Error.',
				]);
			}

		}
	} catch (BaseException|Throwable $e) {
		// TODO: write into log
	}

	return $agentName;
}