1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- <?php
- namespace WorkflowBundle\Command;
- use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
- use Symfony\Component\Console\Input\InputInterface;
- use Symfony\Component\Console\Output\OutputInterface;
- use Symfony\Component\Yaml\Yaml;
- class WorkflowGenerateListCommand extends ContainerAwareCommand
- {
- protected function configure()
- {
- $this
- // the name of the command (the part after "bin/console")
- ->setName('workflow:generate:list')
- // the short description shown while running "php bin/console list"
- ->setDescription('Genera el contenido para el archivo workflow_list.yml.')
- // the full command description shown when running the command with
- // the "--help" option
- ->setHelp('Genera el contenido para el archivo workflow_list.yml.')
- ;
- }
- protected function execute(InputInterface $input, OutputInterface $output)
- {
- // Init
- $em = $this->getContainer()->get("doctrine.orm.entity_manager");
- $workflows = $em->getRepository("WorkflowBundle:Workflow")->findBy(array('enable'=>1));
- $rootDir = $this->getContainer()->getParameter('kernel.root_dir');
- $workflow_template = array();
- $workflow_template['framework'] = array();
- $templates = array();
- foreach($workflows as $k => $workflow) {
- $body = array();
- $body['type'] = $workflow->getType();
-
- if(is_array($workflow->getMarkingName())) {
- $markingName = $workflow->getMarkingName();
- } else {
- $markingName = array(0 => $workflow->getMarkingName());
- }
- $body['marking_store'] = array('type' => $workflow->getMarkingType(), 'arguments' => $markingName);
- $body['supports'] = $workflow->getSupport();
- $body += Yaml::parse($workflow->getTemplate());
- $templates[$workflow->getName()] = $body;
- }
- $workflow_file = $rootDir."/Resources/workflows/workflow_list.yml";
-
- $handle = fopen($workflow_file,"w+");
- if($templates) {
- $workflow_template['framework'] = array('workflows' => $templates);
- $yaml = Yaml::dump($workflow_template,100,2);
- fwrite($handle,$yaml);
- } else {
- fwrite($handle,"");
- }
- fclose($handle);
- chmod($workflow_file, 0777);
- }
- }
|