]> git.immae.eu Git - github/wallabag/wallabag.git/blobdiff - src/Wallabag/UserBundle/EventListener/CreateConfigListener.php
Create user config in one place
[github/wallabag/wallabag.git] / src / Wallabag / UserBundle / EventListener / CreateConfigListener.php
similarity index 53%
rename from src/Wallabag/CoreBundle/EventListener/RegistrationConfirmedListener.php
rename to src/Wallabag/UserBundle/EventListener/CreateConfigListener.php
index 10586126fe35f43ef5ae45a1d1e635686259adb0..15f4ac3dee41faad596d6b56484d3cc1858b6e41 100644 (file)
@@ -1,39 +1,49 @@
 <?php
 
-namespace Wallabag\CoreBundle\EventListener;
+namespace Wallabag\UserBundle\EventListener;
 
 use Doctrine\ORM\EntityManager;
-use FOS\UserBundle\Event\FilterUserResponseEvent;
+use FOS\UserBundle\Event\UserEvent;
 use FOS\UserBundle\FOSUserEvents;
 use Symfony\Component\EventDispatcher\EventDispatcherInterface;
 use Symfony\Component\EventDispatcher\EventSubscriberInterface;
 use Wallabag\CoreBundle\Entity\Config;
 
-class RegistrationConfirmedListener implements EventSubscriberInterface
+/**
+ * This listener will create the associated configuration when a user register.
+ * This configuration will be created right after the registration (no matter if it needs an email validation).
+ */
+class CreateConfigListener implements EventSubscriberInterface
 {
     private $em;
     private $theme;
     private $itemsOnPage;
     private $rssLimit;
     private $language;
+    private $readingSpeed;
 
-    public function __construct(EntityManager $em, $theme, $itemsOnPage, $rssLimit, $language)
+    public function __construct(EntityManager $em, $theme, $itemsOnPage, $rssLimit, $language, $readingSpeed)
     {
         $this->em = $em;
         $this->theme = $theme;
         $this->itemsOnPage = $itemsOnPage;
         $this->rssLimit = $rssLimit;
         $this->language = $language;
+        $this->readingSpeed = $readingSpeed;
     }
 
     public static function getSubscribedEvents()
     {
         return [
-            FOSUserEvents::REGISTRATION_CONFIRMED => 'authenticate',
+            // when a user register using the normal form
+            FOSUserEvents::REGISTRATION_COMPLETED => 'createConfig',
+            // when we manually create a user using the command line
+            // OR when we create it from the config UI
+            FOSUserEvents::USER_CREATED => 'createConfig',
         ];
     }
 
-    public function authenticate(FilterUserResponseEvent $event, $eventName = null, EventDispatcherInterface $eventDispatcher = null)
+    public function createConfig(UserEvent $event, $eventName = null, EventDispatcherInterface $eventDispatcher = null)
     {
         if (!$event->getUser()->isEnabled()) {
             return;
@@ -44,6 +54,8 @@ class RegistrationConfirmedListener implements EventSubscriberInterface
         $config->setItemsPerPage($this->itemsOnPage);
         $config->setRssLimit($this->rssLimit);
         $config->setLanguage($this->language);
+        $config->setReadingSpeed($this->readingSpeed);
+
         $this->em->persist($config);
         $this->em->flush();
     }