UpdateTagSlugsCommand.php 1.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. namespace Muzich\CoreBundle\Command;
  3. use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
  4. use Symfony\Component\Console\Input\InputArgument;
  5. use Symfony\Component\Console\Input\InputInterface;
  6. use Symfony\Component\Console\Input\InputOption;
  7. use Symfony\Component\Console\Output\OutputInterface;
  8. use Muzich\CoreBundle\ElementFactory\ElementManager;
  9. class UpdateTagSlugsCommand extends ContainerAwareCommand
  10. {
  11. protected function configure()
  12. {
  13. $this
  14. ->setName('tagengine:update-slugs')
  15. ->setDescription('Actualise les slugs')
  16. // Dans l'avenir on pourra préciser:
  17. // - le type
  18. // - l'élément
  19. // ->addOption('sites', null, InputOption::VALUE_REQUIRED, 'Liste exhaustive des site a traiter')
  20. // ->addArgument('sites', InputArgument::OPTIONAL, 'Liste exhaustive des site a traiter')
  21. // ->addOption('yell', null, InputOption::VALUE_NONE, 'If set, the task will yell in uppercase letters')
  22. ;
  23. }
  24. protected function execute(InputInterface $input, OutputInterface $output)
  25. {
  26. $doctrine = $this->getContainer()->get('doctrine');
  27. $em = $doctrine->getEntityManager();
  28. $output->writeln('#');
  29. $output->writeln('## Script de mise a jour des slugs tags ##');
  30. $output->writeln('#');
  31. // On récupère les tags
  32. $tags = $em->getRepository('MuzichCoreBundle:Tag')->findAll();
  33. $tag_manager = $this->getContainer()->get('muzich_tag_manager');
  34. $output->writeln('<info>Nombre de tags a traiter: '.count($tags).'</info>');
  35. $output->writeln('<info>Début du traitement ...</info>');
  36. foreach ($tags as $tag)
  37. {
  38. $tag_manager->updateSlug($tag);
  39. $em->persist($tag);
  40. }
  41. $output->writeln('<info>Traitement terminé, enregistrement en base ...</info>');
  42. $em->flush();
  43. $output->writeln('<info>Enregistrement terminé !</info>');
  44. }
  45. }