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
 /**
  * @expectedException \Exception
  * @expectedExceptionMessage Transit exception message
  */
 public function testTransitException()
 {
     $workflowName = 'test_workflow';
     $workflowItem = new WorkflowItem();
     $workflowItem->setWorkflowName($workflowName);
     $this->workflowRegistry->expects($this->once())->method('getWorkflow')->with($workflowName)->will($this->returnValue($this->createWorkflow($workflowName)));
     $entityManager = $this->createEntityManager();
     $entityManager->expects($this->once())->method('beginTransaction');
     $entityManager->expects($this->once())->method('flush')->will($this->throwException(new \Exception('Transit exception message')));
     $entityManager->expects($this->once())->method('rollback');
     $this->registry->expects($this->once())->method('getManager')->will($this->returnValue($entityManager));
     $this->workflowManager->transit($workflowItem, 'test_transition');
 }
 /**
  * @param Lead | Opportunity $entity
  * @param User $owner
  */
 protected function loadSalesFlows($entity, $owner)
 {
     if ($entity instanceof Lead) {
         $step = 'start_from_lead';
         $parameters = array('lead' => $entity);
     } else {
         $step = 'start_from_opportunity';
         $parameters = array('opportunity' => $entity);
     }
     $parameters = array_merge(array('sales_funnel' => null, 'sales_funnel_owner' => $owner, 'sales_funnel_start_date' => new \DateTime('now')), $parameters);
     $salesFunnel = new SalesFunnel();
     $salesFunnel->setDataChannel($this->getReference('default_channel'));
     if (!$this->workflowManager->isStartTransitionAvailable('b2b_flow_sales_funnel', $step, $salesFunnel, $parameters)) {
         return;
     }
     $salesFunnelItem = $this->workflowManager->startWorkflow('b2b_flow_sales_funnel', $salesFunnel, $step, $parameters);
     $salesFunnelItem->getData()->set('new_opportunity_name', $entity->getName())->set('new_company_name', $entity->getName());
     if ($entity instanceof Lead) {
         if ($this->isTransitionAllowed($salesFunnelItem, 'qualify')) {
             $this->workflowManager->transit($salesFunnelItem, 'qualify');
         } else {
             return;
         }
     }
     if (rand(1, 100) > 10) {
         $salesFunnelItem->getData()->set('budget_amount', mt_rand(10, 10000))->set('customer_need', mt_rand(10, 10000))->set('proposed_solution', mt_rand(10, 10000))->set('probability', $this->probabilities[array_rand($this->probabilities)]);
         if ($this->isTransitionAllowed($salesFunnelItem, 'develop')) {
             $this->workflowManager->transit($salesFunnelItem, 'develop');
             if ($this->getRandomBoolean()) {
                 $salesFunnelItem->getData()->set('close_revenue', mt_rand(10, 1000))->set('close_date', new \DateTime());
                 if ($this->getRandomBoolean()) {
                     if ($this->isTransitionAllowed($salesFunnelItem, 'close_as_won')) {
                         $this->workflowManager->transit($salesFunnelItem, 'close_as_won');
                     }
                 } else {
                     $salesFunnelItem->getData()->set('close_reason_name', 'cancelled')->set('close_date', new \DateTime('now', new \DateTimeZone('UTC')));
                     if ($this->isTransitionAllowed($salesFunnelItem, 'close_as_lost')) {
                         $this->workflowManager->transit($salesFunnelItem, 'close_as_lost');
                     }
                 }
             }
         }
     }
 }