• Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/lib/automation/tunnelmanager.php
  • Класс: Bitrix\Crm\Automation\TunnelManager
  • Вызов: TunnelManager::updateTunnel
public function updateTunnel(int $userId, array $tunnel): Main\Result
{
	$result = new Main\Result();

	if (!$this->isAvailable())
	{
		$result->addError(new Error(Loc::getMessage('CRM_AUTOMATION_TUNNEL_UNAVAILABLE')));
		return $result;
	}

	$srcCategory = (int)$tunnel['srcCategory'];
	$dstCategory = (int)$tunnel['robot']['Properties']['CategoryId'];

	if ($srcCategory === $dstCategory)
	{
		$result->addError(new Error(Loc::getMessage('CRM_AUTOMATION_TUNNEL_ADD_ERROR_SAME_CATEGORY2')));
		return $result;
	}

	$template = new Bizproc\Automation\Engine\Template($this->documentType, $tunnel['srcStage']);

	if ($template->isExternalModified())
	{
		$result->addError(new Error(Loc::getMessage('CRM_AUTOMATION_TUNNEL_ADD_ERROR_EXTERNAL_TEMPLATE')));
	}
	else
	{
		$robotName = $tunnel['robot']['Name'];
		$robots = $template->getRobots();

		foreach ($robots as $i => $robot)
		{
			if ($robot->getName() === $robotName)
			{
				$robots[$i] = new Bizproc\Automation\Engine\Robot($tunnel['robot']);
				$saveResult = $template->save($robots, $userId);
				if (!$saveResult->isSuccess())
				{
					$result->addErrors($saveResult->getErrors());
				}
				else
				{
					$result->setData([
						'tunnel' => $this->prepareRobotToTunnel($robot, $tunnel['srcStage'], $tunnel['srcCategory'])
					]);
				}

				break;
			}
		}
	}

	return $result;
}