]> git.immae.eu Git - github/wallabag/wallabag.git/blobdiff - src/Wallabag/ImportBundle/Consumer/RedisEntryConsumer.php
Jump to Simpleue 2.0
[github/wallabag/wallabag.git] / src / Wallabag / ImportBundle / Consumer / RedisEntryConsumer.php
index 38665b01a1a89847afc9bcf552b7ba94ac40e2da..862d0c43cee1d77bbee944405e717deaaba3e24f 100644 (file)
@@ -3,29 +3,9 @@
 namespace Wallabag\ImportBundle\Consumer;
 
 use Simpleue\Job\Job;
-use Doctrine\ORM\EntityManager;
-use Wallabag\ImportBundle\Import\AbstractImport;
-use Wallabag\UserBundle\Repository\UserRepository;
-use Wallabag\CoreBundle\Entity\Entry;
-use Wallabag\CoreBundle\Entity\Tag;
-use Psr\Log\LoggerInterface;
-use Psr\Log\NullLogger;
 
-class RedisEntryConsumer implements Job
+class RedisEntryConsumer extends AbstractConsumer implements Job
 {
-    private $em;
-    private $userRepository;
-    private $import;
-    private $logger;
-
-    public function __construct(EntityManager $em, UserRepository $userRepository, AbstractImport $import, LoggerInterface $logger = null)
-    {
-        $this->em = $em;
-        $this->userRepository = $userRepository;
-        $this->import = $import;
-        $this->logger = $logger ?: new NullLogger();
-    }
-
     /**
      * Handle one message by one message.
      *
@@ -35,50 +15,32 @@ class RedisEntryConsumer implements Job
      */
     public function manage($job)
     {
-        $storedEntry = json_decode($job, true);
-
-        $user = $this->userRepository->find($storedEntry['userId']);
-
-        // no user? Drop message
-        if (null === $user) {
-            $this->logger->warning('Unable to retrieve user', ['entry' => $storedEntry]);
-
-            return false;
-        }
-
-        $this->import->setUser($user);
-
-        $entry = $this->import->parseEntry($storedEntry);
-
-        if (null === $entry) {
-            $this->logger->warning('Unable to parse entry', ['entry' => $storedEntry]);
-
-            return false;
-        }
-
-        try {
-            $this->em->flush();
-
-            // clear only affected entities
-            $this->em->clear(Entry::class);
-            $this->em->clear(Tag::class);
-        } catch (\Exception $e) {
-            $this->logger->warning('Unable to save entry', ['entry' => $storedEntry, 'exception' => $e]);
-
-            return false;
-        }
-
-        $this->logger->info('Content with url ('.$entry->getUrl().') imported !');
-
-        return true;
+        return $this->handleMessage($job);
     }
 
     /**
      * Should tell if the given job will kill the worker.
      * We don't want to stop it :).
+     *
+     * @param string $job Content of the message (directly from Redis)
+     *
+     * @return false
      */
     public function isStopJob($job)
     {
         return false;
     }
+
+    /**
+     * This abstract method is only used when we use one queue for multiple job type.
+     * We don't do that, so we'll always return true.
+     *
+     * @param string $job Content of the message (directly from Redis)
+     *
+     * @return true
+     */
+    public function isMyJob($job)
+    {
+        return true;
+    }
 }