]> git.immae.eu Git - github/wallabag/wallabag.git/commitdiff
Add ability to define created_at for all import
authorJeremy Benoist <jeremy.benoist@gmail.com>
Fri, 9 Sep 2016 07:36:07 +0000 (09:36 +0200)
committerJeremy Benoist <jeremy.benoist@gmail.com>
Sun, 11 Sep 2016 19:58:55 +0000 (21:58 +0200)
At the moment only Readability & wallabag v2 import allow created_at import.
Pocket removed `time_added` field from their API v2 to v3...
And wallabag v1 doesn't export that value.

src/Wallabag/CoreBundle/Entity/Entry.php
src/Wallabag/ImportBundle/Import/PocketImport.php
src/Wallabag/ImportBundle/Import/ReadabilityImport.php
src/Wallabag/ImportBundle/Import/WallabagImport.php
src/Wallabag/ImportBundle/Import/WallabagV1Import.php
tests/Wallabag/ImportBundle/Controller/ReadabilityControllerTest.php
tests/Wallabag/ImportBundle/Controller/WallabagV1ControllerTest.php
tests/Wallabag/ImportBundle/Controller/WallabagV2ControllerTest.php

index c3e6b4d5d35305b3ff3b7fbca1ec58365b7489ea..304258a9c28854977988247fd229d9b676d8de9e 100644 (file)
@@ -410,7 +410,22 @@ class Entry
     }
 
     /**
-     * @return string
+     * Set created_at.
+     * Only used when importing data from an other service.
+     *
+     * @param DateTime $createdAt
+     *
+     * @return Entry
+     */
+    public function setCreatedAt(\DateTime $createdAt)
+    {
+        $this->createdAt = $createdAt;
+
+        return $this;
+    }
+
+    /**
+     * @return DateTime
      */
     public function getCreatedAt()
     {
@@ -418,7 +433,7 @@ class Entry
     }
 
     /**
-     * @return string
+     * @return DateTime
      */
     public function getUpdatedAt()
     {
index 845380b798f61a36c01d28f742e6bcb9c59c85ba..92dcdd409b25d4099914153f4a042d15ed0f7dae 100644 (file)
@@ -193,6 +193,11 @@ class PocketImport extends AbstractImport
         $this->client = $client;
     }
 
+    /**
+     * {@inheritdoc}
+     *
+     * @see https://getpocket.com/developer/docs/v3/retrieve
+     */
     public function parseEntry(array $importedEntry)
     {
         $url = isset($importedEntry['resolved_url']) && $importedEntry['resolved_url'] != '' ? $importedEntry['resolved_url'] : $importedEntry['given_url'];
index 915d4cd38508258a93817c0e493dbf21d862d2f7..8f080d382c12fa0d16e9e1f43675545b448bcdc9 100644 (file)
@@ -89,6 +89,9 @@ class ReadabilityImport extends AbstractImport
         return true;
     }
 
+    /**
+     * {@inheritdoc}
+     */
     public function parseEntry(array $importedEntry)
     {
         $existingEntry = $this->em
@@ -108,6 +111,7 @@ class ReadabilityImport extends AbstractImport
             'language' => '',
             'is_archived' => $importedEntry['archive'] || $this->markAsRead,
             'is_starred' => $importedEntry['favorite'],
+            'created_at' => $importedEntry['date_added'],
         ];
 
         $entry = $this->fetchContent(
@@ -125,6 +129,7 @@ class ReadabilityImport extends AbstractImport
 
         $entry->setArchived($data['is_archived']);
         $entry->setStarred($data['is_starred']);
+        $entry->setCreatedAt(new \DateTime($data['created_at']));
 
         $this->em->persist($entry);
         ++$this->importedEntries;
index 026567b07e6b8ba1c3a6d5af7bec76ddaf2e4590..8e50b135a980a522feda860773671339250a35ad 100644 (file)
@@ -139,6 +139,10 @@ abstract class WallabagImport extends AbstractImport
         $entry->setArchived($data['is_archived']);
         $entry->setStarred($data['is_starred']);
 
+        if (!empty($data['created_at'])) {
+            $entry->setCreatedAt(new \DateTime($data['created_at']));
+        }
+
         $this->em->persist($entry);
         ++$this->importedEntries;
 
index 292b72a70650b9f51e42d0dd1951825f664e8494..4f0010624d047131046697f7929f7baf632e16ab 100644 (file)
@@ -42,6 +42,7 @@ class WallabagV1Import extends WallabagImport
             'is_archived' => $entry['is_read'] || $this->markAsRead,
             'is_starred' => $entry['is_fav'],
             'tags' => '',
+            'created_at' => '',
         ];
 
         // force content to be refreshed in case on bad fetch in the v1 installation
index 92cf4bfc8efd3d147448a89c4c5a3b9504ae13f6..fb39356a140c1b128566c35e0e011629e4a7f7d9 100644 (file)
@@ -49,6 +49,13 @@ class ReadabilityControllerTest extends WallabagCoreTestCase
 
         $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
         $this->assertContains('flashes.import.notice.summary', $body[0]);
+
+        $this->assertNotEmpty($content->getMimetype());
+        $this->assertNotEmpty($content->getPreviewPicture());
+        $this->assertNotEmpty($content->getLanguage());
+        $this->assertEquals(0, count($content->getTags()));
+        $this->assertInstanceOf(\DateTime::class, $content->getCreatedAt());
+        $this->assertEquals('2016-08-25', $content->getCreatedAt()->format('Y-m-d'));
     }
 
     public function testImportReadabilityWithFileAndMarkAllAsRead()
index c1025b41c4a51a180ee7432ac15489797d0c303f..ff1bf6f050580809414af7e42db25abac861c4d5 100644 (file)
@@ -56,6 +56,12 @@ class WallabagV1ControllerTest extends WallabagCoreTestCase
 
         $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
         $this->assertContains('flashes.import.notice.summary', $body[0]);
+
+        $this->assertEmpty($content->getMimetype());
+        $this->assertEmpty($content->getPreviewPicture());
+        $this->assertEmpty($content->getLanguage());
+        $this->assertEquals(1, count($content->getTags()));
+        $this->assertInstanceOf(\DateTime::class, $content->getCreatedAt());
     }
 
     public function testImportWallabagWithFileAndMarkAllAsRead()
index d8d2c8bf60267d34fd9119492e5ec668a85c4b0f..149e88bbbf3c3727447a8139f5ede31115de542a 100644 (file)
@@ -67,6 +67,8 @@ class WallabagV2ControllerTest extends WallabagCoreTestCase
         $this->assertNotEmpty($content->getPreviewPicture());
         $this->assertNotEmpty($content->getLanguage());
         $this->assertEquals(2, count($content->getTags()));
+        $this->assertInstanceOf(\DateTime::class, $content->getCreatedAt());
+        $this->assertEquals('2016-09-08', $content->getCreatedAt()->format('Y-m-d'));
     }
 
     public function testImportWallabagWithEmptyFile()