aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJeremy Benoist <jeremy.benoist@gmail.com>2016-09-26 07:30:02 +0200
committerJeremy Benoist <jeremy.benoist@gmail.com>2016-09-26 07:30:02 +0200
commit990adfb34c148e7cd28b9cb784cf2b7388caae8f (patch)
treef716810fa5f766bcdfa5af5bb9ba3b568c3517ca
parent12d93e6896f2d99b6329b7979ee7b6d11e457c3a (diff)
downloadwallabag-990adfb34c148e7cd28b9cb784cf2b7388caae8f.tar.gz
wallabag-990adfb34c148e7cd28b9cb784cf2b7388caae8f.tar.zst
wallabag-990adfb34c148e7cd28b9cb784cf2b7388caae8f.zip
Move prepareEntry to dedicated place
Yeah first try was ugly, now each part are in the dedicated place. Also, the date is hardly truncated to 10 chars because Firefox date are 16 chars long and Chrome are 17 chars long. So instead of divised them by a huge number, I prefer to truncate them.
-rw-r--r--src/Wallabag/ImportBundle/Import/BrowserImport.php35
-rw-r--r--src/Wallabag/ImportBundle/Import/ChromeImport.php21
-rw-r--r--src/Wallabag/ImportBundle/Import/FirefoxImport.php21
3 files changed, 42 insertions, 35 deletions
diff --git a/src/Wallabag/ImportBundle/Import/BrowserImport.php b/src/Wallabag/ImportBundle/Import/BrowserImport.php
index 68fa8bf8..e15443c4 100644
--- a/src/Wallabag/ImportBundle/Import/BrowserImport.php
+++ b/src/Wallabag/ImportBundle/Import/BrowserImport.php
@@ -196,41 +196,6 @@ abstract class BrowserImport extends AbstractImport
196 /** 196 /**
197 * {@inheritdoc} 197 * {@inheritdoc}
198 */ 198 */
199 protected function prepareEntry(array $entry = [])
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
215 $data = [
216 'title' => $title,
217 'html' => '',
218 'url' => $url,
219 'is_archived' => $this->markAsRead,
220 'tags' => '',
221 'created_at' => $date,
222 ];
223
224 if (array_key_exists('tags', $entry) && $entry['tags'] != '') {
225 $data['tags'] = $entry['tags'];
226 }
227
228 return $data;
229 }
230
231 /**
232 * {@inheritdoc}
233 */
234 protected function setEntryAsRead(array $importedEntry) 199 protected function setEntryAsRead(array $importedEntry)
235 { 200 {
236 $importedEntry['is_archived'] = 1; 201 $importedEntry['is_archived'] = 1;
diff --git a/src/Wallabag/ImportBundle/Import/ChromeImport.php b/src/Wallabag/ImportBundle/Import/ChromeImport.php
index 60602a1b..d7620bcb 100644
--- a/src/Wallabag/ImportBundle/Import/ChromeImport.php
+++ b/src/Wallabag/ImportBundle/Import/ChromeImport.php
@@ -29,4 +29,25 @@ class ChromeImport extends BrowserImport
29 { 29 {
30 return 'import.chrome.description'; 30 return 'import.chrome.description';
31 } 31 }
32
33 /**
34 * {@inheritdoc}
35 */
36 protected function prepareEntry(array $entry = [])
37 {
38 $data = [
39 'title' => $entry['name'],
40 'html' => '',
41 'url' => $entry['url'],
42 'is_archived' => $this->markAsRead,
43 'tags' => '',
44 'created_at' => substr($entry['date_added'], 0, 10),
45 ];
46
47 if (array_key_exists('tags', $entry) && $entry['tags'] != '') {
48 $data['tags'] = $entry['tags'];
49 }
50
51 return $data;
52 }
32} 53}
diff --git a/src/Wallabag/ImportBundle/Import/FirefoxImport.php b/src/Wallabag/ImportBundle/Import/FirefoxImport.php
index 1a0b1154..e010f5a4 100644
--- a/src/Wallabag/ImportBundle/Import/FirefoxImport.php
+++ b/src/Wallabag/ImportBundle/Import/FirefoxImport.php
@@ -29,4 +29,25 @@ class FirefoxImport extends BrowserImport
29 { 29 {
30 return 'import.firefox.description'; 30 return 'import.firefox.description';
31 } 31 }
32
33 /**
34 * {@inheritdoc}
35 */
36 protected function prepareEntry(array $entry = [])
37 {
38 $data = [
39 'title' => $entry['title'],
40 'html' => '',
41 'url' => $entry['uri'],
42 'is_archived' => $this->markAsRead,
43 'tags' => '',
44 'created_at' => substr($entry['dateAdded'], 0, 10),
45 ];
46
47 if (array_key_exists('tags', $entry) && $entry['tags'] != '') {
48 $data['tags'] = $entry['tags'];
49 }
50
51 return $data;
52 }
32} 53}