]> git.immae.eu Git - github/wallabag/wallabag.git/blobdiff - src/Wallabag/ImportBundle/Import/ReadabilityImport.php
Merge remote-tracking branch 'origin/master' into 2.4
[github/wallabag/wallabag.git] / src / Wallabag / ImportBundle / Import / ReadabilityImport.php
index 18a6631a02dbfb993f66abfde522831f8aec2b02..c5abf18921f1a40ba8efa68bc48177a362f8c2ab 100644 (file)
@@ -3,12 +3,9 @@
 namespace Wallabag\ImportBundle\Import;
 
 use Wallabag\CoreBundle\Entity\Entry;
-use Wallabag\UserBundle\Entity\User;
 
 class ReadabilityImport extends AbstractImport
 {
-    private $skippedEntries = 0;
-    private $importedEntries = 0;
     private $filepath;
 
     /**
@@ -47,17 +44,6 @@ class ReadabilityImport extends AbstractImport
         return $this;
     }
 
-    /**
-     * {@inheritdoc}
-     */
-    public function getSummary()
-    {
-        return [
-            'skipped' => $this->skippedEntries,
-            'imported' => $this->importedEntries,
-        ];
-    }
-
     /**
      * {@inheritdoc}
      */
@@ -78,6 +64,8 @@ class ReadabilityImport extends AbstractImport
         $data = json_decode(file_get_contents($this->filepath), true);
 
         if (empty($data) || empty($data['bookmarks'])) {
+            $this->logger->error('ReadabilityImport: no entries in imported file');
+
             return false;
         }
 
@@ -92,6 +80,21 @@ class ReadabilityImport extends AbstractImport
         return true;
     }
 
+    /**
+     * {@inheritdoc}
+     */
+    public function validateEntry(array $importedEntry)
+    {
+        if (empty($importedEntry['article__url'])) {
+            return false;
+        }
+
+        return true;
+    }
+
+    /**
+     * {@inheritdoc}
+     */
     public function parseEntry(array $importedEntry)
     {
         $existingEntry = $this->em
@@ -107,27 +110,22 @@ class ReadabilityImport extends AbstractImport
         $data = [
             'title' => $importedEntry['article__title'],
             'url' => $importedEntry['article__url'],
-            'content_type' => '',
-            'language' => '',
             'is_archived' => $importedEntry['archive'] || $this->markAsRead,
             'is_starred' => $importedEntry['favorite'],
+            'created_at' => $importedEntry['date_added'],
+            'html' => false,
         ];
 
-        $entry = $this->fetchContent(
-            new Entry($this->user),
-            $data['url'],
-            $data
-        );
+        $entry = new Entry($this->user);
+        $entry->setUrl($data['url']);
+        $entry->setTitle($data['title']);
 
-        // jump to next entry in case of problem while getting content
-        if (false === $entry) {
-            ++$this->skippedEntries;
+        // update entry with content (in case fetching failed, the given entry will be return)
+        $this->fetchContent($entry, $data['url'], $data);
 
-            return;
-        }
-
-        $entry->setArchived($data['is_archived']);
+        $entry->updateArchived($data['is_archived']);
         $entry->setStarred($data['is_starred']);
+        $entry->setCreatedAt(new \DateTime($data['created_at']));
 
         $this->em->persist($entry);
         ++$this->importedEntries;
@@ -136,31 +134,12 @@ class ReadabilityImport extends AbstractImport
     }
 
     /**
-     * Faster parse entries for Producer.
-     * We don't care to make check at this time. They'll be done by the consumer.
-     *
-     * @param array $entries
+     * {@inheritdoc}
      */
-    protected function parseEntriesForProducer($entries)
+    protected function setEntryAsRead(array $importedEntry)
     {
-        foreach ($entries as $importedEntry) {
-            // set userId for the producer (it won't know which user is connected)
-            $importedEntry['userId'] = $this->user->getId();
-
-            if ($this->markAsRead) {
-                $importedEntry['archive'] = 1;
-            }
-
-            ++$this->importedEntries;
-
-            // flush every 20 entries
-            if (($i % 20) === 0) {
-                $this->em->flush();
-            }
-            ++$i;
-        }
+        $importedEntry['archive'] = 1;
 
-        $this->em->flush();
-        $this->em->clear();
+        return $importedEntry;
     }
 }