Browse Source

Evolution #148: Routine mail (tags a modérer)

bastien 13 years ago
parent
commit
5398aeb7ad

+ 65 - 0
src/Muzich/CoreBundle/Command/CheckModerateCommand.php View File

@@ -0,0 +1,65 @@
1
+<?php
2
+
3
+namespace Muzich\CoreBundle\Command;
4
+
5
+use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
6
+use Symfony\Component\Console\Input\InputArgument;
7
+use Symfony\Component\Console\Input\InputInterface;
8
+use Symfony\Component\Console\Input\InputOption;
9
+use Symfony\Component\Console\Output\OutputInterface;
10
+
11
+use Muzich\CoreBundle\ElementFactory\ElementManager;
12
+
13
+class CheckModerateCommand extends ContainerAwareCommand
14
+{
15
+  protected function configure()
16
+  {
17
+    $this
18
+      ->setName('moderate:check')
19
+      ->setDescription('Contrôle les moderations a effectuer et envoie un email')
20
+      // Dans l'avenir on pourra préciser:
21
+      // - le type
22
+      // - l'élément
23
+//      ->addOption('sites', null, InputOption::VALUE_REQUIRED, 'Liste exhaustive des site a traiter')
24
+//      ->addArgument('sites', InputArgument::OPTIONAL, 'Liste exhaustive des site a traiter')
25
+//      ->addOption('yell', null, InputOption::VALUE_NONE, 'If set, the task will yell in uppercase letters')
26
+    ;
27
+  }
28
+
29
+  protected function execute(InputInterface $input, OutputInterface $output)
30
+  {
31
+    $doctrine = $this->getContainer()->get('doctrine');
32
+    $em = $doctrine->getEntityManager();
33
+
34
+    $output->writeln('#');
35
+    $output->writeln('## Script de contrôle de la modération ##');
36
+    $output->writeln('#');
37
+ 
38
+    $count_tags = $doctrine->getRepository('MuzichCoreBundle:Tag')
39
+      ->countToModerate();
40
+    $count_elements = $doctrine->getRepository('MuzichCoreBundle:Element')
41
+      ->countToModerate();
42
+    
43
+    $output->writeln('<info>Nombre de tags a modérer: '.$count_tags.'</info>');
44
+    $output->writeln('<info>Nombre d\'élément a modérer: '.$count_elements.'</info>');
45
+    
46
+    if ($count_tags || $count_elements)
47
+    {
48
+      $output->writeln('<info>Envoie du courriel ...</info>');
49
+
50
+      $message = \Swift_Message::newInstance()
51
+          ->setSubject('Muzi.ch: Contrôle modération')
52
+          ->setFrom('noreply@muzi.ch')
53
+          ->setTo('sevajol.bastien@gmail.com')
54
+          ->setBody($this->getContainer()->get('templating')->render('MuzichCoreBundle:Email:checkmoderate.txt.twig', array(
55
+            'tags'     => $count_tags,
56
+            'elements' => $count_elements,
57
+            'url'      => $this->getContainer()->get('router')->generate('MuzichAdminBundle_moderate_index', array(), true)
58
+          )))
59
+      ;
60
+      $this->getContainer()->get('mailer')->send($message);
61
+    }
62
+    
63
+    $output->writeln('<info>Terminé !</info>');
64
+  }
65
+}

+ 6 - 0
src/Muzich/CoreBundle/Resources/views/Email/checkmoderate.txt.twig View File

@@ -0,0 +1,6 @@
1
+{% autoescape false %}
2
+  Il y a des choses a modérer:
3
+  Elements: {{ elements }}.
4
+  Tags: {{ tags }}
5
+  Page de modération: {{ url }}
6
+{% endautoescape %}

+ 1 - 1
src/Muzich/CoreBundle/Tests/Controller/UserControllerTest.php View File

@@ -519,7 +519,7 @@ class UserControllerTest extends FunctionalTest
519 519
       array('HTTP_X-Requested-With' => 'XMLHttpRequest')
520 520
     );
521 521
     
522
-    $this->outputDebug();
522
+    
523 523
     $this->isResponseSuccess();
524 524
     $response = json_decode($this->client->getResponse()->getContent(), true);
525 525