WorkflowGenerateListCommand.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. namespace WorkflowBundle\Command;
  3. use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
  4. use Symfony\Component\Console\Input\InputInterface;
  5. use Symfony\Component\Console\Output\OutputInterface;
  6. use Symfony\Component\Yaml\Yaml;
  7. class WorkflowGenerateListCommand extends ContainerAwareCommand
  8. {
  9. protected function configure()
  10. {
  11. $this
  12. // the name of the command (the part after "bin/console")
  13. ->setName('workflow:generate:list')
  14. // the short description shown while running "php bin/console list"
  15. ->setDescription('Genera el contenido para el archivo workflow_list.yml.')
  16. // the full command description shown when running the command with
  17. // the "--help" option
  18. ->setHelp('Genera el contenido para el archivo workflow_list.yml.')
  19. ;
  20. }
  21. protected function execute(InputInterface $input, OutputInterface $output)
  22. {
  23. // Init
  24. $em = $this->getContainer()->get("doctrine.orm.entity_manager");
  25. $workflows = $em->getRepository("WorkflowBundle:Workflow")->findBy(array('enable'=>1));
  26. $rootDir = $this->getContainer()->getParameter('kernel.root_dir');
  27. $workflow_template = array();
  28. $workflow_template['framework'] = array();
  29. $templates = array();
  30. foreach($workflows as $k => $workflow) {
  31. $body = array();
  32. $body['type'] = $workflow->getType();
  33. if(is_array($workflow->getMarkingName())) {
  34. $markingName = $workflow->getMarkingName();
  35. } else {
  36. $markingName = array(0 => $workflow->getMarkingName());
  37. }
  38. $body['marking_store'] = array('type' => $workflow->getMarkingType(), 'arguments' => $markingName);
  39. $body += Yaml::parse($workflow->getTemplate());
  40. $templates[$workflow->getName()] = $body;
  41. }
  42. $workflow_file = $rootDir."/Resources/workflows/workflow_list.yml";
  43. $handle = fopen($workflow_file,"w+");
  44. if($templates) {
  45. $workflow_template['framework'] = array('workflows' => $templates);
  46. $yaml = Yaml::dump($workflow_template,100,2);
  47. fwrite($handle,$yaml);
  48. } else {
  49. fwrite($handle,"");
  50. }
  51. fclose($handle);
  52. chmod($workflow_file, 0777);
  53. }
  54. }