aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorJeremy Benoist <jeremy.benoist@gmail.com>2016-09-25 22:24:07 +0200
committerJeremy Benoist <jeremy.benoist@gmail.com>2016-09-25 22:24:07 +0200
commit12d93e6896f2d99b6329b7979ee7b6d11e457c3a (patch)
tree5e67f445a652486259fa3a0d6579d7dea5683a81 /src
parent27acc6ddb8b0a1549a3f015171621e3056ef65d2 (diff)
downloadwallabag-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).
Diffstat (limited to 'src')
-rw-r--r--src/Wallabag/ImportBundle/Import/BrowserImport.php36
1 files changed, 24 insertions, 12 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'] != '') {