Esempio n. 1
0
 /**
  * {@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);
 }
Esempio n. 2
0
 /**
  * @param mixed $entityId
  * @param WorkflowItem $workflowItem
  *
  * @dataProvider entityDataProvider
  */
 public function testGetWorkflowItemByEntity($entityId, WorkflowItem $workflowItem = null)
 {
     $entity = new \DateTime('now');
     $entityClass = get_class($entity);
     $this->doctrineHelper->expects($this->any())->method('getEntityClass')->with($entity)->will($this->returnValue($entityClass));
     $this->doctrineHelper->expects($this->any())->method('getSingleEntityIdentifier')->with($entity)->will($this->returnValue($entityId));
     $workflowItemsRepository = $this->getMockBuilder('Oro\\Bundle\\WorkflowBundle\\Entity\\Repository\\WorkflowItemRepository')->disableOriginalConstructor()->setMethods(array('findByEntityMetadata'))->getMock();
     $workflowItemsRepository->expects($this->any())->method('findByEntityMetadata')->with($entityClass, $entityId)->will($this->returnValue($workflowItem));
     $this->registry->expects($this->any())->method('getRepository')->with('OroWorkflowBundle:WorkflowItem')->will($this->returnValue($workflowItemsRepository));
     $this->assertEquals($workflowItem, $this->workflowManager->getWorkflowItemByEntity($entity));
 }
Esempio n. 3
0
 /**
  * Check that entity has workflow item.
  *
  * @param object $entity
  * @return bool
  */
 public function hasWorkflowItem($entity)
 {
     return $this->workflowManager->getWorkflowItemByEntity($entity) !== null;
 }