ssossossossosso

Forums

This topic contains 3 replies, has 2 voices, and was last updated by  Yevhen Shyshkin 2 years, 3 months ago.

  • Creator
    Topic
  • #28495

    dimitri.seguin17
    Participant

    Hello, I want to automation workflow to send email, etc.

    I create a command but I have a performance problem.


    /** @var \Doctrine\ORM\EntityManager $em */
    $em = $this->getContainer()->get('doctrine.orm.entity_manager');

    $workflowItems = $em->createQueryBuilder()
    ->select('wi')
    ->from('OroWorkflowBundle:WorkflowItem', 'wi')
    ->from('OroWorkflowBundle:WorkflowStep', 'ws')
    ->where('wi.currentStep = ws.id')
    ->andWhere('wi.definition = \'main_workflow\'')
    ->andWhere('ws.final=0')
    ->getQuery()->getResult();

    $user = $this->getContainer()->get('doctrine')->getRepository('OroUserBundle:User')->findOneBy(['username' => 'admin']);
    $token = new UsernamePasswordToken($user, null, 'main', $user->getRoles());
    $this->getContainer()->get('security.context')->setToken($token);

    $workflowManager = $this->getWorkflowManager();

    foreach ($workflowItems as $workflowItem)
    {
    $transitions = $workflowManager->getTransitionsByWorkflowItem($workflowItem);

    foreach ($transitions as $transition) {
    if($workflowManager->isTransitionAvailable($workflowItem, $transition)) {
    $workflowManager->transit($workflowItem, $transition);
    break;
    }
    }
    }

    Have you an idea to update a code ?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Author
    Replies
  • #28496

    Yevhen Shyshkin
    Participant

    Hello, Dmitri.

    Performance issue happens because of flush on each transition (see https://github.com/laboro/platform/blob/master/src/Oro/Bundle/WorkflowBundle/Model/WorkflowManager.php#L167). We’ve already fixed this issue for mass start of workflow (see methods startWorkflow and massStartWorkflow) – looks like now we need to do the same for transit method. We will do that ASAP.

    If I understand conditions correctly, your workflow items does not have cross relations, so you can safely perform all transits in one flush and transaction. I’d recommend you to create some service and implement mass transit logic there. Also it would be really good if you add massTransit action to WorkflowManager and create pull request to platform – so we can merge it and it will be available in the next release.

    Feel free to post here PR or any questions related to this issue.

    #28497

    dimitri.seguin17
    Participant

    Thank’s for your answer.
    I did a pull request which implement a method massTransitWorkflow.
    I was inspired of method massStartWorkflow as you have suggested me.

    #28498

    Yevhen Shyshkin
    Participant

    Thank you!

    We’ll review and merge it ASAP.

Viewing 3 replies - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.