getWorkflowId(); $workflow = $this->workflowRepository->find($workflowId); $workflowComponent = $this->registry->get($workflow, $workflow->getWorkflowName()); $metadataStore = $workflowComponent->getMetadataStore(); $transitions = $workflowComponent->getEnabledTransitions($workflow); $steps = $workflow->getSteps(); $transitionApplied = false; if (count($steps) === 1) { $this->em->remove($workflow->getCurrentStep()); $this->em->remove($workflow); } else { foreach ($transitions as $transition) { $isFinal = $metadataStore->getMetadata('isFinal', $transition); $isFinalPositive = $metadataStore->getMetadata('isFinalPositive', $transition); if ($isFinal && !$isFinalPositive) { $workflowComponent->apply($workflow, 'annule'); $this->logger->info(sprintf('EntityWorkflow %d has been transitioned.', $workflowId)); $transitionApplied = true; break; } } if (!$transitionApplied) { $this->logger->error(sprintf('No valid transition found for EntityWorkflow %d.', $workflowId)); throw new UnrecoverableMessageHandlingException( sprintf('No valid transition found for EntityWorkflow %d.', $workflowId) ); } } } }