WorkflowGenerateListCommand.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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['supports'] = $workflow->getSupport();
  40. $body += Yaml::parse($workflow->getTemplate());
  41. $templates[$workflow->getName()] = $body;
  42. }
  43. $workflow_file = $rootDir."/Resources/workflows/workflow_list.yml";
  44. $handle = fopen($workflow_file,"w+");
  45. if($templates) {
  46. $workflow_template['framework'] = array('workflows' => $templates);
  47. $yaml = Yaml::dump($workflow_template,100,2);
  48. fwrite($handle,$yaml);
  49. } else {
  50. fwrite($handle,"");
  51. }
  52. fclose($handle);
  53. chmod($workflow_file, 0777);
  54. }
  55. }