name); $steps = $this->stepBuilder->build($data->steps); $this->transactions->run(function () use ($templateId, $data, $name, $steps): void { $template = $this->templates->findById($templateId) ?? throw new WorkflowTemplateNotFound($templateId); $workType = $this->workTypes->findById($data->workTypeId); $workTypeChanged = $data->workTypeId !== $template->workTypeId(); if ($workType === null || ($workTypeChanged && ! $workType->isActive())) { throw new CatalogItemNotFound(CatalogLevel::WorkType, $data->workTypeId); } if ($this->templates->isNameTaken($data->workTypeId, $name->value, $templateId)) { throw new WorkflowTemplateNameTaken; } $this->stepBuilder->checkWorkTypes($workType, $steps, $template->steps()); $template->change($data->workTypeId, $name, $steps); $this->templates->save($template); }); } }