|
@@ -0,0 +1,71 @@
|
|
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
|
+//use Muzich\CoreBundle\Managers\CommentsManager;
|
|
11
|
+
|
|
12
|
+class MigrationUpgradeCommand extends ContainerAwareCommand
|
|
13
|
+{
|
|
14
|
+ protected function configure()
|
|
15
|
+ {
|
|
16
|
+ $this
|
|
17
|
+ ->setName('migration:upgrade')
|
|
18
|
+ ->setDescription('Mise a jour de données nécéssaire pour migrations')
|
|
19
|
+ ->addArgument('from', InputArgument::REQUIRED, 'version de départ')
|
|
20
|
+ ->addArgument('to', InputArgument::REQUIRED, 'version visé')
|
|
21
|
+ ;
|
|
22
|
+ }
|
|
23
|
+
|
|
24
|
+ protected function execute(InputInterface $input, OutputInterface $output)
|
|
25
|
+ {
|
|
26
|
+ $doctrine = $this->getContainer()->get('doctrine');
|
|
27
|
+ $em = $doctrine->getEntityManager();
|
|
28
|
+
|
|
29
|
+ $output->writeln('#');
|
|
30
|
+ $output->writeln('## Outil de migration ##');
|
|
31
|
+ $output->writeln('#');
|
|
32
|
+
|
|
33
|
+ $proceeded = false;
|
|
34
|
+ if ($input->getArgument('from') == '0.6' && $input->getArgument('to') == '0.7')
|
|
35
|
+ {
|
|
36
|
+ $proceeded = true;
|
|
37
|
+ $output->writeln('<info>Mise a jour des données "commentaires" pour migration 0.6 => 0.7</info>');
|
|
38
|
+ /**
|
|
39
|
+ * Pour cette migration on a besoin de rajouter une valeur aux données
|
|
40
|
+ * de commentaire d'éléments.
|
|
41
|
+ */
|
|
42
|
+
|
|
43
|
+ $elements = $em->getRepository('MuzichCoreBundle:Element')->findAll();
|
|
44
|
+ foreach ($elements as $element)
|
|
45
|
+ {
|
|
46
|
+ if (count(($comments = $element->getComments())))
|
|
47
|
+ {
|
|
48
|
+ // Oui un for serai plus performant ...
|
|
49
|
+ foreach ($comments as $i => $comment)
|
|
50
|
+ {
|
|
51
|
+ // Si il n'y as pas d'enregistrement 'a' dans le commentaire
|
|
52
|
+ if (!array_key_exists('a', $comment))
|
|
53
|
+ {
|
|
54
|
+ // Il faut le rajouter
|
|
55
|
+ $comments[$i]['a'] = array();
|
|
56
|
+ }
|
|
57
|
+ }
|
|
58
|
+ $element->setComments($comments);
|
|
59
|
+ $em->persist($element);
|
|
60
|
+ }
|
|
61
|
+ }
|
|
62
|
+ $em->flush();
|
|
63
|
+ $output->writeln('<info>Terminé !</info>');
|
|
64
|
+ }
|
|
65
|
+
|
|
66
|
+ if (!$proceeded)
|
|
67
|
+ {
|
|
68
|
+ $output->writeln('<error>Versions saisies non prises en charges</error>');
|
|
69
|
+ }
|
|
70
|
+ }
|
|
71
|
+}
|