|
@@ -0,0 +1,55 @@
|
|
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 UpdateTagSlugsCommand extends ContainerAwareCommand
|
|
14
|
+{
|
|
15
|
+ protected function configure()
|
|
16
|
+ {
|
|
17
|
+ $this
|
|
18
|
+ ->setName('tagengine:update-slugs')
|
|
19
|
+ ->setDescription('Actualise les slugs')
|
|
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 mise a jour des slugs tags ##');
|
|
36
|
+ $output->writeln('#');
|
|
37
|
+
|
|
38
|
+ // On récupère les tags
|
|
39
|
+ $tags = $em->getRepository('MuzichCoreBundle:Tag')->findAll();
|
|
40
|
+ $tag_manager = $this->getContainer()->get('muzich_tag_manager');
|
|
41
|
+
|
|
42
|
+ $output->writeln('<info>Nombre de tags a traiter: '.count($tags).'</info>');
|
|
43
|
+ $output->writeln('<info>Début du traitement ...</info>');
|
|
44
|
+
|
|
45
|
+ foreach ($tags as $tag)
|
|
46
|
+ {
|
|
47
|
+ $tag_manager->updateSlug($tag);
|
|
48
|
+ $em->persist($tag);
|
|
49
|
+ }
|
|
50
|
+
|
|
51
|
+ $output->writeln('<info>Traitement terminé, enregistrement en base ...</info>');
|
|
52
|
+ $em->flush();
|
|
53
|
+ $output->writeln('<info>Enregistrement terminé !</info>');
|
|
54
|
+ }
|
|
55
|
+}
|