diff options
author | Nicolas LÅ“uillet <nicolas@loeuillet.org> | 2016-10-01 15:51:37 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-10-01 15:51:37 +0200 |
commit | db5541e7a1e7131d62b4df23fa6eadd0c542b256 (patch) | |
tree | c5c71df873a9aa9350660e225f046a448274868f /src/Wallabag/CoreBundle | |
parent | 114c55c0a6eade2ba6c53fe25f61cc58cca91620 (diff) | |
parent | fb7354c4a430f4f4916a1247aa1b1bf564ead0da (diff) | |
download | wallabag-db5541e7a1e7131d62b4df23fa6eadd0c542b256.tar.gz wallabag-db5541e7a1e7131d62b4df23fa6eadd0c542b256.tar.zst wallabag-db5541e7a1e7131d62b4df23fa6eadd0c542b256.zip |
Merge pull request #2320 from wallabag/user-config
Create user config in one place.
Diffstat (limited to 'src/Wallabag/CoreBundle')
4 files changed, 12 insertions, 80 deletions
diff --git a/src/Wallabag/CoreBundle/Command/InstallCommand.php b/src/Wallabag/CoreBundle/Command/InstallCommand.php index 3873d2d3..cc7c2c94 100644 --- a/src/Wallabag/CoreBundle/Command/InstallCommand.php +++ b/src/Wallabag/CoreBundle/Command/InstallCommand.php | |||
@@ -2,6 +2,8 @@ | |||
2 | 2 | ||
3 | namespace Wallabag\CoreBundle\Command; | 3 | namespace Wallabag\CoreBundle\Command; |
4 | 4 | ||
5 | use FOS\UserBundle\Event\UserEvent; | ||
6 | use FOS\UserBundle\FOSUserEvents; | ||
5 | use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; | 7 | use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; |
6 | use Symfony\Component\Console\Helper\Table; | 8 | use Symfony\Component\Console\Helper\Table; |
7 | use Symfony\Component\Console\Input\ArrayInput; | 9 | use Symfony\Component\Console\Input\ArrayInput; |
@@ -236,14 +238,9 @@ class InstallCommand extends ContainerAwareCommand | |||
236 | 238 | ||
237 | $em->persist($user); | 239 | $em->persist($user); |
238 | 240 | ||
239 | $config = new Config($user); | 241 | // dispatch a created event so the associated config will be created |
240 | $config->setTheme($this->getContainer()->getParameter('wallabag_core.theme')); | 242 | $event = new UserEvent($user); |
241 | $config->setItemsPerPage($this->getContainer()->getParameter('wallabag_core.items_on_page')); | 243 | $this->getContainer()->get('event_dispatcher')->dispatch(FOSUserEvents::USER_CREATED, $event); |
242 | $config->setRssLimit($this->getContainer()->getParameter('wallabag_core.rss_limit')); | ||
243 | $config->setReadingSpeed($this->getContainer()->getParameter('wallabag_core.reading_speed')); | ||
244 | $config->setLanguage($this->getContainer()->getParameter('wallabag_core.language')); | ||
245 | |||
246 | $em->persist($config); | ||
247 | 244 | ||
248 | $this->defaultOutput->writeln(''); | 245 | $this->defaultOutput->writeln(''); |
249 | 246 | ||
diff --git a/src/Wallabag/CoreBundle/Controller/ConfigController.php b/src/Wallabag/CoreBundle/Controller/ConfigController.php index 4f75511b..75a9af0b 100644 --- a/src/Wallabag/CoreBundle/Controller/ConfigController.php +++ b/src/Wallabag/CoreBundle/Controller/ConfigController.php | |||
@@ -2,6 +2,8 @@ | |||
2 | 2 | ||
3 | namespace Wallabag\CoreBundle\Controller; | 3 | namespace Wallabag\CoreBundle\Controller; |
4 | 4 | ||
5 | use FOS\UserBundle\Event\UserEvent; | ||
6 | use FOS\UserBundle\FOSUserEvents; | ||
5 | use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; | 7 | use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; |
6 | use Symfony\Bundle\FrameworkBundle\Controller\Controller; | 8 | use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
7 | use Symfony\Component\HttpFoundation\JsonResponse; | 9 | use Symfony\Component\HttpFoundation\JsonResponse; |
@@ -133,18 +135,11 @@ class ConfigController extends Controller | |||
133 | $newUserForm->handleRequest($request); | 135 | $newUserForm->handleRequest($request); |
134 | 136 | ||
135 | if ($newUserForm->isValid() && $this->get('security.authorization_checker')->isGranted('ROLE_SUPER_ADMIN')) { | 137 | if ($newUserForm->isValid() && $this->get('security.authorization_checker')->isGranted('ROLE_SUPER_ADMIN')) { |
136 | $userManager->updateUser($newUser, true); | 138 | $userManager->updateUser($newUser); |
137 | 139 | ||
138 | $config = new Config($newUser); | 140 | // dispatch a created event so the associated config will be created |
139 | $config->setTheme($this->getParameter('wallabag_core.theme')); | 141 | $event = new UserEvent($newUser, $request); |
140 | $config->setItemsPerPage($this->getParameter('wallabag_core.items_on_page')); | 142 | $this->get('event_dispatcher')->dispatch(FOSUserEvents::USER_CREATED, $event); |
141 | $config->setRssLimit($this->getParameter('wallabag_core.rss_limit')); | ||
142 | $config->setLanguage($this->getParameter('wallabag_core.language')); | ||
143 | $config->setReadingSpeed($this->getParameter('wallabag_core.reading_speed')); | ||
144 | |||
145 | $em->persist($config); | ||
146 | |||
147 | $em->flush(); | ||
148 | 143 | ||
149 | $this->get('session')->getFlashBag()->add( | 144 | $this->get('session')->getFlashBag()->add( |
150 | 'notice', | 145 | 'notice', |
@@ -238,6 +233,7 @@ class ConfigController extends Controller | |||
238 | ->getRepository('WallabagCoreBundle:Config') | 233 | ->getRepository('WallabagCoreBundle:Config') |
239 | ->findOneByUser($this->getUser()); | 234 | ->findOneByUser($this->getUser()); |
240 | 235 | ||
236 | // should NEVER HAPPEN ... | ||
241 | if (!$config) { | 237 | if (!$config) { |
242 | $config = new Config($this->getUser()); | 238 | $config = new Config($this->getUser()); |
243 | } | 239 | } |
diff --git a/src/Wallabag/CoreBundle/EventListener/RegistrationConfirmedListener.php b/src/Wallabag/CoreBundle/EventListener/RegistrationConfirmedListener.php deleted file mode 100644 index 10586126..00000000 --- a/src/Wallabag/CoreBundle/EventListener/RegistrationConfirmedListener.php +++ /dev/null | |||
@@ -1,50 +0,0 @@ | |||
1 | <?php | ||
2 | |||
3 | namespace Wallabag\CoreBundle\EventListener; | ||
4 | |||
5 | use Doctrine\ORM\EntityManager; | ||
6 | use FOS\UserBundle\Event\FilterUserResponseEvent; | ||
7 | use FOS\UserBundle\FOSUserEvents; | ||
8 | use Symfony\Component\EventDispatcher\EventDispatcherInterface; | ||
9 | use Symfony\Component\EventDispatcher\EventSubscriberInterface; | ||
10 | use Wallabag\CoreBundle\Entity\Config; | ||
11 | |||
12 | class RegistrationConfirmedListener implements EventSubscriberInterface | ||
13 | { | ||
14 | private $em; | ||
15 | private $theme; | ||
16 | private $itemsOnPage; | ||
17 | private $rssLimit; | ||
18 | private $language; | ||
19 | |||
20 | public function __construct(EntityManager $em, $theme, $itemsOnPage, $rssLimit, $language) | ||
21 | { | ||
22 | $this->em = $em; | ||
23 | $this->theme = $theme; | ||
24 | $this->itemsOnPage = $itemsOnPage; | ||
25 | $this->rssLimit = $rssLimit; | ||
26 | $this->language = $language; | ||
27 | } | ||
28 | |||
29 | public static function getSubscribedEvents() | ||
30 | { | ||
31 | return [ | ||
32 | FOSUserEvents::REGISTRATION_CONFIRMED => 'authenticate', | ||
33 | ]; | ||
34 | } | ||
35 | |||
36 | public function authenticate(FilterUserResponseEvent $event, $eventName = null, EventDispatcherInterface $eventDispatcher = null) | ||
37 | { | ||
38 | if (!$event->getUser()->isEnabled()) { | ||
39 | return; | ||
40 | } | ||
41 | |||
42 | $config = new Config($event->getUser()); | ||
43 | $config->setTheme($this->theme); | ||
44 | $config->setItemsPerPage($this->itemsOnPage); | ||
45 | $config->setRssLimit($this->rssLimit); | ||
46 | $config->setLanguage($this->language); | ||
47 | $this->em->persist($config); | ||
48 | $this->em->flush(); | ||
49 | } | ||
50 | } | ||
diff --git a/src/Wallabag/CoreBundle/Resources/config/services.yml b/src/Wallabag/CoreBundle/Resources/config/services.yml index 23e6d3ca..5a727ec5 100644 --- a/src/Wallabag/CoreBundle/Resources/config/services.yml +++ b/src/Wallabag/CoreBundle/Resources/config/services.yml | |||
@@ -88,17 +88,6 @@ services: | |||
88 | arguments: | 88 | arguments: |
89 | - WallabagCoreBundle:Tag | 89 | - WallabagCoreBundle:Tag |
90 | 90 | ||
91 | wallabag_core.registration_confirmed: | ||
92 | class: Wallabag\CoreBundle\EventListener\RegistrationConfirmedListener | ||
93 | arguments: | ||
94 | - "@doctrine.orm.entity_manager" | ||
95 | - "%wallabag_core.theme%" | ||
96 | - "%wallabag_core.items_on_page%" | ||
97 | - "%wallabag_core.rss_limit%" | ||
98 | - "%wallabag_core.language%" | ||
99 | tags: | ||
100 | - { name: kernel.event_subscriber } | ||
101 | |||
102 | wallabag_core.helper.entries_export: | 91 | wallabag_core.helper.entries_export: |
103 | class: Wallabag\CoreBundle\Helper\EntriesExport | 92 | class: Wallabag\CoreBundle\Helper\EntriesExport |
104 | arguments: | 93 | arguments: |