public function testImport() { $expectedData = array('name' => 'test_name', 'label' => 'test_label', 'enabled' => false, 'start_step' => 'test_step', 'configuration' => array('test', 'configuration'), 'entities' => array(array('class' => 'TestClass'))); $this->assertNotEquals($expectedData, $this->getDefinitionAsArray($this->workflowDefinition)); $definitionEntity = new WorkflowDefinitionEntity(); $definitionEntity->setClassName($expectedData['entities'][0]['class']); $newDefinition = new WorkflowDefinition(); $newDefinition->setName($expectedData['name'])->setLabel($expectedData['label'])->setEnabled($expectedData['enabled'])->setStartStep($expectedData['start_step'])->setConfiguration($expectedData['configuration'])->setWorkflowDefinitionEntities(array($definitionEntity)); $this->workflowDefinition->import($newDefinition); $this->assertEquals($expectedData, $this->getDefinitionAsArray($this->workflowDefinition)); }
public function testImport() { $startStep = new WorkflowStep(); $startStep->setName('start'); $expectedData = array('name' => 'test_name', 'label' => 'test_label', 'steps' => new ArrayCollection(array($startStep)), 'start_step' => $startStep, 'configuration' => array('test', 'configuration')); $this->assertNotEquals($expectedData, $this->getDefinitionAsArray($this->workflowDefinition)); $newDefinition = new WorkflowDefinition(); $newDefinition->setName($expectedData['name'])->setSteps($expectedData['steps'])->setLabel($expectedData['label'])->setStartStep($expectedData['start_step'])->setConfiguration($expectedData['configuration']); $this->assertEquals($this->workflowDefinition, $this->workflowDefinition->import($newDefinition)); $this->assertEquals($expectedData, $this->getDefinitionAsArray($this->workflowDefinition)); }
/** * Update workflow definition * * Returns * - HTTP_OK (200) * - HTTP_BAD_REQUEST (400) * * @param WorkflowDefinition $workflowDefinition * * @Rest\Put( * "/api/rest/{version}/workflowdefinition/{workflowDefinition}", * defaults={"version"="latest", "_format"="json"} * ) * @ApiDoc( * description="Update workflow definition", * resource=true * ) * @AclAncestor("oro_workflow_definition_update") * @return Response */ public function putAction(WorkflowDefinition $workflowDefinition) { try { /** @var WorkflowDefinitionHandleBuilder $definitionBuilder */ $definitionBuilder = $this->get('oro_workflow.configuration.builder.workflow_definition.handle'); $builtDefinition = $definitionBuilder->buildFromRawConfiguration($this->getConfiguration()); $workflowDefinition->import($builtDefinition); /** @var WorkflowAssembler $workflowAssembler */ $workflowAssembler = $this->get('oro_workflow.workflow_assembler'); $workflowAssembler->assemble($workflowDefinition); $entityManager = $this->getEntityManager(); $entityManager->persist($workflowDefinition); $entityManager->flush($workflowDefinition); } catch (\Exception $exception) { return $this->handleView($this->view(array('error' => $exception->getMessage()), Codes::HTTP_BAD_REQUEST)); } return $this->handleView($this->view($workflowDefinition->getName(), Codes::HTTP_OK)); }
/** * @Route( * "/clone/{name}", * name="oro_workflow_definition_clone" * ) * @AclAncestor("oro_workflow_definition_create") * @Template("OroWorkflowBundle:WorkflowDefinition:update.html.twig") * * @param WorkflowDefinition $workflowDefinition * @return array */ public function cloneAction(WorkflowDefinition $workflowDefinition) { /** @var TranslatorInterface $translator */ $translator = $this->get('translator'); $clonePrefix = $translator->trans('oro.workflow.workflowdefinition.clone_label_prefix'); $clonedDefinition = new WorkflowDefinition(); $clonedDefinition->import($workflowDefinition)->setName($workflowDefinition->getName() . uniqid('_clone_'))->setLabel($clonePrefix . $workflowDefinition->getLabel())->setSystem(false); $response = $this->updateAction($clonedDefinition); $response['delete_allowed'] = false; return $response; }