diff options
Diffstat (limited to 'src/Wallabag/ImportBundle/Import')
8 files changed, 113 insertions, 114 deletions
diff --git a/src/Wallabag/ImportBundle/Import/AbstractImport.php b/src/Wallabag/ImportBundle/Import/AbstractImport.php index 9b624296..cb46db09 100644 --- a/src/Wallabag/ImportBundle/Import/AbstractImport.php +++ b/src/Wallabag/ImportBundle/Import/AbstractImport.php | |||
@@ -2,17 +2,17 @@ | |||
2 | 2 | ||
3 | namespace Wallabag\ImportBundle\Import; | 3 | namespace Wallabag\ImportBundle\Import; |
4 | 4 | ||
5 | use Doctrine\ORM\EntityManager; | ||
6 | use OldSound\RabbitMqBundle\RabbitMq\ProducerInterface; | ||
5 | use Psr\Log\LoggerInterface; | 7 | use Psr\Log\LoggerInterface; |
6 | use Psr\Log\NullLogger; | 8 | use Psr\Log\NullLogger; |
7 | use Doctrine\ORM\EntityManager; | 9 | use Symfony\Component\EventDispatcher\EventDispatcherInterface; |
8 | use Wallabag\CoreBundle\Helper\ContentProxy; | ||
9 | use Wallabag\CoreBundle\Entity\Entry; | 10 | use Wallabag\CoreBundle\Entity\Entry; |
10 | use Wallabag\CoreBundle\Entity\Tag; | 11 | use Wallabag\CoreBundle\Entity\Tag; |
12 | use Wallabag\CoreBundle\Event\EntrySavedEvent; | ||
13 | use Wallabag\CoreBundle\Helper\ContentProxy; | ||
11 | use Wallabag\CoreBundle\Helper\TagsAssigner; | 14 | use Wallabag\CoreBundle\Helper\TagsAssigner; |
12 | use Wallabag\UserBundle\Entity\User; | 15 | use Wallabag\UserBundle\Entity\User; |
13 | use OldSound\RabbitMqBundle\RabbitMq\ProducerInterface; | ||
14 | use Symfony\Component\EventDispatcher\EventDispatcherInterface; | ||
15 | use Wallabag\CoreBundle\Event\EntrySavedEvent; | ||
16 | 16 | ||
17 | abstract class AbstractImport implements ImportInterface | 17 | abstract class AbstractImport implements ImportInterface |
18 | { | 18 | { |
@@ -98,6 +98,27 @@ abstract class AbstractImport implements ImportInterface | |||
98 | } | 98 | } |
99 | 99 | ||
100 | /** | 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 | /** | ||
101 | * Fetch content from the ContentProxy (using graby). | 122 | * Fetch content from the ContentProxy (using graby). |
102 | * 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). |
103 | * | 124 | * |
@@ -196,27 +217,6 @@ abstract class AbstractImport implements ImportInterface | |||
196 | } | 217 | } |
197 | 218 | ||
198 | /** | 219 | /** |
199 | * {@inheritdoc} | ||
200 | */ | ||
201 | public function getSummary() | ||
202 | { | ||
203 | return [ | ||
204 | 'skipped' => $this->skippedEntries, | ||
205 | 'imported' => $this->importedEntries, | ||
206 | 'queued' => $this->queuedEntries, | ||
207 | ]; | ||
208 | } | ||
209 | |||
210 | /** | ||
211 | * Parse one entry. | ||
212 | * | ||
213 | * @param array $importedEntry | ||
214 | * | ||
215 | * @return Entry | ||
216 | */ | ||
217 | abstract public function parseEntry(array $importedEntry); | ||
218 | |||
219 | /** | ||
220 | * Set current imported entry to archived / read. | 220 | * Set current imported entry to archived / read. |
221 | * Implementation is different accross all imports. | 221 | * Implementation is different accross all imports. |
222 | * | 222 | * |
diff --git a/src/Wallabag/ImportBundle/Import/BrowserImport.php b/src/Wallabag/ImportBundle/Import/BrowserImport.php index 71e65e59..f1195824 100644 --- a/src/Wallabag/ImportBundle/Import/BrowserImport.php +++ b/src/Wallabag/ImportBundle/Import/BrowserImport.php | |||
@@ -3,8 +3,8 @@ | |||
3 | namespace Wallabag\ImportBundle\Import; | 3 | namespace Wallabag\ImportBundle\Import; |
4 | 4 | ||
5 | use Wallabag\CoreBundle\Entity\Entry; | 5 | use Wallabag\CoreBundle\Entity\Entry; |
6 | use Wallabag\UserBundle\Entity\User; | ||
7 | use Wallabag\CoreBundle\Event\EntrySavedEvent; | 6 | use Wallabag\CoreBundle\Event\EntrySavedEvent; |
7 | use Wallabag\UserBundle\Entity\User; | ||
8 | 8 | ||
9 | abstract class BrowserImport extends AbstractImport | 9 | abstract class BrowserImport extends AbstractImport |
10 | { | 10 | { |
@@ -74,6 +74,80 @@ abstract class BrowserImport extends AbstractImport | |||
74 | } | 74 | } |
75 | 75 | ||
76 | /** | 76 | /** |
77 | * {@inheritdoc} | ||
78 | */ | ||
79 | public function parseEntry(array $importedEntry) | ||
80 | { | ||
81 | if ((!array_key_exists('guid', $importedEntry) || (!array_key_exists('id', $importedEntry))) && is_array(reset($importedEntry))) { | ||
82 | if ($this->producer) { | ||
83 | $this->parseEntriesForProducer($importedEntry); | ||
84 | |||
85 | return; | ||
86 | } | ||
87 | |||
88 | $this->parseEntries($importedEntry); | ||
89 | |||
90 | return; | ||
91 | } | ||
92 | |||
93 | if (array_key_exists('children', $importedEntry)) { | ||
94 | if ($this->producer) { | ||
95 | $this->parseEntriesForProducer($importedEntry['children']); | ||
96 | |||
97 | return; | ||
98 | } | ||
99 | |||
100 | $this->parseEntries($importedEntry['children']); | ||
101 | |||
102 | return; | ||
103 | } | ||
104 | |||
105 | if (!array_key_exists('uri', $importedEntry) && !array_key_exists('url', $importedEntry)) { | ||
106 | return; | ||
107 | } | ||
108 | |||
109 | $url = array_key_exists('uri', $importedEntry) ? $importedEntry['uri'] : $importedEntry['url']; | ||
110 | |||
111 | $existingEntry = $this->em | ||
112 | ->getRepository('WallabagCoreBundle:Entry') | ||
113 | ->findByUrlAndUserId($url, $this->user->getId()); | ||
114 | |||
115 | if (false !== $existingEntry) { | ||
116 | ++$this->skippedEntries; | ||
117 | |||
118 | return; | ||
119 | } | ||
120 | |||
121 | $data = $this->prepareEntry($importedEntry); | ||
122 | |||
123 | $entry = new Entry($this->user); | ||
124 | $entry->setUrl($data['url']); | ||
125 | $entry->setTitle($data['title']); | ||
126 | |||
127 | // update entry with content (in case fetching failed, the given entry will be return) | ||
128 | $this->fetchContent($entry, $data['url'], $data); | ||
129 | |||
130 | if (array_key_exists('tags', $data)) { | ||
131 | $this->tagsAssigner->assignTagsToEntry( | ||
132 | $entry, | ||
133 | $data['tags'] | ||
134 | ); | ||
135 | } | ||
136 | |||
137 | $entry->setArchived($data['is_archived']); | ||
138 | |||
139 | if (!empty($data['created_at'])) { | ||
140 | $dt = new \DateTime(); | ||
141 | $entry->setCreatedAt($dt->setTimestamp($data['created_at'])); | ||
142 | } | ||
143 | |||
144 | $this->em->persist($entry); | ||
145 | ++$this->importedEntries; | ||
146 | |||
147 | return $entry; | ||
148 | } | ||
149 | |||
150 | /** | ||
77 | * Parse and insert all given entries. | 151 | * Parse and insert all given entries. |
78 | * | 152 | * |
79 | * @param $entries | 153 | * @param $entries |
@@ -152,80 +226,6 @@ abstract class BrowserImport extends AbstractImport | |||
152 | /** | 226 | /** |
153 | * {@inheritdoc} | 227 | * {@inheritdoc} |
154 | */ | 228 | */ |
155 | public function parseEntry(array $importedEntry) | ||
156 | { | ||
157 | if ((!array_key_exists('guid', $importedEntry) || (!array_key_exists('id', $importedEntry))) && is_array(reset($importedEntry))) { | ||
158 | if ($this->producer) { | ||
159 | $this->parseEntriesForProducer($importedEntry); | ||
160 | |||
161 | return; | ||
162 | } | ||
163 | |||
164 | $this->parseEntries($importedEntry); | ||
165 | |||
166 | return; | ||
167 | } | ||
168 | |||
169 | if (array_key_exists('children', $importedEntry)) { | ||
170 | if ($this->producer) { | ||
171 | $this->parseEntriesForProducer($importedEntry['children']); | ||
172 | |||
173 | return; | ||
174 | } | ||
175 | |||
176 | $this->parseEntries($importedEntry['children']); | ||
177 | |||
178 | return; | ||
179 | } | ||
180 | |||
181 | if (!array_key_exists('uri', $importedEntry) && !array_key_exists('url', $importedEntry)) { | ||
182 | return; | ||
183 | } | ||
184 | |||
185 | $url = array_key_exists('uri', $importedEntry) ? $importedEntry['uri'] : $importedEntry['url']; | ||
186 | |||
187 | $existingEntry = $this->em | ||
188 | ->getRepository('WallabagCoreBundle:Entry') | ||
189 | ->findByUrlAndUserId($url, $this->user->getId()); | ||
190 | |||
191 | if (false !== $existingEntry) { | ||
192 | ++$this->skippedEntries; | ||
193 | |||
194 | return; | ||
195 | } | ||
196 | |||
197 | $data = $this->prepareEntry($importedEntry); | ||
198 | |||
199 | $entry = new Entry($this->user); | ||
200 | $entry->setUrl($data['url']); | ||
201 | $entry->setTitle($data['title']); | ||
202 | |||
203 | // update entry with content (in case fetching failed, the given entry will be return) | ||
204 | $this->fetchContent($entry, $data['url'], $data); | ||
205 | |||
206 | if (array_key_exists('tags', $data)) { | ||
207 | $this->tagsAssigner->assignTagsToEntry( | ||
208 | $entry, | ||
209 | $data['tags'] | ||
210 | ); | ||
211 | } | ||
212 | |||
213 | $entry->setArchived($data['is_archived']); | ||
214 | |||
215 | if (!empty($data['created_at'])) { | ||
216 | $dt = new \DateTime(); | ||
217 | $entry->setCreatedAt($dt->setTimestamp($data['created_at'])); | ||
218 | } | ||
219 | |||
220 | $this->em->persist($entry); | ||
221 | ++$this->importedEntries; | ||
222 | |||
223 | return $entry; | ||
224 | } | ||
225 | |||
226 | /** | ||
227 | * {@inheritdoc} | ||
228 | */ | ||
229 | protected function setEntryAsRead(array $importedEntry) | 229 | protected function setEntryAsRead(array $importedEntry) |
230 | { | 230 | { |
231 | $importedEntry['is_archived'] = 1; | 231 | $importedEntry['is_archived'] = 1; |
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 | ||
3 | namespace Wallabag\ImportBundle\Import; | 3 | namespace Wallabag\ImportBundle\Import; |
4 | 4 | ||
5 | use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
6 | use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; | 5 | use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; |
6 | use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
7 | use Symfony\Component\DependencyInjection\Reference; | 7 | use Symfony\Component\DependencyInjection\Reference; |
8 | 8 | ||
9 | class ImportCompilerPass implements CompilerPassInterface | 9 | class ImportCompilerPass implements CompilerPassInterface |
diff --git a/src/Wallabag/ImportBundle/Import/InstapaperImport.php b/src/Wallabag/ImportBundle/Import/InstapaperImport.php index 3aa12f6f..7d70154a 100644 --- a/src/Wallabag/ImportBundle/Import/InstapaperImport.php +++ b/src/Wallabag/ImportBundle/Import/InstapaperImport.php | |||
@@ -72,7 +72,7 @@ class InstapaperImport extends AbstractImport | |||
72 | // BUT it can also be the status (since status = folder in Instapaper) | 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 | 73 | // and we don't want archive, unread & starred to become a tag |
74 | $tags = null; | 74 | $tags = null; |
75 | if (false === in_array($data[3], ['Archive', 'Unread', 'Starred'])) { | 75 | if (false === in_array($data[3], ['Archive', 'Unread', 'Starred'], true)) { |
76 | $tags = [$data[3]]; | 76 | $tags = [$data[3]]; |
77 | } | 77 | } |
78 | 78 | ||
diff --git a/src/Wallabag/ImportBundle/Import/PocketImport.php b/src/Wallabag/ImportBundle/Import/PocketImport.php index c1d5b6da..7d38826b 100644 --- a/src/Wallabag/ImportBundle/Import/PocketImport.php +++ b/src/Wallabag/ImportBundle/Import/PocketImport.php | |||
@@ -8,11 +8,10 @@ use Wallabag\CoreBundle\Entity\Entry; | |||
8 | 8 | ||
9 | class PocketImport extends AbstractImport | 9 | class PocketImport extends AbstractImport |
10 | { | 10 | { |
11 | const NB_ELEMENTS = 5000; | ||
11 | private $client; | 12 | private $client; |
12 | private $accessToken; | 13 | private $accessToken; |
13 | 14 | ||
14 | const NB_ELEMENTS = 5000; | ||
15 | |||
16 | /** | 15 | /** |
17 | * Only used for test purpose. | 16 | * Only used for test purpose. |
18 | * | 17 | * |
@@ -176,7 +175,7 @@ class PocketImport extends AbstractImport | |||
176 | */ | 175 | */ |
177 | public function parseEntry(array $importedEntry) | 176 | public function parseEntry(array $importedEntry) |
178 | { | 177 | { |
179 | $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']; |
180 | 179 | ||
181 | $existingEntry = $this->em | 180 | $existingEntry = $this->em |
182 | ->getRepository('WallabagCoreBundle:Entry') | 181 | ->getRepository('WallabagCoreBundle:Entry') |
@@ -195,15 +194,15 @@ class PocketImport extends AbstractImport | |||
195 | $this->fetchContent($entry, $url); | 194 | $this->fetchContent($entry, $url); |
196 | 195 | ||
197 | // 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 |
198 | $entry->setArchived($importedEntry['status'] == 1 || $this->markAsRead); | 197 | $entry->setArchived($importedEntry['status'] === 1 || $this->markAsRead); |
199 | 198 | ||
200 | // 0 or 1 - 1 If the item is starred | 199 | // 0 or 1 - 1 If the item is starred |
201 | $entry->setStarred($importedEntry['favorite'] == 1); | 200 | $entry->setStarred($importedEntry['favorite'] === 1); |
202 | 201 | ||
203 | $title = 'Untitled'; | 202 | $title = 'Untitled'; |
204 | if (isset($importedEntry['resolved_title']) && $importedEntry['resolved_title'] != '') { | 203 | if (isset($importedEntry['resolved_title']) && $importedEntry['resolved_title'] !== '') { |
205 | $title = $importedEntry['resolved_title']; | 204 | $title = $importedEntry['resolved_title']; |
206 | } elseif (isset($importedEntry['given_title']) && $importedEntry['given_title'] != '') { | 205 | } elseif (isset($importedEntry['given_title']) && $importedEntry['given_title'] !== '') { |
207 | $title = $importedEntry['given_title']; | 206 | $title = $importedEntry['given_title']; |
208 | } | 207 | } |
209 | 208 | ||
diff --git a/src/Wallabag/ImportBundle/Import/WallabagV1Import.php b/src/Wallabag/ImportBundle/Import/WallabagV1Import.php index 1f0df646..d585d44d 100644 --- a/src/Wallabag/ImportBundle/Import/WallabagV1Import.php +++ b/src/Wallabag/ImportBundle/Import/WallabagV1Import.php | |||
@@ -56,12 +56,12 @@ class WallabagV1Import extends WallabagImport | |||
56 | 56 | ||
57 | // In case of a bad fetch in v1, replace title and content with v2 error strings | 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 | 58 | // If fetching fails again, they will get this instead of the v1 strings |
59 | if (in_array($entry['title'], $this->untitled)) { | 59 | if (in_array($entry['title'], $this->untitled, true)) { |
60 | $data['title'] = $this->fetchingErrorMessageTitle; | 60 | $data['title'] = $this->fetchingErrorMessageTitle; |
61 | $data['html'] = $this->fetchingErrorMessage; | 61 | $data['html'] = $this->fetchingErrorMessage; |
62 | } | 62 | } |
63 | 63 | ||
64 | if (array_key_exists('tags', $entry) && $entry['tags'] != '') { | 64 | if (array_key_exists('tags', $entry) && $entry['tags'] !== '') { |
65 | $data['tags'] = $entry['tags']; | 65 | $data['tags'] = $entry['tags']; |
66 | } | 66 | } |
67 | 67 | ||