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

		return null;
	}

	$entityService = new EntityService();
	$sprint = $entityService->getEntityById($id);

	if (!$sprint->getId())
	{
		$this->errorCollection->add([new Error('Sprint not found')]);

		return null;
	}
	if ($sprint->getEntityType() !== EntityForm::SPRINT_TYPE)
	{
		$this->errorCollection->add([new Error('Sprint not found')]);

		return null;
	}

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

		return null;
	}

	$itemService = new ItemService();
	$backlogService = new BacklogService();

	$backlog = $backlogService->getBacklogByGroupId($sprint->getGroupId());

	$hasSprintItems = (!empty($itemService->getItemIdsByEntityId($sprint->getId())));

	if ($hasSprintItems)
	{
		if ($backlog->isEmpty())
		{
			$this->errorCollection->add([new Error('It is forbidden remove a sprint with items')]);

			return null;
		}
		else
		{
			$itemService->moveItemsToEntity(
				$itemService->getItemIdsByEntityId($sprint->getId()),
				$backlog->getId()
			);

			if ($itemService->getErrors())
			{
				$this->errorCollection->add([new Error('Sprint items have not been moved to backlog')]);

				return null;
			}
		}
	}

	$sprintService = new SprintService();
	if (!$sprintService->removeSprint($sprint))
	{
		$this->errorCollection->add([new Error('Sprint not deleted')]);
	}

	return [];
}