From 27acc6ddb8b0a1549a3f015171621e3056ef65d2 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Sun, 25 Sep 2016 15:29:40 +0200 Subject: [PATCH] Fix bad date format in Browser import --- .../ImportBundle/Import/BrowserImport.php | 23 ++++++++++++++ .../ImportBundle/Import/ChromeImport.php | 31 ------------------- .../ImportBundle/Import/FirefoxImport.php | 31 ------------------- .../Controller/ChromeControllerTest.php | 4 +++ .../Controller/FirefoxControllerTest.php | 4 +++ 5 files changed, 31 insertions(+), 62 deletions(-) diff --git a/src/Wallabag/ImportBundle/Import/BrowserImport.php b/src/Wallabag/ImportBundle/Import/BrowserImport.php index 44315e8b..da69df9b 100644 --- a/src/Wallabag/ImportBundle/Import/BrowserImport.php +++ b/src/Wallabag/ImportBundle/Import/BrowserImport.php @@ -193,6 +193,29 @@ abstract class BrowserImport extends AbstractImport return $entry; } + /** + * {@inheritdoc} + */ + protected function prepareEntry($entry = []) + { + $data = [ + 'title' => $entry['name'], + 'html' => '', + 'url' => $entry['url'], + 'is_archived' => $this->markAsRead, + 'tags' => '', + // date are in format like "13118829474385693" + // and it'll be devided by 1000 in AbstractImport + 'created_at' => (int) ceil($entry['date_added'] / 10000), + ]; + + if (array_key_exists('tags', $entry) && $entry['tags'] != '') { + $data['tags'] = $entry['tags']; + } + + return $data; + } + /** * {@inheritdoc} */ diff --git a/src/Wallabag/ImportBundle/Import/ChromeImport.php b/src/Wallabag/ImportBundle/Import/ChromeImport.php index 1af7cc87..60602a1b 100644 --- a/src/Wallabag/ImportBundle/Import/ChromeImport.php +++ b/src/Wallabag/ImportBundle/Import/ChromeImport.php @@ -29,35 +29,4 @@ class ChromeImport extends BrowserImport { return 'import.chrome.description'; } - - /** - * {@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} - */ - protected function setEntryAsRead(array $importedEntry) - { - $importedEntry['is_archived'] = 1; - - return $importedEntry; - } } diff --git a/src/Wallabag/ImportBundle/Import/FirefoxImport.php b/src/Wallabag/ImportBundle/Import/FirefoxImport.php index 351cbef1..1a0b1154 100644 --- a/src/Wallabag/ImportBundle/Import/FirefoxImport.php +++ b/src/Wallabag/ImportBundle/Import/FirefoxImport.php @@ -29,35 +29,4 @@ class FirefoxImport extends BrowserImport { return 'import.firefox.description'; } - - /** - * {@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} - */ - protected function setEntryAsRead(array $importedEntry) - { - $importedEntry['is_archived'] = 1; - - return $importedEntry; - } } diff --git a/tests/Wallabag/ImportBundle/Controller/ChromeControllerTest.php b/tests/Wallabag/ImportBundle/Controller/ChromeControllerTest.php index 8890c5b1..23c80bec 100644 --- a/tests/Wallabag/ImportBundle/Controller/ChromeControllerTest.php +++ b/tests/Wallabag/ImportBundle/Controller/ChromeControllerTest.php @@ -120,6 +120,10 @@ class ChromeControllerTest extends WallabagCoreTestCase $this->assertNotEmpty($content->getPreviewPicture()); $this->assertNotEmpty($content->getLanguage()); $this->assertEquals(0, count($content->getTags())); + + $createdAt = $content->getCreatedAt(); + $this->assertEquals('2011', $createdAt->format('Y')); + $this->assertEquals('07', $createdAt->format('m')); } public function testImportWallabagWithEmptyFile() diff --git a/tests/Wallabag/ImportBundle/Controller/FirefoxControllerTest.php b/tests/Wallabag/ImportBundle/Controller/FirefoxControllerTest.php index 2de0aa09..10fbc225 100644 --- a/tests/Wallabag/ImportBundle/Controller/FirefoxControllerTest.php +++ b/tests/Wallabag/ImportBundle/Controller/FirefoxControllerTest.php @@ -133,6 +133,10 @@ class FirefoxControllerTest extends WallabagCoreTestCase $this->assertNotEmpty($content->getMimetype()); $this->assertNotEmpty($content->getPreviewPicture()); $this->assertEmpty($content->getLanguage()); + + $createdAt = $content->getCreatedAt(); + $this->assertEquals('2011', $createdAt->format('Y')); + $this->assertEquals('07', $createdAt->format('m')); } public function testImportWallabagWithEmptyFile() -- 2.41.0