• Модуль: calendar
  • Путь к файлу: ~/bitrix/modules/calendar/lib/sync/office365/startsynccontroller.php
  • Класс: BitrixCalendarSyncOffice365StartSyncController
  • Вызов: StartSyncController::start
public function start(): ?Connection
{
	/** @var Connection $connection */
	if ($connection = $this->initConnection())
	{
		// TODO: change it to disabling update sections agent
		$this->muteConnection($connection, true);
		$status = self::STATUSES['connection_created'];
		try
		{
			$connection = $this->fixUglyAccountName($connection);
			$this->sendResult($status);
			// $status = self::STATUSES['connection_renamed']; // this status is virtual. We can't roll back it.

			$factory = new Factory($connection);

			$exchangeManager = new VendorDataExchangeManager(
				$factory,
				(new SyncSectionFactory())->getSyncSectionMapByFactory($factory)
			);

			$exchangeManager
				->addStatusHandlerList($this->getStatusHandlerList())
				->exchange();

			$status = self::STATUSES['events_sync_finished'];
			$this->sendResult($status);

			if ($this->isPushEnabled())
			{
				$this->initSubscription($connection);
				$status = self::STATUSES['subscribe_finished'];
				$this->sendResult($status);
			}

			$this->setConnectionStatus($connection, SyncDictionary::SYNC_STATUS['success']);

			$this->muteConnection($connection, false);
			return $connection;
		}
		catch (SyncException|Throwable $e)
		{
			// TODO: remove Throwable after finish of testing
			$this->rollBack($connection);
			throw $e;
		}
	}

	throw new SyncException('Error of create connection');
}