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

		return null;
	}

	$epicService = new EpicService($this->getUserId());

	$epic = $epicService->getEpic($id);
	if (!$epic->getId())
	{
		$this->errorCollection->add([new Error('Epic not found')]);

		return null;
	}
	if (!$this->checkAccess($epic->getGroupId()))
	{
		$this->errorCollection->add([new Error('Access denied')]);

		return null;
	}

	$inputEpic = new EpicForm();

	if (array_key_exists('groupId', $fields) && is_numeric($fields['groupId']))
	{
		if (!$this->checkAccess($fields['groupId']))
		{
			$this->errorCollection->add([new Error('Access denied')]);

			return null;
		}

		$inputEpic->setGroupId($fields['groupId']);
	}

	if (array_key_exists('name', $fields) && is_string($fields['name']))
	{
		$inputEpic->setName($fields['name']);
	}

	if (array_key_exists('description', $fields) && is_string($fields['description']))
	{
		$userFields = $epicService->getFilesUserField($this->getUserFieldManager(), $epic->getId());

		$inputEpic->setDescription($this->sanitizeText($fields['description'], $userFields));
	}

	if (array_key_exists('createdBy', $fields) && is_numeric($fields['createdBy']))
	{
		$createdBy = (int) $fields['createdBy'];
		if (!$this->existsUser($createdBy))
		{
			$this->errorCollection->add([new Error('createdBy user not found')]);

			return null;
		}

		$inputEpic->setCreatedBy($createdBy);
	}

	$modifiedBy = null;
	if (array_key_exists('modifiedBy', $fields) && is_numeric($fields['modifiedBy']))
	{
		$modifiedBy = (int) $fields['modifiedBy'];
		if (!$this->existsUser($modifiedBy))
		{
			$this->errorCollection->add([new Error('modifiedBy user not found')]);

			return null;
		}
	}
	$inputEpic->setModifiedBy($modifiedBy ?? $this->getUserId());

	if (array_key_exists('color', $fields) && is_string($fields['color']))
	{
		$inputEpic->setColor($fields['color']);
	}

	$epicService->updateEpic($epic->getId(), $inputEpic);
	if (!empty($epicService->getErrors()))
	{
		$this->errorCollection->add([new Error('Epic not updated')]);

		return null;
	}

	if (array_key_exists('files', $fields))
	{
		$files = (is_array($fields['files']) ? $fields['files'] : []);

		$epicService->attachFiles($this->getUserFieldManager(), $epic->getId(), $files);
		if (!empty($epicService->getErrors()))
		{
			$this->errorCollection->add([new Error('Epic files not attached')]);

			return null;
		}
	}

	$epic = $epicService->getEpic($id);

	return $epic->toArray();
}