123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- <?php
- namespace WorkflowBundle\Command;
- use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
- use Symfony\Component\Console\Input\InputInterface;
- use Symfony\Component\Console\Input\InputOption;
- use Symfony\Component\Console\Output\OutputInterface;
- use WorkflowBundle\Entity\Workflow;
- use WorkflowBundle\Utils\WorkFlowEntityClasses;
- class WorkflowDefaultCommand extends ContainerAwareCommand
- {
- protected function configure()
- {
- $this
- ->setName('workflow:default')
- ->setDescription('Set class default workflow and assign to all class entities')
- ->setHelp('Set class default workflow and assign to all class entities')
- ->addOption(
- 'class',
- null,
- InputOption::VALUE_REQUIRED,
- 'Entity Class name. e.g.: FTTHBundle\\Entity\\ONU'
- )
- ->addOption(
- 'all',
- null,
- InputOption::VALUE_NONE,
- 'Assign default workflow to all class entities passed by parameters'
- )
- ;
- }
- /**
- * @param InputInterface $input
- * @param OutputInterface $output
- */
- protected function execute(InputInterface $input, OutputInterface $output)
- {
- $class = $input->getOption('class');
-
- if (is_null($class)) {
- $output->writeln("<error>El parametro --class es requerido</error>");
- }
-
- $em = $this->getContainer()->get("doctrine.orm.entity_manager");
- $workworkflowRepository = $em->getRepository(Workflow::class);
-
- $workflow = null;
- $workflows = $workworkflowRepository->findAllByClass($class);
- if (count($workflows)) {
- // Hay workflows habilitados
- $workflow = current($workflows);
- // en el caso que haya varios workflows, seteo por defecto el primero
- if ($workflow->getUsedByDefault() == false) {
- $workflow->setUsedByDefault(true);
-
- $em->flush();
- }
-
- $output->writeln("<info>Workflow asignado por defecto: </info> {$workflow}");
- }
-
- if (!is_null($workflow) && $input->getOption('all')) {
- // actualizo las onus que no tengan currentState.
- // por ej si fueron importadas
- $qb = $em->getRepository($class)->createQueryBuilder($class);
- $result = $qb->update($class, 'o')
- ->set('o.currentState', ':currentState')
- ->setParameter('currentState', 'active')
- ->where('o.currentState IS NULL')
- ->getQuery()->getResult();
-
- $qb = $em->getRepository($class)->createQueryBuilder($class);
- $result = $qb->update($class, 'o')
- ->set('o.workflow', ':workflow')
- ->setParameter('workflow', $workflow)
- ->getQuery()->getResult();
-
- $output->writeln("<info>Se ejecutó la actualización de entidates</info> {$class}");
- $output->writeln("<info>Result:</info> {$result}");
- } elseif (is_null($workflow)) {
- $output->writeln("<error>No hay workflows para la clase</error>");
- }
- }
- }
|