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.php27
-rw-r--r--src/Wallabag/ImportBundle/Import/BrowserImport.php5
-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.php5
-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.php18
-rw-r--r--src/Wallabag/ImportBundle/Import/WallabagV2Import.php4
9 files changed, 66 insertions, 22 deletions
diff --git a/src/Wallabag/ImportBundle/Import/AbstractImport.php b/src/Wallabag/ImportBundle/Import/AbstractImport.php
index 1d4a6e27..9b624296 100644
--- a/src/Wallabag/ImportBundle/Import/AbstractImport.php
+++ b/src/Wallabag/ImportBundle/Import/AbstractImport.php
@@ -8,6 +8,7 @@ use Doctrine\ORM\EntityManager;
8use Wallabag\CoreBundle\Helper\ContentProxy; 8use Wallabag\CoreBundle\Helper\ContentProxy;
9use Wallabag\CoreBundle\Entity\Entry; 9use Wallabag\CoreBundle\Entity\Entry;
10use Wallabag\CoreBundle\Entity\Tag; 10use Wallabag\CoreBundle\Entity\Tag;
11use Wallabag\CoreBundle\Helper\TagsAssigner;
11use Wallabag\UserBundle\Entity\User; 12use Wallabag\UserBundle\Entity\User;
12use OldSound\RabbitMqBundle\RabbitMq\ProducerInterface; 13use OldSound\RabbitMqBundle\RabbitMq\ProducerInterface;
13use Symfony\Component\EventDispatcher\EventDispatcherInterface; 14use Symfony\Component\EventDispatcher\EventDispatcherInterface;
@@ -18,19 +19,22 @@ abstract class AbstractImport implements ImportInterface
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,34 @@ 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 /**
85 * Fetch content from the ContentProxy (using graby). 101 * 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). 102 * If it fails return the given entry to be saved in all case (to avoid user to loose the content).
87 * 103 *
88 * @param Entry $entry Entry to update 104 * @param Entry $entry Entry to update
89 * @param string $url Url to grab content for 105 * @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 106 * @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 */ 107 */
94 protected function fetchContent(Entry $entry, $url, array $content = []) 108 protected function fetchContent(Entry $entry, $url, array $content = [])
95 { 109 {
96 try { 110 try {
97 return $this->contentProxy->updateEntry($entry, $url, $content); 111 $this->contentProxy->updateEntry($entry, $url, $content, $this->disableContentUpdate);
98 } catch (\Exception $e) { 112 } catch (\Exception $e) {
99 return $entry; 113 $this->logger->error('Error trying to import an entry.', [
114 'entry_url' => $url,
115 'error_msg' => $e->getMessage(),
116 ]);
100 } 117 }
101 } 118 }
102 119
diff --git a/src/Wallabag/ImportBundle/Import/BrowserImport.php b/src/Wallabag/ImportBundle/Import/BrowserImport.php
index 8bf7d92e..71e65e59 100644
--- a/src/Wallabag/ImportBundle/Import/BrowserImport.php
+++ b/src/Wallabag/ImportBundle/Import/BrowserImport.php
@@ -4,7 +4,6 @@ namespace Wallabag\ImportBundle\Import;
4 4
5use Wallabag\CoreBundle\Entity\Entry; 5use Wallabag\CoreBundle\Entity\Entry;
6use Wallabag\UserBundle\Entity\User; 6use Wallabag\UserBundle\Entity\User;
7use Wallabag\CoreBundle\Helper\ContentProxy;
8use Wallabag\CoreBundle\Event\EntrySavedEvent; 7use Wallabag\CoreBundle\Event\EntrySavedEvent;
9 8
10abstract class BrowserImport extends AbstractImport 9abstract class BrowserImport extends AbstractImport
@@ -202,10 +201,10 @@ abstract class BrowserImport extends AbstractImport
202 $entry->setTitle($data['title']); 201 $entry->setTitle($data['title']);
203 202
204 // update entry with content (in case fetching failed, the given entry will be return) 203 // update entry with content (in case fetching failed, the given entry will be return)
205 $entry = $this->fetchContent($entry, $data['url'], $data); 204 $this->fetchContent($entry, $data['url'], $data);
206 205
207 if (array_key_exists('tags', $data)) { 206 if (array_key_exists('tags', $data)) {
208 $this->contentProxy->assignTagsToEntry( 207 $this->tagsAssigner->assignTagsToEntry(
209 $entry, 208 $entry,
210 $data['tags'] 209 $data['tags']
211 ); 210 );
diff --git a/src/Wallabag/ImportBundle/Import/InstapaperImport.php b/src/Wallabag/ImportBundle/Import/InstapaperImport.php
index 70a53f1a..3aa12f6f 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'])) {
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..c1d5b6da 100644
--- a/src/Wallabag/ImportBundle/Import/PocketImport.php
+++ b/src/Wallabag/ImportBundle/Import/PocketImport.php
@@ -5,7 +5,6 @@ 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{
@@ -193,7 +192,7 @@ class PocketImport extends AbstractImport
193 $entry->setUrl($url); 192 $entry->setUrl($url);
194 193
195 // update entry with content (in case fetching failed, the given entry will be return) 194 // update entry with content (in case fetching failed, the given entry will be return)
196 $entry = $this->fetchContent($entry, $url); 195 $this->fetchContent($entry, $url);
197 196
198 // 0, 1, 2 - 1 if the item is archived - 2 if the item should be deleted 197 // 0, 1, 2 - 1 if the item is archived - 2 if the item should be deleted
199 $entry->setArchived($importedEntry['status'] == 1 || $this->markAsRead); 198 $entry->setArchived($importedEntry['status'] == 1 || $this->markAsRead);
@@ -216,7 +215,7 @@ class PocketImport extends AbstractImport
216 } 215 }
217 216
218 if (isset($importedEntry['tags']) && !empty($importedEntry['tags'])) { 217 if (isset($importedEntry['tags']) && !empty($importedEntry['tags'])) {
219 $this->contentProxy->assignTagsToEntry( 218 $this->tagsAssigner->assignTagsToEntry(
220 $entry, 219 $entry,
221 array_keys($importedEntry['tags']), 220 array_keys($importedEntry['tags']),
222 $this->em->getUnitOfWork()->getScheduledEntityInsertions() 221 $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..1f0df646 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,10 +54,11 @@ 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
58 // If fetching fails again, they will get this instead of the v1 strings
47 if (in_array($entry['title'], $this->untitled)) { 59 if (in_array($entry['title'], $this->untitled)) {
48 $data['title'] = ''; 60 $data['title'] = $this->fetchingErrorMessageTitle;
49 $data['html'] = ''; 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'] != '') {
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