]> git.immae.eu Git - github/wallabag/wallabag.git/blobdiff - src/Wallabag/ImportBundle/Import/ChromeImport.php
Validate imported entry to avoid error on import
[github/wallabag/wallabag.git] / src / Wallabag / ImportBundle / Import / ChromeImport.php
index 7936ee2f427d862ab9df3f2f1d2994739814fa59..eccee69869a1197c59bdf3e500953a4c6867d424 100644 (file)
@@ -2,13 +2,6 @@
 
 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;
-
 class ChromeImport extends BrowserImport
 {
     protected $filepath;
@@ -38,34 +31,36 @@ class ChromeImport extends BrowserImport
     }
 
     /**
-       * {@inheritdoc}
-       */
-      protected function prepareEntry($entry = [])
-      {
-          $data = [
-              'title' => $entry['name'],
-              'html' => '',
-              'url' => $entry['url'],
-              'is_archived' => $this->markAsRead,
-              'tags' => '',
-              'created_at' => $entry['date_added'],
-          ];
-
-          if (array_key_exists('tags', $entry) && $entry['tags'] != '') {
-              $data['tags'] = $entry['tags'];
-          }
-
-          return $data;
-      }
+     * {@inheritdoc}
+     */
+    public function validateEntry(array $importedEntry)
+    {
+        if (empty($importedEntry['url'])) {
+            return false;
+        }
 
+        return true;
+    }
 
     /**
      * {@inheritdoc}
      */
-    protected function setEntryAsRead(array $importedEntry)
+    protected function prepareEntry(array $entry = [])
     {
-        $importedEntry['is_archived'] = 1;
+        $data = [
+            'title' => $entry['name'],
+            'html' => false,
+            'url' => $entry['url'],
+            'is_archived' => (int) $this->markAsRead,
+            'is_starred' => false,
+            'tags' => '',
+            'created_at' => substr($entry['date_added'], 0, 10),
+        ];
+
+        if (array_key_exists('tags', $entry) && '' !== $entry['tags']) {
+            $data['tags'] = $entry['tags'];
+        }
 
-        return $importedEntry;
+        return $data;
     }
 }