]> git.immae.eu Git - github/wallabag/wallabag.git/blobdiff - src/Wallabag/ImportBundle/Import/WallabagImport.php
Fix error on EntityManager clear
[github/wallabag/wallabag.git] / src / Wallabag / ImportBundle / Import / WallabagImport.php
index d65bc5306e1a35038768d5e054b45b3916788318..9cd3dcb8bac7213118136503d64a799016de6cbb 100644 (file)
@@ -2,19 +2,12 @@
 
 namespace Wallabag\ImportBundle\Import;
 
-use Psr\Log\LoggerInterface;
-use Psr\Log\NullLogger;
-use Doctrine\ORM\EntityManager;
 use Wallabag\CoreBundle\Entity\Entry;
 use Wallabag\UserBundle\Entity\User;
-use Wallabag\CoreBundle\Helper\ContentProxy;
 
-abstract class WallabagImport implements ImportInterface
+abstract class WallabagImport extends AbstractImport
 {
     protected $user;
-    protected $em;
-    protected $logger;
-    protected $contentProxy;
     protected $skippedEntries = 0;
     protected $importedEntries = 0;
     protected $filepath;
@@ -35,18 +28,6 @@ abstract class WallabagImport implements ImportInterface
         '',
     ];
 
-    public function __construct(EntityManager $em, ContentProxy $contentProxy)
-    {
-        $this->em = $em;
-        $this->logger = new NullLogger();
-        $this->contentProxy = $contentProxy;
-    }
-
-    public function setLogger(LoggerInterface $logger)
-    {
-        $this->logger = $logger;
-    }
-
     /**
      * We define the user in a custom call because on the import command there is no logged in user.
      * So we can't retrieve user from the `security.token_storage` service.
@@ -159,12 +140,18 @@ abstract class WallabagImport implements ImportInterface
 
             $data = $this->prepareEntry($importedEntry, $this->markAsRead);
 
-            $entry = $this->contentProxy->updateEntry(
+            $entry = $this->fetchContent(
                 new Entry($this->user),
                 $importedEntry['url'],
                 $data
             );
 
+            // jump to next entry in case of problem while getting content
+            if (false === $entry) {
+                ++$this->skippedEntries;
+                continue;
+            }
+
             if (array_key_exists('tags', $data)) {
                 $this->contentProxy->assignTagsToEntry(
                     $entry,
@@ -185,6 +172,10 @@ abstract class WallabagImport implements ImportInterface
             // flush every 20 entries
             if (($i % 20) === 0) {
                 $this->em->flush();
+
+                // clear only affected entities
+                $this->em->clear(Entry::class);
+                $this->em->clear(Tag::class);
             }
             ++$i;
         }