• Модуль: tasks
  • Путь к файлу: ~/bitrix/modules/tasks/lib/rest/controllers/scrum/kanban.php
  • Класс: BitrixTasksRestControllersScrumKanban
  • Вызов: Kanban::updateStageAction
public function updateStageAction(int $stageId, array $fields): bool
{
	$stageId = (int) $stageId;
	if (!$stageId)
	{
		$this->errorCollection->add([new Error('Stage id not found')]);

		return false;
	}

	try
	{
		$queryObject = StagesTable::getById($stageId);
		if ($stage = $queryObject->fetch())
		{
			$sprintId = $stage['ENTITY_ID'];

			$sprintService = new SprintService();

			$sprint = $sprintService->getSprintById($sprintId);

			if (!$sprint->getId() || !$this->checkAccess($sprint->getGroupId()))
			{
				$this->errorCollection->add([new Error('Access denied')]);

				return false;
			}

			$updatedFields = [];

			if (array_key_exists('name', $fields) && is_string($fields['name']))
			{
				$updatedFields['TITLE'] = $fields['name'];
			}

			if (array_key_exists('sprintId', $fields) && is_numeric($fields['sprintId']))
			{
				$newSprint = $sprintService->getSprintById($fields['sprintId']);
				if (!$newSprint->getId() || !$this->checkAccess($newSprint->getGroupId()))
				{
					$this->errorCollection->add([new Error('Incorrect sprintId value')]);

					return false;
				}

				$updatedFields['ENTITY_ID'] = $newSprint->getId();
			}

			if (array_key_exists('color', $fields) && is_string($fields['color']))
			{
				$updatedFields['COLOR'] = $fields['color'];
			}

			if (array_key_exists('sort', $fields) && is_numeric($fields['sort']))
			{
				$updatedFields['SORT'] = $fields['sort'];
			}

			$availableTypes = [
				StagesTable::SYS_TYPE_NEW,
				StagesTable::SYS_TYPE_PROGRESS,
				StagesTable::SYS_TYPE_FINISH,
			];
			if (array_key_exists('type', $fields) && in_array($fields['type'], $availableTypes, true))
			{
				$updatedFields['SYSTEM_TYPE'] = $fields['type'];
			}

			if ($updatedFields)
			{
				$result = StagesTable::update($stage['ID'], $updatedFields);

				if (!$result->isSuccess())
				{
					$this->errorCollection->setError(new Error('System error'));

					return false;
				}
			}

			return true;
		}
		else
		{
			$this->errorCollection->setError(new Error('Stage not found'));

			return false;
		}
	}
	catch (Exception $exception)
	{
		$this->errorCollection->setError(new Error('System error'));

		return false;
	}
}