protected function loadTriggers(OutputInterface $output, array $configuration)
 {
     /** @var ProcessDefinition[] $allDefinitions */
     $allDefinitions = $this->getDefinitionRepository()->findAll();
     $definitionsByName = array();
     foreach ($allDefinitions as $definition) {
         $definitionsByName[$definition->getName()] = $definition;
     }
     $triggers = $this->configurationBuilder->buildProcessTriggers($configuration, $definitionsByName);
     if ($triggers) {
         $output->writeln('Loading process triggers...');
         $entityManager = $this->getEntityManager();
         $triggerRepository = $entityManager->getRepository('OroWorkflowBundle:ProcessTrigger');
         foreach ($triggers as $trigger) {
             $output->writeln(sprintf('  <comment>></comment> <info>%s:%s</info>', $trigger->getDefinition()->getName(), $trigger->getEvent()));
             $existingTrigger = $triggerRepository->findEqualTrigger($trigger);
             if ($existingTrigger) {
                 $existingTrigger->import($trigger);
             } else {
                 $entityManager->persist($trigger);
             }
         }
         $entityManager->flush();
     } else {
         $output->writeln('No process triggers found.');
     }
 }
 /**
  * @expectedException \LogicException
  * @expectedExceptionMessage Process definition "not_existing_definition" not found
  */
 public function testBuildProcessTriggersException()
 {
     $this->builder->buildProcessTriggers(array('not_existing_definition' => array('triggers', 'configuration')), array('existing_definition' => new ProcessDefinition()));
 }