- Модуль: rpa
- Путь к файлу: ~/bitrix/modules/rpa/lib/controller/stage.php
- Класс: BitrixRpaControllerStage
- Вызов: Stage::updateAction
public function updateAction(BitrixRpaModelStage $stage, array $fields, string $eventId = ''): ?array
{
$isNew = (!($stage->getId() > 0));
unset($fields['id']);
if($stage->getId() > 0)
{
unset($fields['typeId']);
}
$converter = new Converter(Converter::TO_UPPER | Converter::KEYS | Converter::TO_SNAKE);
$previousStageId = null;
if(isset($fields['previousStageId']))
{
$previousStageId = (int) $fields['previousStageId'];
}
$fields = $converter->process($fields);
foreach($fields as $name => $value)
{
if($stage->entity->hasField($name))
{
$stage->set($name, $value);
}
}
if($previousStageId !== null)
{
$sort = $this->getSortByPreviousStageId($stage, $previousStageId);
$stage->setSort($sort);
}
$result = $stage->save();
if($result->isSuccess())
{
$permissionResult = $this->processPermissions($stage, $fields);
$permissionResult = $this->savePermissions($stage, $permissionResult);
if(!$permissionResult->isSuccess())
{
$this->addErrors($permissionResult->getErrors());
}
if(isset($fields['FIELDS']))
{
$fieldResult = FieldTable::mergeSettings($stage->getTypeId(), $stage->getId(), $fields['FIELDS']);
if(!$fieldResult->isSuccess())
{
$this->addErrors($fieldResult->getErrors());
}
}
if(isset($fields['POSSIBLE_NEXT_STAGES']))
{
if(!is_array($fields['POSSIBLE_NEXT_STAGES']))
{
$fields['POSSIBLE_NEXT_STAGES'] = [];
}
$possibleNextStagesResult = $this->processPossibleNextStages($stage, $fields['POSSIBLE_NEXT_STAGES']);
if(!$possibleNextStagesResult->isSuccess())
{
$this->addErrors($possibleNextStagesResult->getErrors());
}
}
$userPermissions = Driver::getInstance()->getUserPermissions();
$userPermissions->loadUserPermissions();
if($isNew)
{
$stage->getType()->getStages()->add($stage);
Driver::getInstance()->getPullManager()->sendStageAddedEvent($stage, $eventId);
}
else
{
Driver::getInstance()->getPullManager()->sendStageUpdatedEvent($stage, $eventId);
}
if($previousStageId !== null)
{
$stage->getType()->resortStages();
}
return $this->getAction($stage);
}
else
{
$this->addErrors($result->getErrors());
return null;
}
}