diff options
author | Jeremy Benoist <jeremy.benoist@gmail.com> | 2016-09-25 22:24:07 +0200 |
---|---|---|
committer | Jeremy Benoist <jeremy.benoist@gmail.com> | 2016-09-25 22:24:07 +0200 |
commit | 12d93e6896f2d99b6329b7979ee7b6d11e457c3a (patch) | |
tree | 5e67f445a652486259fa3a0d6579d7dea5683a81 | |
parent | 27acc6ddb8b0a1549a3f015171621e3056ef65d2 (diff) | |
download | wallabag-12d93e6896f2d99b6329b7979ee7b6d11e457c3a.tar.gz wallabag-12d93e6896f2d99b6329b7979ee7b6d11e457c3a.tar.zst wallabag-12d93e6896f2d99b6329b7979ee7b6d11e457c3a.zip |
Update Firefox file
With real data, the previous looks more than a Chrome converted file.
Also, fix date conversion (hope so).
4 files changed, 91 insertions, 78 deletions
diff --git a/src/Wallabag/ImportBundle/Import/BrowserImport.php b/src/Wallabag/ImportBundle/Import/BrowserImport.php index da69df9b..68fa8bf8 100644 --- a/src/Wallabag/ImportBundle/Import/BrowserImport.php +++ b/src/Wallabag/ImportBundle/Import/BrowserImport.php | |||
@@ -136,27 +136,27 @@ abstract class BrowserImport extends AbstractImport | |||
136 | */ | 136 | */ |
137 | public function parseEntry(array $importedEntry) | 137 | public function parseEntry(array $importedEntry) |
138 | { | 138 | { |
139 | if ((!key_exists('guid', $importedEntry) || (!key_exists('id', $importedEntry))) && is_array(reset($importedEntry))) { | 139 | if ((!array_key_exists('guid', $importedEntry) || (!array_key_exists('id', $importedEntry))) && is_array(reset($importedEntry))) { |
140 | $this->parseEntries($importedEntry); | 140 | $this->parseEntries($importedEntry); |
141 | 141 | ||
142 | return; | 142 | return; |
143 | } | 143 | } |
144 | 144 | ||
145 | if (key_exists('children', $importedEntry)) { | 145 | if (array_key_exists('children', $importedEntry)) { |
146 | $this->parseEntries($importedEntry['children']); | 146 | $this->parseEntries($importedEntry['children']); |
147 | 147 | ||
148 | return; | 148 | return; |
149 | } | 149 | } |
150 | 150 | ||
151 | if (!key_exists('uri', $importedEntry) && !key_exists('url', $importedEntry)) { | 151 | if (!array_key_exists('uri', $importedEntry) && !array_key_exists('url', $importedEntry)) { |
152 | return; | 152 | return; |
153 | } | 153 | } |
154 | 154 | ||
155 | $firefox = key_exists('uri', $importedEntry); | 155 | $url = array_key_exists('uri', $importedEntry) ? $importedEntry['uri'] : $importedEntry['url']; |
156 | 156 | ||
157 | $existingEntry = $this->em | 157 | $existingEntry = $this->em |
158 | ->getRepository('WallabagCoreBundle:Entry') | 158 | ->getRepository('WallabagCoreBundle:Entry') |
159 | ->findByUrlAndUserId(($firefox) ? $importedEntry['uri'] : $importedEntry['url'], $this->user->getId()); | 159 | ->findByUrlAndUserId($url, $this->user->getId()); |
160 | 160 | ||
161 | if (false !== $existingEntry) { | 161 | if (false !== $existingEntry) { |
162 | ++$this->skippedEntries; | 162 | ++$this->skippedEntries; |
@@ -184,7 +184,7 @@ abstract class BrowserImport extends AbstractImport | |||
184 | 184 | ||
185 | if (!empty($data['created_at'])) { | 185 | if (!empty($data['created_at'])) { |
186 | $dt = new \DateTime(); | 186 | $dt = new \DateTime(); |
187 | $entry->setCreatedAt($dt->setTimestamp($data['created_at'] / 1000)); | 187 | $entry->setCreatedAt($dt->setTimestamp($data['created_at'])); |
188 | } | 188 | } |
189 | 189 | ||
190 | $this->em->persist($entry); | 190 | $this->em->persist($entry); |
@@ -196,17 +196,29 @@ abstract class BrowserImport extends AbstractImport | |||
196 | /** | 196 | /** |
197 | * {@inheritdoc} | 197 | * {@inheritdoc} |
198 | */ | 198 | */ |
199 | protected function prepareEntry($entry = []) | 199 | protected function prepareEntry(array $entry = []) |
200 | { | 200 | { |
201 | $url = array_key_exists('uri', $entry) ? $entry['uri'] : $entry['url']; | ||
202 | $date = array_key_exists('date_added', $entry) ? $entry['date_added'] : $entry['dateAdded']; | ||
203 | $title = array_key_exists('name', $entry) ? $entry['name'] : $entry['title']; | ||
204 | |||
205 | if (16 === strlen($date)) { | ||
206 | // firefox ... | ||
207 | $date = (int) ceil($date / 1000000); | ||
208 | } else if (17 === strlen($date)) { | ||
209 | // chrome ... | ||
210 | $date = (int) ceil($date / 10000000); | ||
211 | } else { | ||
212 | $date = ''; | ||
213 | } | ||
214 | |||
201 | $data = [ | 215 | $data = [ |
202 | 'title' => $entry['name'], | 216 | 'title' => $title, |
203 | 'html' => '', | 217 | 'html' => '', |
204 | 'url' => $entry['url'], | 218 | 'url' => $url, |
205 | 'is_archived' => $this->markAsRead, | 219 | 'is_archived' => $this->markAsRead, |
206 | 'tags' => '', | 220 | 'tags' => '', |
207 | // date are in format like "13118829474385693" | 221 | 'created_at' => $date, |
208 | // and it'll be devided by 1000 in AbstractImport | ||
209 | 'created_at' => (int) ceil($entry['date_added'] / 10000), | ||
210 | ]; | 222 | ]; |
211 | 223 | ||
212 | if (array_key_exists('tags', $entry) && $entry['tags'] != '') { | 224 | if (array_key_exists('tags', $entry) && $entry['tags'] != '') { |
diff --git a/tests/Wallabag/ImportBundle/Controller/FirefoxControllerTest.php b/tests/Wallabag/ImportBundle/Controller/FirefoxControllerTest.php index 10fbc225..dea5b79c 100644 --- a/tests/Wallabag/ImportBundle/Controller/FirefoxControllerTest.php +++ b/tests/Wallabag/ImportBundle/Controller/FirefoxControllerTest.php | |||
@@ -135,8 +135,8 @@ class FirefoxControllerTest extends WallabagCoreTestCase | |||
135 | $this->assertEmpty($content->getLanguage()); | 135 | $this->assertEmpty($content->getLanguage()); |
136 | 136 | ||
137 | $createdAt = $content->getCreatedAt(); | 137 | $createdAt = $content->getCreatedAt(); |
138 | $this->assertEquals('2011', $createdAt->format('Y')); | 138 | $this->assertEquals('2013', $createdAt->format('Y')); |
139 | $this->assertEquals('07', $createdAt->format('m')); | 139 | $this->assertEquals('12', $createdAt->format('m')); |
140 | } | 140 | } |
141 | 141 | ||
142 | public function testImportWallabagWithEmptyFile() | 142 | public function testImportWallabagWithEmptyFile() |
diff --git a/tests/Wallabag/ImportBundle/Import/FirefoxImportTest.php b/tests/Wallabag/ImportBundle/Import/FirefoxImportTest.php index e8f0f3c7..007dda6a 100644 --- a/tests/Wallabag/ImportBundle/Import/FirefoxImportTest.php +++ b/tests/Wallabag/ImportBundle/Import/FirefoxImportTest.php | |||
@@ -61,7 +61,7 @@ class FirefoxImportTest extends \PHPUnit_Framework_TestCase | |||
61 | ->disableOriginalConstructor() | 61 | ->disableOriginalConstructor() |
62 | ->getMock(); | 62 | ->getMock(); |
63 | 63 | ||
64 | $entryRepo->expects($this->exactly(4)) | 64 | $entryRepo->expects($this->exactly(2)) |
65 | ->method('findByUrlAndUserId') | 65 | ->method('findByUrlAndUserId') |
66 | ->willReturn(false); | 66 | ->willReturn(false); |
67 | 67 | ||
@@ -75,14 +75,14 @@ class FirefoxImportTest extends \PHPUnit_Framework_TestCase | |||
75 | ->getMock(); | 75 | ->getMock(); |
76 | 76 | ||
77 | $this->contentProxy | 77 | $this->contentProxy |
78 | ->expects($this->exactly(4)) | 78 | ->expects($this->exactly(2)) |
79 | ->method('updateEntry') | 79 | ->method('updateEntry') |
80 | ->willReturn($entry); | 80 | ->willReturn($entry); |
81 | 81 | ||
82 | $res = $firefoxImport->import(); | 82 | $res = $firefoxImport->import(); |
83 | 83 | ||
84 | $this->assertTrue($res); | 84 | $this->assertTrue($res); |
85 | $this->assertEquals(['skipped' => 0, 'imported' => 4, 'queued' => 0], $firefoxImport->getSummary()); | 85 | $this->assertEquals(['skipped' => 0, 'imported' => 2, 'queued' => 0], $firefoxImport->getSummary()); |
86 | } | 86 | } |
87 | 87 | ||
88 | public function testImportAndMarkAllAsRead() | 88 | public function testImportAndMarkAllAsRead() |
@@ -94,7 +94,7 @@ class FirefoxImportTest extends \PHPUnit_Framework_TestCase | |||
94 | ->disableOriginalConstructor() | 94 | ->disableOriginalConstructor() |
95 | ->getMock(); | 95 | ->getMock(); |
96 | 96 | ||
97 | $entryRepo->expects($this->exactly(4)) | 97 | $entryRepo->expects($this->exactly(2)) |
98 | ->method('findByUrlAndUserId') | 98 | ->method('findByUrlAndUserId') |
99 | ->will($this->onConsecutiveCalls(false, true)); | 99 | ->will($this->onConsecutiveCalls(false, true)); |
100 | 100 | ||
@@ -120,7 +120,7 @@ class FirefoxImportTest extends \PHPUnit_Framework_TestCase | |||
120 | 120 | ||
121 | $this->assertTrue($res); | 121 | $this->assertTrue($res); |
122 | 122 | ||
123 | $this->assertEquals(['skipped' => 3, 'imported' => 1, 'queued' => 0], $firefoxImport->getSummary()); | 123 | $this->assertEquals(['skipped' => 1, 'imported' => 1, 'queued' => 0], $firefoxImport->getSummary()); |
124 | } | 124 | } |
125 | 125 | ||
126 | public function testImportWithRabbit() | 126 | public function testImportWithRabbit() |
diff --git a/tests/Wallabag/ImportBundle/fixtures/firefox-bookmarks.json b/tests/Wallabag/ImportBundle/fixtures/firefox-bookmarks.json index 8b78b8a4..ee06a16c 100644 --- a/tests/Wallabag/ImportBundle/fixtures/firefox-bookmarks.json +++ b/tests/Wallabag/ImportBundle/fixtures/firefox-bookmarks.json | |||
@@ -1,61 +1,62 @@ | |||
1 | { | 1 | { |
2 | "checksum": "ef1e30cddf64cb94c63d7835640165be", | 2 | "guid": "root________", |
3 | "roots": { | 3 | "title": "", |
4 | "bookmark_bar": { | 4 | "index": 0, |
5 | "children": [ { | 5 | "dateAdded": 1388166091504000, |
6 | "date_added": "13112787540531997", | 6 | "lastModified": 1472897622350000, |
7 | "id": "7", | 7 | "id": 1, |
8 | "name": "Terrorisme: les sombres prédictions du directeur de la DGSI", | 8 | "type": "text/x-moz-place-container", |
9 | "type": "url", | 9 | "root": "placesRoot", |
10 | "url": "http://www.lefigaro.fr/actualite-france/2016/07/12/01016-20160712ARTFIG00016-terrorisme-les-sombres-perspectives-de-patrick-calvar-directeur-de-la-dgsi.php" | 10 | "children": [ |
11 | } ], | 11 | { |
12 | "date_added": "13112787380480144", | 12 | "guid": "toolbar_____", |
13 | "date_modified": "13112787542724942", | 13 | "title": "Barre personnelle", |
14 | "id": "1", | 14 | "index": 1, |
15 | "name": "Bookmarks bar", | 15 | "dateAdded": 1388166091504000, |
16 | "type": "folder" | 16 | "lastModified": 1472897622263000, |
17 | }, | 17 | "id": 3, |
18 | "other": { | 18 | "annos": [ |
19 | "children": [ { | 19 | { |
20 | "date_added": "13112787503900822", | 20 | "name": "bookmarkProperties/description", |
21 | "id": "6", | 21 | "flags": 0, |
22 | "name": "Parser for Exported Bookmarks HTML file of Google Chrome and Mozilla in Java - Stack Overflow", | 22 | "expires": 4, |
23 | "type": "url", | 23 | "value": "Ajoutez des marque-pages dans ce dossier pour les voir apparaître sur votre barre personnelle" |
24 | "url": "http://stackoverflow.com/questions/15017163/parser-for-exported-bookmarks-html-file-of-google-chrome-and-mozilla-in-java" | 24 | } |
25 | }, { | 25 | ], |
26 | "children": [ { | 26 | "type": "text/x-moz-place-container", |
27 | "date_added": "13112787564443378", | 27 | "root": "toolbarFolder", |
28 | "id": "9", | 28 | "children": [ |
29 | "name": "Orange offre un meilleur réseau mobile que Bouygues et SFR, Free derrière - L'Express L'Expansion", | 29 | { |
30 | "type": "url", | 30 | "guid": "tard77lzbC5H", |
31 | "url": "http://lexpansion.lexpress.fr/high-tech/orange-offre-un-meilleur-reseau-mobile-que-bouygues-et-sfr-free-derriere_1811554.html" | 31 | "title": "Orange offre un meilleur réseau mobile que Bouygues et SFR, Free derrière - L'Express L'Expansion", |
32 | } ], | 32 | "index": 1, |
33 | "date_added": "13112787556763735", | 33 | "dateAdded": 1388166091644000, |
34 | "date_modified": "13112794390493325", | 34 | "lastModified": 1388166091644000, |
35 | "id": "8", | 35 | "id": 4, |
36 | "name": "test", | 36 | "type": "text/x-moz-place", |
37 | "type": "folder" | 37 | "uri": "http://lexpansion.lexpress.fr/high-tech/orange-offre-un-meilleur-reseau-mobile-que-bouygues-et-sfr-free-derriere_1811554.html" |
38 | }, { | 38 | }, |
39 | "date_added": "13112794390493325", | 39 | { |
40 | "id": "12", | 40 | "guid": "E385l9vZ_LVn", |
41 | "name": "JSON Formatter & Validator", | 41 | "title": "Parser for Exported Bookmarks HTML file of Google Chrome and Mozilla in Java", |
42 | "type": "url", | 42 | "index": 1, |
43 | "url": "https://jsonformatter.curiousconcept.com/" | 43 | "dateAdded": 1388166091544000, |
44 | } ], | 44 | "lastModified": 1388166091545000, |
45 | "date_added": "13112787380480151", | 45 | "id": 5, |
46 | "date_modified": "13112794393509988", | 46 | "type": "text/x-moz-place", |
47 | "id": "2", | 47 | "uri": "http://stackoverflow.com/questions/15017163/parser-for-exported-bookmarks-html-file-of-google-chrome-and-mozilla-in-java" |
48 | "name": "Other bookmarks", | 48 | } |
49 | "type": "folder" | 49 | ] |
50 | }, | 50 | }, |
51 | "synced": { | 51 | { |
52 | "children": [ ], | 52 | "guid": "unfiled_____", |
53 | "date_added": "13112787380480155", | 53 | "title": "Autres marque-pages", |
54 | "date_modified": "0", | 54 | "index": 3, |
55 | "id": "3", | 55 | "dateAdded": 1388166091504000, |
56 | "name": "Mobile bookmarks", | 56 | "lastModified": 1388166091542000, |
57 | "type": "folder" | 57 | "id": 6, |
58 | } | 58 | "type": "text/x-moz-place-container", |
59 | }, | 59 | "root": "unfiledBookmarksFolder" |
60 | "version": 1 | 60 | } |
61 | ] | ||
61 | } | 62 | } |