]> git.immae.eu Git - github/wallabag/wallabag.git/blobdiff - src/Wallabag/ImportBundle/Consumer/AbstractConsumer.php
Validate imported entry to avoid error on import
[github/wallabag/wallabag.git] / src / Wallabag / ImportBundle / Consumer / AbstractConsumer.php
index aa7ff9144a121aa4f915320da9f29cdce3204d1b..e4bfbdf033807fca182b99343d6455d6361e451a 100644 (file)
@@ -3,20 +3,21 @@
 namespace Wallabag\ImportBundle\Consumer;
 
 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;
 use Symfony\Component\EventDispatcher\EventDispatcherInterface;
+use Wallabag\CoreBundle\Entity\Entry;
+use Wallabag\CoreBundle\Entity\Tag;
 use Wallabag\CoreBundle\Event\EntrySavedEvent;
+use Wallabag\ImportBundle\Import\AbstractImport;
+use Wallabag\UserBundle\Repository\UserRepository;
 
 abstract class AbstractConsumer
 {
     protected $em;
     protected $userRepository;
     protected $import;
+    protected $eventDispatcher;
     protected $logger;
 
     public function __construct(EntityManager $em, UserRepository $userRepository, AbstractImport $import, EventDispatcherInterface $eventDispatcher, LoggerInterface $logger = null)
@@ -45,11 +46,19 @@ abstract class AbstractConsumer
         if (null === $user) {
             $this->logger->warning('Unable to retrieve user', ['entry' => $storedEntry]);
 
-            return false;
+            // return true to skip message
+            return true;
         }
 
         $this->import->setUser($user);
 
+        if (false === $this->import->validateEntry($storedEntry)) {
+            $this->logger->warning('Entry is invalid', ['entry' => $storedEntry]);
+
+            // return true to skip message
+            return true;
+        }
+
         $entry = $this->import->parseEntry($storedEntry);
 
         if (null === $entry) {
@@ -74,7 +83,7 @@ abstract class AbstractConsumer
             return false;
         }
 
-        $this->logger->info('Content with url imported! ('.$entry->getUrl().')');
+        $this->logger->info('Content with url imported! (' . $entry->getUrl() . ')');
 
         return true;
     }