|
@@ -9,6 +9,7 @@ use Symfony\Component\Console\Input\InputOption;
|
9
|
9
|
use Symfony\Component\Console\Output\OutputInterface;
|
10
|
10
|
//use Muzich\CoreBundle\Managers\CommentsManager;
|
11
|
11
|
use Muzich\CoreBundle\Util\StrictCanonicalizer;
|
|
12
|
+use Muzich\CoreBundle\Entity\Element;
|
12
|
13
|
|
13
|
14
|
class MigrationUpgradeCommand extends ContainerAwareCommand
|
14
|
15
|
{
|
|
@@ -72,10 +73,17 @@ class MigrationUpgradeCommand extends ContainerAwareCommand
|
72
|
73
|
foreach ($elements as $element)
|
73
|
74
|
{
|
74
|
75
|
$element->setSlug($canonicalizer->canonicalize_stricter($element->getName()));
|
75
|
|
- $output->write('.');
|
|
76
|
+ $this->updateCountFavorited($element);
|
|
77
|
+ $this->updateCountPlaylisted($element);
|
|
78
|
+
|
|
79
|
+ $output->writeln('<info>Element '.$element->getName().' favorited ...'.$element->getCountFavorited().'</info>');
|
|
80
|
+ $output->writeln('<info>Element '.$element->getName().' playlisted ...'.$element->getCountPlaylisted().'</info>');
|
|
81
|
+
|
|
82
|
+ //$output->write('.');
|
76
|
83
|
$em->persist($element);
|
77
|
84
|
}
|
78
|
85
|
|
|
86
|
+ $output->writeln('');
|
79
|
87
|
$output->writeln('<info>Save in Database ...</info>');
|
80
|
88
|
$em->flush();
|
81
|
89
|
$output->writeln('<info>Terminé !</info>');
|
|
@@ -86,4 +94,49 @@ class MigrationUpgradeCommand extends ContainerAwareCommand
|
86
|
94
|
$output->writeln('<error>Versions saisies non prises en charges</error>');
|
87
|
95
|
}
|
88
|
96
|
}
|
|
97
|
+
|
|
98
|
+ protected function updateCountFavorited(Element $element)
|
|
99
|
+ {
|
|
100
|
+ $em = $this->getContainer()->get('doctrine')->getEntityManager();
|
|
101
|
+
|
|
102
|
+ // Compter le nombre de favoris de cet élement
|
|
103
|
+ // + Effectué par un autre que le proprio
|
|
104
|
+ // + Qui ont l'email confirmé
|
|
105
|
+
|
|
106
|
+ $count = $em->createQueryBuilder()
|
|
107
|
+ ->select('COUNT(DISTINCT element)')
|
|
108
|
+ ->from('MuzichCoreBundle:UsersElementsFavorites', 'fav')
|
|
109
|
+ ->join('fav.user', 'owner')
|
|
110
|
+ ->join('fav.element', 'element')
|
|
111
|
+ ->where('fav.user != :element_owner_id AND owner.email_confirmed = 1')
|
|
112
|
+ ->andWhere('fav.element = :element_id')
|
|
113
|
+ ->setParameter('element_owner_id', $element->getOwner()->getId())
|
|
114
|
+ ->setParameter('element_id', $element->getId())
|
|
115
|
+ ->getQuery()
|
|
116
|
+ ->getSingleScalarResult()
|
|
117
|
+ ;
|
|
118
|
+ $element->setCountFavorited($count);
|
|
119
|
+ }
|
|
120
|
+
|
|
121
|
+ protected function updateCountPlaylisted(Element $element)
|
|
122
|
+ {
|
|
123
|
+ $em = $this->getContainer()->get('doctrine')->getEntityManager();
|
|
124
|
+
|
|
125
|
+ // Compter le nombre d'user qui ont l'element dans une playlist
|
|
126
|
+ // + Effectué par un user différent que le proprio
|
|
127
|
+ // + Qui ont l'email confirmé
|
|
128
|
+
|
|
129
|
+ $count = $em->createQueryBuilder()
|
|
130
|
+ ->select('COUNT(DISTINCT user)')
|
|
131
|
+ ->from('MuzichCoreBundle:Playlist', 'playlist')
|
|
132
|
+ ->join('playlist.owner', 'user')
|
|
133
|
+ ->where('playlist.elements LIKE :element_id AND playlist.owner != :element_owner_id AND user.email_confirmed = 1')
|
|
134
|
+ ->setParameter('element_owner_id', $element->getOwner()->getId())
|
|
135
|
+ ->setParameter('element_id', '%"id":"'.$element->getId().'"%')
|
|
136
|
+ ->getQuery()
|
|
137
|
+ ->getSingleScalarResult()
|
|
138
|
+ ;
|
|
139
|
+ $element->setCountPlaylisted($count);
|
|
140
|
+ }
|
|
141
|
+
|
89
|
142
|
}
|