- Модуль: tasks
- Путь к файлу: ~/bitrix/modules/tasks/lib/rest/controllers/scrum/backlog.php
- Класс: BitrixTasksRestControllersScrumBacklog
- Вызов: Backlog::updateAction
public function updateAction(int $id, array $fields)
{
$id = (int) $id;
if (!$id)
{
$this->errorCollection->add([new Error('Backlog id not found')]);
return null;
}
$entityService = new EntityService();
$backlogService = new BacklogService();
$backlog = $entityService->getEntityById($id);
if ($backlog->isEmpty())
{
$this->errorCollection->add([new Error('Backlog not found')]);
return null;
}
if ($backlog->getEntityType() !== EntityForm::BACKLOG_TYPE)
{
$this->errorCollection->add([new Error('Backlog not found')]);
return null;
}
if (!$this->checkAccess($backlog->getGroupId()))
{
$this->errorCollection->add([new Error('Access denied')]);
return null;
}
if (array_key_exists('groupId', $fields) && is_numeric($fields['groupId']))
{
$groupId = (int) $fields['groupId'];
$itemService = new ItemService();
$isGroupUpdatingAction = ($backlog->getGroupId() !== $groupId);
$hasBacklogItems = (!empty($itemService->getItemIdsByEntityId($backlog->getId())));
if ($isGroupUpdatingAction)
{
if ($hasBacklogItems)
{
$this->errorCollection->add([new Error('It is forbidden move a backlog with items')]);
return null;
}
$targetBacklog = $backlogService->getBacklogByGroupId($groupId);
if (!$targetBacklog->isEmpty())
{
$this->errorCollection->add([new Error('The target group already has a backlog')]);
return null;
}
}
$backlog->setGroupId($groupId);
}
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;
}
$backlog->setCreatedBy($createdBy);
}
$modifiedBy = 0;
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;
}
}
$backlog->setModifiedBy($modifiedBy ?? $this->getUserId());
$backlogService->changeBacklog($backlog);
if (!empty($backlogService->getErrors()))
{
$this->errorCollection->add([new Error('Unable to update backlog')]);
return null;
}
return [
'id' => $backlog->getId(),
'groupId' => $backlog->getGroupId(),
'createdBy' => $backlog->getCreatedBy(),
'modifiedBy' => $backlog->getModifiedBy(),
];
}