]> git.immae.eu Git - github/wallabag/wallabag.git/blobdiff - src/Wallabag/ImportBundle/Import/ReadabilityImport.php
Validate imported entry to avoid error on import
[github/wallabag/wallabag.git] / src / Wallabag / ImportBundle / Import / ReadabilityImport.php
index 915d4cd38508258a93817c0e493dbf21d862d2f7..a5f3798e0277f05b4167c6318be47a9cb5d603b7 100644 (file)
@@ -44,17 +44,6 @@ class ReadabilityImport extends AbstractImport
         return $this;
     }
 
-    /**
-     * {@inheritdoc}
-     */
-    public function getSummary()
-    {
-        return [
-            'skipped' => $this->skippedEntries,
-            'imported' => $this->importedEntries,
-        ];
-    }
-
     /**
      * {@inheritdoc}
      */
@@ -75,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;
         }
 
@@ -89,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
@@ -104,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
-        );
-
-        // jump to next entry in case of problem while getting content
-        if (false === $entry) {
-            ++$this->skippedEntries;
+        $entry = new Entry($this->user);
+        $entry->setUrl($data['url']);
+        $entry->setTitle($data['title']);
 
-            return;
-        }
+        // update entry with content (in case fetching failed, the given entry will be return)
+        $this->fetchContent($entry, $data['url'], $data);
 
         $entry->setArchived($data['is_archived']);
         $entry->setStarred($data['is_starred']);
+        $entry->setCreatedAt(new \DateTime($data['created_at']));
 
         $this->em->persist($entry);
         ++$this->importedEntries;