• Модуль: crmmobile
  • Путь к файлу: ~/bitrix/modules/crmmobile/lib/Controller/Stage.php
  • Класс: BitrixCrmMobileControllerStage
  • Вызов: Stage::updateAction
public function updateAction(Factory $factory, array $fields): bool
{
	$stage = $factory->getStage($fields['statusId']);

	if (!$stage)
	{
		$this->addError(new Error(Loc::getMessage('CRM_STAGE_STAGE_NOT_FOUND')));
		return false;
	}

	if (!Container::getInstance()->getUserPermissions()->canWriteConfig())
	{
		$this->addError(ErrorCode::getAccessDeniedError());
		return false;
	}

	if (isset($fields['name']) && is_string($fields['name']))
	{
		$stage->setName($fields['name']);
	}

	if (isset($fields['color']) && is_string($fields['color']))
	{
		$stage->setColor($fields['color']);
	}

	$result = $stage->save();
	if (!$result->isSuccess())
	{
		$this->addErrors($result->getErrors());
		return false;
	}

	if (!isset($fields['tunnels']) || !is_array($fields['tunnels']))
	{
		$fields['tunnels'] = [];
	}

	$categoriesEnabled = $factory->isCategoriesEnabled();
	$stagesEnabled = $factory->isStagesEnabled();

	if ($categoriesEnabled && $stagesEnabled)
	{
		$userId = $this->getCurrentUser()->getId();
		$tunnelManager = new BitrixCrmAutomationTunnelManager($factory->getEntityTypeId());
		$tunnelManagerResult = $tunnelManager->updateStageTunnels(
			$fields['tunnels'],
			$stage->getStatusId(),
			$userId
		);

		if (!$tunnelManagerResult->isSuccess())
		{
			$this->addErrors($tunnelManagerResult->getErrors());
			return false;
		}
	}

	return true;
}