CheckModerateCommand.php 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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 CheckModerateCommand extends ContainerAwareCommand
  10. {
  11. protected function configure()
  12. {
  13. $this
  14. ->setName('moderate:check')
  15. ->setDescription('Contrôle les moderations a effectuer et envoie un email')
  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 contrôle de la modération ##');
  30. $output->writeln('#');
  31. $count_tags = $doctrine->getRepository('MuzichCoreBundle:Tag')
  32. ->countToModerate();
  33. $count_elements = $doctrine->getRepository('MuzichCoreBundle:Element')
  34. ->countToModerate();
  35. $count_comments = $doctrine->getRepository('MuzichCoreBundle:Element')
  36. ->countForCommentToModerate();
  37. $output->writeln('<info>Nombre de tags a modérer: '.$count_tags.'</info>');
  38. $output->writeln('<info>Nombre d\'élément a modérer: '.$count_elements.'</info>');
  39. $output->writeln('<info>Nombre d\'élément avec commentaire a modérer: '.$count_comments.'</info>');
  40. if ($count_tags || $count_elements || $count_comments)
  41. {
  42. $output->writeln('<info>Envoie du courriel ...</info>');
  43. $message = \Swift_Message::newInstance()
  44. ->setSubject('Muzi.ch: Contrôle modération')
  45. ->setFrom('noreply@muzi.ch')
  46. ->setTo('sevajol.bastien@gmail.com')
  47. ->setBody($this->getContainer()->get('templating')->render('MuzichCoreBundle:Email:checkmoderate.txt.twig', array(
  48. 'tags' => $count_tags,
  49. 'elements' => $count_elements,
  50. 'comments' => $count_comments,
  51. 'url' => $this->getContainer()->get('router')->generate('MuzichAdminBundle_moderate_index', array(), true)
  52. )))
  53. ;
  54. $this->getContainer()->get('mailer')->send($message);
  55. }
  56. $output->writeln('<info>Terminé !</info>');
  57. }
  58. }