aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/ImportBundle/Import
diff options
context:
space:
mode:
Diffstat (limited to 'src/Wallabag/ImportBundle/Import')
-rw-r--r--src/Wallabag/ImportBundle/Import/AbstractImport.php79
-rw-r--r--src/Wallabag/ImportBundle/Import/BrowserImport.php152
-rw-r--r--src/Wallabag/ImportBundle/Import/ChromeImport.php2
-rw-r--r--src/Wallabag/ImportBundle/Import/FirefoxImport.php2
-rw-r--r--src/Wallabag/ImportBundle/Import/ImportCompilerPass.php2
-rw-r--r--src/Wallabag/ImportBundle/Import/InstapaperImport.php19
-rw-r--r--src/Wallabag/ImportBundle/Import/PinboardImport.php4
-rw-r--r--src/Wallabag/ImportBundle/Import/PocketImport.php18
-rw-r--r--src/Wallabag/ImportBundle/Import/ReadabilityImport.php2
-rw-r--r--src/Wallabag/ImportBundle/Import/WallabagImport.php4
-rw-r--r--src/Wallabag/ImportBundle/Import/WallabagV1Import.php22
-rw-r--r--src/Wallabag/ImportBundle/Import/WallabagV2Import.php4
12 files changed, 177 insertions, 133 deletions
diff --git a/src/Wallabag/ImportBundle/Import/AbstractImport.php b/src/Wallabag/ImportBundle/Import/AbstractImport.php
index 1d4a6e27..cb46db09 100644
--- a/src/Wallabag/ImportBundle/Import/AbstractImport.php
+++ b/src/Wallabag/ImportBundle/Import/AbstractImport.php
@@ -2,35 +2,39 @@
2 2
3namespace Wallabag\ImportBundle\Import; 3namespace Wallabag\ImportBundle\Import;
4 4
5use Doctrine\ORM\EntityManager;
6use OldSound\RabbitMqBundle\RabbitMq\ProducerInterface;
5use Psr\Log\LoggerInterface; 7use Psr\Log\LoggerInterface;
6use Psr\Log\NullLogger; 8use Psr\Log\NullLogger;
7use Doctrine\ORM\EntityManager; 9use Symfony\Component\EventDispatcher\EventDispatcherInterface;
8use Wallabag\CoreBundle\Helper\ContentProxy;
9use Wallabag\CoreBundle\Entity\Entry; 10use Wallabag\CoreBundle\Entity\Entry;
10use Wallabag\CoreBundle\Entity\Tag; 11use Wallabag\CoreBundle\Entity\Tag;
11use Wallabag\UserBundle\Entity\User;
12use OldSound\RabbitMqBundle\RabbitMq\ProducerInterface;
13use Symfony\Component\EventDispatcher\EventDispatcherInterface;
14use Wallabag\CoreBundle\Event\EntrySavedEvent; 12use Wallabag\CoreBundle\Event\EntrySavedEvent;
13use Wallabag\CoreBundle\Helper\ContentProxy;
14use Wallabag\CoreBundle\Helper\TagsAssigner;
15use Wallabag\UserBundle\Entity\User;
15 16
16abstract class AbstractImport implements ImportInterface 17abstract class AbstractImport implements ImportInterface
17{ 18{
18 protected $em; 19 protected $em;
19 protected $logger; 20 protected $logger;
20 protected $contentProxy; 21 protected $contentProxy;
22 protected $tagsAssigner;
21 protected $eventDispatcher; 23 protected $eventDispatcher;
22 protected $producer; 24 protected $producer;
23 protected $user; 25 protected $user;
24 protected $markAsRead; 26 protected $markAsRead;
27 protected $disableContentUpdate = false;
25 protected $skippedEntries = 0; 28 protected $skippedEntries = 0;
26 protected $importedEntries = 0; 29 protected $importedEntries = 0;
27 protected $queuedEntries = 0; 30 protected $queuedEntries = 0;
28 31
29 public function __construct(EntityManager $em, ContentProxy $contentProxy, EventDispatcherInterface $eventDispatcher) 32 public function __construct(EntityManager $em, ContentProxy $contentProxy, TagsAssigner $tagsAssigner, EventDispatcherInterface $eventDispatcher)
30 { 33 {
31 $this->em = $em; 34 $this->em = $em;
32 $this->logger = new NullLogger(); 35 $this->logger = new NullLogger();
33 $this->contentProxy = $contentProxy; 36 $this->contentProxy = $contentProxy;
37 $this->tagsAssigner = $tagsAssigner;
34 $this->eventDispatcher = $eventDispatcher; 38 $this->eventDispatcher = $eventDispatcher;
35 } 39 }
36 40
@@ -82,21 +86,55 @@ abstract class AbstractImport implements ImportInterface
82 } 86 }
83 87
84 /** 88 /**
89 * Set whether articles should be fetched for updated content.
90 *
91 * @param bool $disableContentUpdate
92 */
93 public function setDisableContentUpdate($disableContentUpdate)
94 {
95 $this->disableContentUpdate = $disableContentUpdate;
96
97 return $this;
98 }
99
100 /**
101 * {@inheritdoc}
102 */
103 public function getSummary()
104 {
105 return [
106 'skipped' => $this->skippedEntries,
107 'imported' => $this->importedEntries,
108 'queued' => $this->queuedEntries,
109 ];
110 }
111
112 /**
113 * Parse one entry.
114 *
115 * @param array $importedEntry
116 *
117 * @return Entry
118 */
119 abstract public function parseEntry(array $importedEntry);
120
121 /**
85 * Fetch content from the ContentProxy (using graby). 122 * Fetch content from the ContentProxy (using graby).
86 * If it fails return the given entry to be saved in all case (to avoid user to loose the content). 123 * If it fails return the given entry to be saved in all case (to avoid user to loose the content).
87 * 124 *
88 * @param Entry $entry Entry to update 125 * @param Entry $entry Entry to update
89 * @param string $url Url to grab content for 126 * @param string $url Url to grab content for
90 * @param array $content An array with AT LEAST keys title, html, url, language & content_type to skip the fetchContent from the url 127 * @param array $content An array with AT LEAST keys title, html, url, language & content_type to skip the fetchContent from the url
91 *
92 * @return Entry
93 */ 128 */
94 protected function fetchContent(Entry $entry, $url, array $content = []) 129 protected function fetchContent(Entry $entry, $url, array $content = [])
95 { 130 {
96 try { 131 try {
97 return $this->contentProxy->updateEntry($entry, $url, $content); 132 $this->contentProxy->updateEntry($entry, $url, $content, $this->disableContentUpdate);
98 } catch (\Exception $e) { 133 } catch (\Exception $e) {
99 return $entry; 134 $this->logger->error('Error trying to import an entry.', [
135 'entry_url' => $url,
136 'error_msg' => $e->getMessage(),
137 ]);
100 } 138 }
101 } 139 }
102 140
@@ -179,27 +217,6 @@ abstract class AbstractImport implements ImportInterface
179 } 217 }
180 218
181 /** 219 /**
182 * {@inheritdoc}
183 */
184 public function getSummary()
185 {
186 return [
187 'skipped' => $this->skippedEntries,
188 'imported' => $this->importedEntries,
189 'queued' => $this->queuedEntries,
190 ];
191 }
192
193 /**
194 * Parse one entry.
195 *
196 * @param array $importedEntry
197 *
198 * @return Entry
199 */
200 abstract public function parseEntry(array $importedEntry);
201
202 /**
203 * Set current imported entry to archived / read. 220 * Set current imported entry to archived / read.
204 * Implementation is different accross all imports. 221 * Implementation is different accross all imports.
205 * 222 *
diff --git a/src/Wallabag/ImportBundle/Import/BrowserImport.php b/src/Wallabag/ImportBundle/Import/BrowserImport.php
index 8bf7d92e..78077324 100644
--- a/src/Wallabag/ImportBundle/Import/BrowserImport.php
+++ b/src/Wallabag/ImportBundle/Import/BrowserImport.php
@@ -3,8 +3,6 @@
3namespace Wallabag\ImportBundle\Import; 3namespace Wallabag\ImportBundle\Import;
4 4
5use Wallabag\CoreBundle\Entity\Entry; 5use Wallabag\CoreBundle\Entity\Entry;
6use Wallabag\UserBundle\Entity\User;
7use Wallabag\CoreBundle\Helper\ContentProxy;
8use Wallabag\CoreBundle\Event\EntrySavedEvent; 6use Wallabag\CoreBundle\Event\EntrySavedEvent;
9 7
10abstract class BrowserImport extends AbstractImport 8abstract class BrowserImport extends AbstractImport
@@ -75,6 +73,80 @@ abstract class BrowserImport extends AbstractImport
75 } 73 }
76 74
77 /** 75 /**
76 * {@inheritdoc}
77 */
78 public function parseEntry(array $importedEntry)
79 {
80 if ((!array_key_exists('guid', $importedEntry) || (!array_key_exists('id', $importedEntry))) && is_array(reset($importedEntry))) {
81 if ($this->producer) {
82 $this->parseEntriesForProducer($importedEntry);
83
84 return;
85 }
86
87 $this->parseEntries($importedEntry);
88
89 return;
90 }
91
92 if (array_key_exists('children', $importedEntry)) {
93 if ($this->producer) {
94 $this->parseEntriesForProducer($importedEntry['children']);
95
96 return;
97 }
98
99 $this->parseEntries($importedEntry['children']);
100
101 return;
102 }
103
104 if (!array_key_exists('uri', $importedEntry) && !array_key_exists('url', $importedEntry)) {
105 return;
106 }
107
108 $url = array_key_exists('uri', $importedEntry) ? $importedEntry['uri'] : $importedEntry['url'];
109
110 $existingEntry = $this->em
111 ->getRepository('WallabagCoreBundle:Entry')
112 ->findByUrlAndUserId($url, $this->user->getId());
113
114 if (false !== $existingEntry) {
115 ++$this->skippedEntries;
116
117 return;
118 }
119
120 $data = $this->prepareEntry($importedEntry);
121
122 $entry = new Entry($this->user);
123 $entry->setUrl($data['url']);
124 $entry->setTitle($data['title']);
125
126 // update entry with content (in case fetching failed, the given entry will be return)
127 $this->fetchContent($entry, $data['url'], $data);
128
129 if (array_key_exists('tags', $data)) {
130 $this->tagsAssigner->assignTagsToEntry(
131 $entry,
132 $data['tags']
133 );
134 }
135
136 $entry->setArchived($data['is_archived']);
137
138 if (!empty($data['created_at'])) {
139 $dt = new \DateTime();
140 $entry->setCreatedAt($dt->setTimestamp($data['created_at']));
141 }
142
143 $this->em->persist($entry);
144 ++$this->importedEntries;
145
146 return $entry;
147 }
148
149 /**
78 * Parse and insert all given entries. 150 * Parse and insert all given entries.
79 * 151 *
80 * @param $entries 152 * @param $entries
@@ -153,84 +225,12 @@ abstract class BrowserImport extends AbstractImport
153 /** 225 /**
154 * {@inheritdoc} 226 * {@inheritdoc}
155 */ 227 */
156 public function parseEntry(array $importedEntry)
157 {
158 if ((!array_key_exists('guid', $importedEntry) || (!array_key_exists('id', $importedEntry))) && is_array(reset($importedEntry))) {
159 if ($this->producer) {
160 $this->parseEntriesForProducer($importedEntry);
161
162 return;
163 }
164
165 $this->parseEntries($importedEntry);
166
167 return;
168 }
169
170 if (array_key_exists('children', $importedEntry)) {
171 if ($this->producer) {
172 $this->parseEntriesForProducer($importedEntry['children']);
173
174 return;
175 }
176
177 $this->parseEntries($importedEntry['children']);
178
179 return;
180 }
181
182 if (!array_key_exists('uri', $importedEntry) && !array_key_exists('url', $importedEntry)) {
183 return;
184 }
185
186 $url = array_key_exists('uri', $importedEntry) ? $importedEntry['uri'] : $importedEntry['url'];
187
188 $existingEntry = $this->em
189 ->getRepository('WallabagCoreBundle:Entry')
190 ->findByUrlAndUserId($url, $this->user->getId());
191
192 if (false !== $existingEntry) {
193 ++$this->skippedEntries;
194
195 return;
196 }
197
198 $data = $this->prepareEntry($importedEntry);
199
200 $entry = new Entry($this->user);
201 $entry->setUrl($data['url']);
202 $entry->setTitle($data['title']);
203
204 // update entry with content (in case fetching failed, the given entry will be return)
205 $entry = $this->fetchContent($entry, $data['url'], $data);
206
207 if (array_key_exists('tags', $data)) {
208 $this->contentProxy->assignTagsToEntry(
209 $entry,
210 $data['tags']
211 );
212 }
213
214 $entry->setArchived($data['is_archived']);
215
216 if (!empty($data['created_at'])) {
217 $dt = new \DateTime();
218 $entry->setCreatedAt($dt->setTimestamp($data['created_at']));
219 }
220
221 $this->em->persist($entry);
222 ++$this->importedEntries;
223
224 return $entry;
225 }
226
227 /**
228 * {@inheritdoc}
229 */
230 protected function setEntryAsRead(array $importedEntry) 228 protected function setEntryAsRead(array $importedEntry)
231 { 229 {
232 $importedEntry['is_archived'] = 1; 230 $importedEntry['is_archived'] = 1;
233 231
234 return $importedEntry; 232 return $importedEntry;
235 } 233 }
234
235 abstract protected function prepareEntry(array $entry = []);
236} 236}
diff --git a/src/Wallabag/ImportBundle/Import/ChromeImport.php b/src/Wallabag/ImportBundle/Import/ChromeImport.php
index 2667890f..e3ba636a 100644
--- a/src/Wallabag/ImportBundle/Import/ChromeImport.php
+++ b/src/Wallabag/ImportBundle/Import/ChromeImport.php
@@ -45,7 +45,7 @@ class ChromeImport extends BrowserImport
45 'created_at' => substr($entry['date_added'], 0, 10), 45 'created_at' => substr($entry['date_added'], 0, 10),
46 ]; 46 ];
47 47
48 if (array_key_exists('tags', $entry) && $entry['tags'] != '') { 48 if (array_key_exists('tags', $entry) && $entry['tags'] !== '') {
49 $data['tags'] = $entry['tags']; 49 $data['tags'] = $entry['tags'];
50 } 50 }
51 51
diff --git a/src/Wallabag/ImportBundle/Import/FirefoxImport.php b/src/Wallabag/ImportBundle/Import/FirefoxImport.php
index c50c69b3..c18e7e93 100644
--- a/src/Wallabag/ImportBundle/Import/FirefoxImport.php
+++ b/src/Wallabag/ImportBundle/Import/FirefoxImport.php
@@ -45,7 +45,7 @@ class FirefoxImport extends BrowserImport
45 'created_at' => substr($entry['dateAdded'], 0, 10), 45 'created_at' => substr($entry['dateAdded'], 0, 10),
46 ]; 46 ];
47 47
48 if (array_key_exists('tags', $entry) && $entry['tags'] != '') { 48 if (array_key_exists('tags', $entry) && $entry['tags'] !== '') {
49 $data['tags'] = $entry['tags']; 49 $data['tags'] = $entry['tags'];
50 } 50 }
51 51
diff --git a/src/Wallabag/ImportBundle/Import/ImportCompilerPass.php b/src/Wallabag/ImportBundle/Import/ImportCompilerPass.php
index a363a566..d7df0a83 100644
--- a/src/Wallabag/ImportBundle/Import/ImportCompilerPass.php
+++ b/src/Wallabag/ImportBundle/Import/ImportCompilerPass.php
@@ -2,8 +2,8 @@
2 2
3namespace Wallabag\ImportBundle\Import; 3namespace Wallabag\ImportBundle\Import;
4 4
5use Symfony\Component\DependencyInjection\ContainerBuilder;
6use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; 5use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
6use Symfony\Component\DependencyInjection\ContainerBuilder;
7use Symfony\Component\DependencyInjection\Reference; 7use Symfony\Component\DependencyInjection\Reference;
8 8
9class ImportCompilerPass implements CompilerPassInterface 9class ImportCompilerPass implements CompilerPassInterface
diff --git a/src/Wallabag/ImportBundle/Import/InstapaperImport.php b/src/Wallabag/ImportBundle/Import/InstapaperImport.php
index 70a53f1a..7d70154a 100644
--- a/src/Wallabag/ImportBundle/Import/InstapaperImport.php
+++ b/src/Wallabag/ImportBundle/Import/InstapaperImport.php
@@ -68,6 +68,14 @@ class InstapaperImport extends AbstractImport
68 continue; 68 continue;
69 } 69 }
70 70
71 // last element in the csv is the folder where the content belong
72 // BUT it can also be the status (since status = folder in Instapaper)
73 // and we don't want archive, unread & starred to become a tag
74 $tags = null;
75 if (false === in_array($data[3], ['Archive', 'Unread', 'Starred'], true)) {
76 $tags = [$data[3]];
77 }
78
71 $entries[] = [ 79 $entries[] = [
72 'url' => $data[0], 80 'url' => $data[0],
73 'title' => $data[1], 81 'title' => $data[1],
@@ -75,6 +83,7 @@ class InstapaperImport extends AbstractImport
75 'is_archived' => $data[3] === 'Archive' || $data[3] === 'Starred', 83 'is_archived' => $data[3] === 'Archive' || $data[3] === 'Starred',
76 'is_starred' => $data[3] === 'Starred', 84 'is_starred' => $data[3] === 'Starred',
77 'html' => false, 85 'html' => false,
86 'tags' => $tags,
78 ]; 87 ];
79 } 88 }
80 fclose($handle); 89 fclose($handle);
@@ -116,7 +125,15 @@ class InstapaperImport extends AbstractImport
116 $entry->setTitle($importedEntry['title']); 125 $entry->setTitle($importedEntry['title']);
117 126
118 // update entry with content (in case fetching failed, the given entry will be return) 127 // update entry with content (in case fetching failed, the given entry will be return)
119 $entry = $this->fetchContent($entry, $importedEntry['url'], $importedEntry); 128 $this->fetchContent($entry, $importedEntry['url'], $importedEntry);
129
130 if (!empty($importedEntry['tags'])) {
131 $this->tagsAssigner->assignTagsToEntry(
132 $entry,
133 $importedEntry['tags'],
134 $this->em->getUnitOfWork()->getScheduledEntityInsertions()
135 );
136 }
120 137
121 $entry->setArchived($importedEntry['is_archived']); 138 $entry->setArchived($importedEntry['is_archived']);
122 $entry->setStarred($importedEntry['is_starred']); 139 $entry->setStarred($importedEntry['is_starred']);
diff --git a/src/Wallabag/ImportBundle/Import/PinboardImport.php b/src/Wallabag/ImportBundle/Import/PinboardImport.php
index d9865534..110b0464 100644
--- a/src/Wallabag/ImportBundle/Import/PinboardImport.php
+++ b/src/Wallabag/ImportBundle/Import/PinboardImport.php
@@ -109,10 +109,10 @@ class PinboardImport extends AbstractImport
109 $entry->setTitle($data['title']); 109 $entry->setTitle($data['title']);
110 110
111 // update entry with content (in case fetching failed, the given entry will be return) 111 // update entry with content (in case fetching failed, the given entry will be return)
112 $entry = $this->fetchContent($entry, $data['url'], $data); 112 $this->fetchContent($entry, $data['url'], $data);
113 113
114 if (!empty($data['tags'])) { 114 if (!empty($data['tags'])) {
115 $this->contentProxy->assignTagsToEntry( 115 $this->tagsAssigner->assignTagsToEntry(
116 $entry, 116 $entry,
117 $data['tags'], 117 $data['tags'],
118 $this->em->getUnitOfWork()->getScheduledEntityInsertions() 118 $this->em->getUnitOfWork()->getScheduledEntityInsertions()
diff --git a/src/Wallabag/ImportBundle/Import/PocketImport.php b/src/Wallabag/ImportBundle/Import/PocketImport.php
index 33093480..7d38826b 100644
--- a/src/Wallabag/ImportBundle/Import/PocketImport.php
+++ b/src/Wallabag/ImportBundle/Import/PocketImport.php
@@ -5,15 +5,13 @@ namespace Wallabag\ImportBundle\Import;
5use GuzzleHttp\Client; 5use GuzzleHttp\Client;
6use GuzzleHttp\Exception\RequestException; 6use GuzzleHttp\Exception\RequestException;
7use Wallabag\CoreBundle\Entity\Entry; 7use Wallabag\CoreBundle\Entity\Entry;
8use Wallabag\CoreBundle\Helper\ContentProxy;
9 8
10class PocketImport extends AbstractImport 9class PocketImport extends AbstractImport
11{ 10{
11 const NB_ELEMENTS = 5000;
12 private $client; 12 private $client;
13 private $accessToken; 13 private $accessToken;
14 14
15 const NB_ELEMENTS = 5000;
16
17 /** 15 /**
18 * Only used for test purpose. 16 * Only used for test purpose.
19 * 17 *
@@ -177,7 +175,7 @@ class PocketImport extends AbstractImport
177 */ 175 */
178 public function parseEntry(array $importedEntry) 176 public function parseEntry(array $importedEntry)
179 { 177 {
180 $url = isset($importedEntry['resolved_url']) && $importedEntry['resolved_url'] != '' ? $importedEntry['resolved_url'] : $importedEntry['given_url']; 178 $url = isset($importedEntry['resolved_url']) && $importedEntry['resolved_url'] !== '' ? $importedEntry['resolved_url'] : $importedEntry['given_url'];
181 179
182 $existingEntry = $this->em 180 $existingEntry = $this->em
183 ->getRepository('WallabagCoreBundle:Entry') 181 ->getRepository('WallabagCoreBundle:Entry')
@@ -193,18 +191,18 @@ class PocketImport extends AbstractImport
193 $entry->setUrl($url); 191 $entry->setUrl($url);
194 192
195 // update entry with content (in case fetching failed, the given entry will be return) 193 // update entry with content (in case fetching failed, the given entry will be return)
196 $entry = $this->fetchContent($entry, $url); 194 $this->fetchContent($entry, $url);
197 195
198 // 0, 1, 2 - 1 if the item is archived - 2 if the item should be deleted 196 // 0, 1, 2 - 1 if the item is archived - 2 if the item should be deleted
199 $entry->setArchived($importedEntry['status'] == 1 || $this->markAsRead); 197 $entry->setArchived($importedEntry['status'] === 1 || $this->markAsRead);
200 198
201 // 0 or 1 - 1 If the item is starred 199 // 0 or 1 - 1 If the item is starred
202 $entry->setStarred($importedEntry['favorite'] == 1); 200 $entry->setStarred($importedEntry['favorite'] === 1);
203 201
204 $title = 'Untitled'; 202 $title = 'Untitled';
205 if (isset($importedEntry['resolved_title']) && $importedEntry['resolved_title'] != '') { 203 if (isset($importedEntry['resolved_title']) && $importedEntry['resolved_title'] !== '') {
206 $title = $importedEntry['resolved_title']; 204 $title = $importedEntry['resolved_title'];
207 } elseif (isset($importedEntry['given_title']) && $importedEntry['given_title'] != '') { 205 } elseif (isset($importedEntry['given_title']) && $importedEntry['given_title'] !== '') {
208 $title = $importedEntry['given_title']; 206 $title = $importedEntry['given_title'];
209 } 207 }
210 208
@@ -216,7 +214,7 @@ class PocketImport extends AbstractImport
216 } 214 }
217 215
218 if (isset($importedEntry['tags']) && !empty($importedEntry['tags'])) { 216 if (isset($importedEntry['tags']) && !empty($importedEntry['tags'])) {
219 $this->contentProxy->assignTagsToEntry( 217 $this->tagsAssigner->assignTagsToEntry(
220 $entry, 218 $entry,
221 array_keys($importedEntry['tags']), 219 array_keys($importedEntry['tags']),
222 $this->em->getUnitOfWork()->getScheduledEntityInsertions() 220 $this->em->getUnitOfWork()->getScheduledEntityInsertions()
diff --git a/src/Wallabag/ImportBundle/Import/ReadabilityImport.php b/src/Wallabag/ImportBundle/Import/ReadabilityImport.php
index de320d23..002b27f4 100644
--- a/src/Wallabag/ImportBundle/Import/ReadabilityImport.php
+++ b/src/Wallabag/ImportBundle/Import/ReadabilityImport.php
@@ -109,7 +109,7 @@ class ReadabilityImport extends AbstractImport
109 $entry->setTitle($data['title']); 109 $entry->setTitle($data['title']);
110 110
111 // update entry with content (in case fetching failed, the given entry will be return) 111 // update entry with content (in case fetching failed, the given entry will be return)
112 $entry = $this->fetchContent($entry, $data['url'], $data); 112 $this->fetchContent($entry, $data['url'], $data);
113 113
114 $entry->setArchived($data['is_archived']); 114 $entry->setArchived($data['is_archived']);
115 $entry->setStarred($data['is_starred']); 115 $entry->setStarred($data['is_starred']);
diff --git a/src/Wallabag/ImportBundle/Import/WallabagImport.php b/src/Wallabag/ImportBundle/Import/WallabagImport.php
index 702da057..c64ccd64 100644
--- a/src/Wallabag/ImportBundle/Import/WallabagImport.php
+++ b/src/Wallabag/ImportBundle/Import/WallabagImport.php
@@ -108,10 +108,10 @@ abstract class WallabagImport extends AbstractImport
108 $entry->setTitle($data['title']); 108 $entry->setTitle($data['title']);
109 109
110 // update entry with content (in case fetching failed, the given entry will be return) 110 // update entry with content (in case fetching failed, the given entry will be return)
111 $entry = $this->fetchContent($entry, $data['url'], $data); 111 $this->fetchContent($entry, $data['url'], $data);
112 112
113 if (array_key_exists('tags', $data)) { 113 if (array_key_exists('tags', $data)) {
114 $this->contentProxy->assignTagsToEntry( 114 $this->tagsAssigner->assignTagsToEntry(
115 $entry, 115 $entry,
116 $data['tags'], 116 $data['tags'],
117 $this->em->getUnitOfWork()->getScheduledEntityInsertions() 117 $this->em->getUnitOfWork()->getScheduledEntityInsertions()
diff --git a/src/Wallabag/ImportBundle/Import/WallabagV1Import.php b/src/Wallabag/ImportBundle/Import/WallabagV1Import.php
index 59e3ce02..d585d44d 100644
--- a/src/Wallabag/ImportBundle/Import/WallabagV1Import.php
+++ b/src/Wallabag/ImportBundle/Import/WallabagV1Import.php
@@ -4,6 +4,17 @@ namespace Wallabag\ImportBundle\Import;
4 4
5class WallabagV1Import extends WallabagImport 5class WallabagV1Import extends WallabagImport
6{ 6{
7 protected $fetchingErrorMessage;
8 protected $fetchingErrorMessageTitle;
9
10 public function __construct($em, $contentProxy, $tagsAssigner, $eventDispatcher, $fetchingErrorMessageTitle, $fetchingErrorMessage)
11 {
12 $this->fetchingErrorMessageTitle = $fetchingErrorMessageTitle;
13 $this->fetchingErrorMessage = $fetchingErrorMessage;
14
15 parent::__construct($em, $contentProxy, $tagsAssigner, $eventDispatcher);
16 }
17
7 /** 18 /**
8 * {@inheritdoc} 19 * {@inheritdoc}
9 */ 20 */
@@ -43,13 +54,14 @@ class WallabagV1Import extends WallabagImport
43 'created_at' => '', 54 'created_at' => '',
44 ]; 55 ];
45 56
46 // force content to be refreshed in case on bad fetch in the v1 installation 57 // In case of a bad fetch in v1, replace title and content with v2 error strings
47 if (in_array($entry['title'], $this->untitled)) { 58 // If fetching fails again, they will get this instead of the v1 strings
48 $data['title'] = ''; 59 if (in_array($entry['title'], $this->untitled, true)) {
49 $data['html'] = ''; 60 $data['title'] = $this->fetchingErrorMessageTitle;
61 $data['html'] = $this->fetchingErrorMessage;
50 } 62 }
51 63
52 if (array_key_exists('tags', $entry) && $entry['tags'] != '') { 64 if (array_key_exists('tags', $entry) && $entry['tags'] !== '') {
53 $data['tags'] = $entry['tags']; 65 $data['tags'] = $entry['tags'];
54 } 66 }
55 67
diff --git a/src/Wallabag/ImportBundle/Import/WallabagV2Import.php b/src/Wallabag/ImportBundle/Import/WallabagV2Import.php
index d2a89d79..3e085ecf 100644
--- a/src/Wallabag/ImportBundle/Import/WallabagV2Import.php
+++ b/src/Wallabag/ImportBundle/Import/WallabagV2Import.php
@@ -36,8 +36,8 @@ class WallabagV2Import extends WallabagImport
36 return [ 36 return [
37 'html' => $entry['content'], 37 'html' => $entry['content'],
38 'content_type' => $entry['mimetype'], 38 'content_type' => $entry['mimetype'],
39 'is_archived' => (int) ($entry['is_archived'] || $this->markAsRead), 39 'is_archived' => (bool) ($entry['is_archived'] || $this->markAsRead),
40 'is_starred' => false, 40 'is_starred' => (bool) $entry['is_starred'],
41 ] + $entry; 41 ] + $entry;
42 } 42 }
43 43