/** * @param BuildBefore $event */ public function onBuildBefore(BuildBefore $event) { $config = $event->getConfig(); // get root entity $rootEntity = null; $rootEntityAlias = null; $from = $config->offsetGetByPath('[source][query][from]'); if ($from) { $firstFrom = current($from); if (!empty($firstFrom['table']) && !empty($firstFrom['alias'])) { $rootEntity = $this->updateEntityClass($firstFrom['table']); $rootEntityAlias = $firstFrom['alias']; } } $groupBy = $config->offsetGetByPath('[source][query][groupBy]', null); if (!$rootEntity || !$rootEntityAlias || $groupBy) { return; } // whether entity has active workflow and entity should render workflow step field $isShowWorkflowStep = $this->workflowManager->hasApplicableWorkflowByEntityClass($rootEntity) && $this->isShowWorkflowStep($rootEntity); // check whether grid contains workflow step column $columns = $config->offsetGetByPath('[columns]', array()); $workflowStepColumns = array_intersect($this->workflowStepColumns, array_keys($columns)); // remove workflow step if it must be hidden but there are workflow step columns if (!$isShowWorkflowStep && $workflowStepColumns) { $this->removeWorkflowStep($config, $workflowStepColumns); } // add workflow step if it must be shown and there are no workflow step columns if ($isShowWorkflowStep && empty($workflowStepColumns)) { $this->addWorkflowStep($config, $rootEntity, $rootEntityAlias); } }
/** * {@inheritDoc} */ protected function executeAction($context) { $workflowName = $this->getName($context); $entity = $this->getEntity($context); $startTransition = $this->getTransition($context); $data = $this->getData($context); $workflowItem = $this->workflowManager->startWorkflow($workflowName, $entity, $startTransition, $data); $attribute = $this->getAttribute(); $this->contextAccessor->setValue($context, $attribute, $workflowItem); }
/** * @expectedException \Oro\Bundle\WorkflowBundle\Exception\ActionException * @expectedExceptionMessage Cannot transit workflow, instance of "stdClass" doesn't have workflow item. */ public function testExecuteFailsWhenThereIsNoWorkflowItem() { $expectedEntity = new \stdClass(); $context = new ItemStub(); $context->test = $expectedEntity; $options = ['entity' => new PropertyPath('test'), 'transition' => 'test_transition']; $this->workflowManager->expects($this->once())->method('getWorkflowItemByEntity')->with($expectedEntity)->will($this->returnValue(null)); $this->workflowManager->expects($this->never())->method('transit'); $this->action->initialize($options); $this->action->execute($context); }
/** * {@inheritdoc} */ protected function executeAction($context) { $entity = $this->contextAccessor->getValue($context, $this->entity); $transition = $this->contextAccessor->getValue($context, $this->transition); $workflowItem = $this->workflowManager->getWorkflowItemByEntity($entity); if (!$workflowItem) { throw new ActionException(sprintf('Cannot transit workflow, instance of "%s" doesn\'t have workflow item.', is_object($entity) ? get_class($entity) : gettype($entity))); } $data = $this->getData($context); if ($data) { $workflowItem->getData()->add($data); } $this->workflowManager->transit($workflowItem, $transition); }
/** * Execute workflow start for scheduled entities. */ public function postFlush() { $currentDeepLevel = $this->deepLevel; if (!empty($this->entitiesScheduledForWorkflowStart[$currentDeepLevel])) { $this->deepLevel++; $massStartData = $this->entitiesScheduledForWorkflowStart[$currentDeepLevel]; unset($this->entitiesScheduledForWorkflowStart[$currentDeepLevel]); $this->workflowManager->massStartWorkflow($massStartData); $this->deepLevel--; } }
public function testResetWorkflowData() { $name = 'testWorkflow'; $entityClass = 'Test:Entity'; $workflowDefinition = new WorkflowDefinition(); $workflowDefinition->setName($name)->setRelatedEntity($entityClass); $workflowItemsRepository = $this->getMockBuilder('Oro\\Bundle\\WorkflowBundle\\Entity\\Repository\\WorkflowItemRepository')->disableOriginalConstructor()->setMethods(array('resetWorkflowData'))->getMock(); $workflowItemsRepository->expects($this->once())->method('resetWorkflowData')->with($entityClass, array($name)); $this->registry->expects($this->once())->method('getRepository')->with('OroWorkflowBundle:WorkflowItem')->will($this->returnValue($workflowItemsRepository)); $this->workflowManager->resetWorkflowData($workflowDefinition); }
public function testIsAllManagedEntitiesSpecified() { $managedAttributeName = 'entity'; $managedAttribute = new Attribute(); $managedAttribute->setName($managedAttributeName); $workflow = $this->createWorkflow(self::TEST_WORKFLOW_NAME, array($managedAttribute)); $this->workflowRegistry->expects($this->any())->method('getWorkflow')->with(self::TEST_WORKFLOW_NAME)->will($this->returnValue($workflow)); $validWorkflowItem = $this->createWorkflowItem(); $validWorkflowItem->getData()->set($managedAttributeName, new \DateTime()); $this->assertTrue($this->workflowManager->isAllManagedEntitiesSpecified($validWorkflowItem)); $invalidWorkflowItem = $this->createWorkflowItem(); $this->assertFalse($this->workflowManager->isAllManagedEntitiesSpecified($invalidWorkflowItem)); }
/** * @param WorkflowItem $workflowItem * @throws NotFoundHttpException */ public function validate(WorkflowItem $workflowItem) { if (!$this->workflowManager->isAllManagedEntitiesSpecified($workflowItem)) { throw new NotFoundHttpException('Managed entities for workflow item not found'); } }
/** * @param WorkflowManager $workflowManager * @param WorkflowItem $workflowItem * @param string $transition * @param array $data */ protected function transit($workflowManager, $workflowItem, $transition, array $data) { foreach ($data as $key => $value) { $workflowItem->getData()->set($key, $value); } $workflow = $workflowManager->getWorkflow($workflowItem); /** @var EntityManager $em */ $workflow->transit($workflowItem, $transition); $workflowItem->setUpdated(); }
/** * @param WorkflowItem $workflowItem * @param string $transition * @return bool */ protected function isTransitionAllowed(WorkflowItem $workflowItem, $transition) { $workflow = $this->workflowManager->getWorkflow($workflowItem); return $workflow->isTransitionAllowed($workflowItem, $transition); }
/** * Check that entity workflow item is equal to the active workflow item. * * @param object $entity * @return bool */ public function isResetAllowed($entity) { return $this->workflowManager->isResetAllowed($entity); }