• Модуль: calendar
  • Путь к файлу: ~/bitrix/modules/calendar/lib/sync/icloud/vendorsyncmanager.php
  • Класс: BitrixCalendarSyncIcloudVendorSyncManager
  • Вызов: VendorSyncManager::initConnection
public function initConnection(array $connectionRaw): ?int
{
	$connection = null;
	$calendarPath = $this->getSyncService()->getCalendarServerPath($connectionRaw);
	if (!$calendarPath)
	{
		$this->error = 'Error while trying to get calendars path';

		return null;
	}
	$owner = CoreRoleHelper::getRole(CCalendar::GetUserId(), CoreRoleUser::TYPE);
	$connectionManager = new ManagersConnectionManager();
	$connections = $connectionManager->getConnectionsData($owner, [Helper::ACCOUNT_TYPE]);
	foreach ($connections as $con)
	{
		$existPath = $con->getServerScheme()
			. '://'
			. $con->getServerHost()
			. ':'
			. $con->getServerPort()
			. $con->getServerPath()
		;
		if ($existPath === $calendarPath)
		{
			$connection = (new BuilderConnectionFromDM($con))->build();
			break;
		}
	}

	if ($connection)
	{
		if ($connection->isDeleted())
		{
			$connection->setDeleted(false);
			$connection->getServer()->setPassword($connectionRaw['SERVER_PASSWORD']);
		}

		$connectionManager->update($connection);
		return $connection->getId();
	}

	return $this->addConnection($connectionRaw, $calendarPath);
}