OroPlatform Forums

Covering OroPlatform topics, including community updates and company announcements.

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

Starting from March 1, 2020 the forum has been switched to the read-only mode. Please head to StackOverflow for support.

  • Creator
    Topic
  • #33976

    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
  • #33977

    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.

    #33978

    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.

    #33979

    Yevhen Shyshkin
    Participant

    Thank you!

    We’ll review and merge it ASAP.

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

The forum ‘OroPlatform – Programming Questions’ is closed to new topics and replies.

Back to top

You will be redirected to [title]. Would you like to continue?

Yes No

You will be redirected to [title]. Would you like to continue?

Yes No