WorkflowRunActionCommand.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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\Input\InputOption;
  6. use Symfony\Component\Console\Output\OutputInterface;
  7. use WorkflowBundle\Utils\WorkFlowEntityClasses;
  8. class WorkflowRunActionCommand extends ContainerAwareCommand
  9. {
  10. protected function configure()
  11. {
  12. $this
  13. ->setName('workflow:run:action')
  14. ->setDescription('Ejecuta un Action de workflow para una Entidad')
  15. ->setHelp('Ejecuta un Action (WorflowBundle\Entity\Action) de workflow para una Entidad (WorkflowBundle\Utils\WorkFlowEntityClasses)')
  16. ->addOption(
  17. 'action',
  18. null,
  19. InputOption::VALUE_REQUIRED,
  20. 'Action name'
  21. )
  22. ->addOption(
  23. 'entity',
  24. null,
  25. InputOption::VALUE_REQUIRED,
  26. 'Entity Class. Possible values: ' . implode(', ', WorkFlowEntityClasses::getConstants())
  27. )
  28. ->addOption(
  29. 'id',
  30. null,
  31. InputOption::VALUE_REQUIRED,
  32. 'Entity id'
  33. )
  34. ;
  35. }
  36. /**
  37. * @param InputInterface $input
  38. * @param OutputInterface $output
  39. */
  40. protected function execute(InputInterface $input, OutputInterface $output)
  41. {
  42. /* @var $producerService \WorkflowBundle\Services\ProducerService */
  43. $producerService = $this->getContainer()->get("workflow.producer_service");
  44. $actionName = $input->getOption('action');
  45. $entityClass = $input->getOption('entity');
  46. $entityId = $input->getOption('id');
  47. if ($actionName && $entityClass && $entityId) {
  48. $producerService->executeAction($actionName, $entityClass, $entityId);
  49. $output->writeln("<info>Action '{$actionName}' para la entidad '{$entityClass}' ejecutada</info>");
  50. } else {
  51. $output->writeln('<error>Ingrese todas las opciones</error>');
  52. }
  53. }
  54. }