aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Wallabag/ImportBundle/Import/AbstractImport.php42
-rw-r--r--src/Wallabag/ImportBundle/Import/PocketImport.php22
-rw-r--r--src/Wallabag/ImportBundle/Import/ReadabilityImport.php28
-rw-r--r--src/Wallabag/ImportBundle/Import/WallabagImport.php2
-rw-r--r--src/Wallabag/ImportBundle/Import/WallabagV1Import.php18
-rw-r--r--src/Wallabag/ImportBundle/Import/WallabagV2Import.php18
6 files changed, 60 insertions, 70 deletions
diff --git a/src/Wallabag/ImportBundle/Import/AbstractImport.php b/src/Wallabag/ImportBundle/Import/AbstractImport.php
index 5b9d65d7..b085dc3a 100644
--- a/src/Wallabag/ImportBundle/Import/AbstractImport.php
+++ b/src/Wallabag/ImportBundle/Import/AbstractImport.php
@@ -7,7 +7,7 @@ use Psr\Log\NullLogger;
7use Doctrine\ORM\EntityManager; 7use Doctrine\ORM\EntityManager;
8use Wallabag\CoreBundle\Helper\ContentProxy; 8use Wallabag\CoreBundle\Helper\ContentProxy;
9use Wallabag\CoreBundle\Entity\Entry; 9use Wallabag\CoreBundle\Entity\Entry;
10use Symfony\Component\Security\Core\User\UserInterface; 10use Wallabag\UserBundle\Entity\User;
11use OldSound\RabbitMqBundle\RabbitMq\Producer; 11use OldSound\RabbitMqBundle\RabbitMq\Producer;
12 12
13abstract class AbstractImport implements ImportInterface 13abstract class AbstractImport implements ImportInterface
@@ -46,9 +46,9 @@ abstract class AbstractImport implements ImportInterface
46 * Set current user. 46 * Set current user.
47 * Could the current *connected* user or one retrieve by the consumer. 47 * Could the current *connected* user or one retrieve by the consumer.
48 * 48 *
49 * @param UserInterface $user 49 * @param User $user
50 */ 50 */
51 public function setUser(UserInterface $user) 51 public function setUser(User $user)
52 { 52 {
53 $this->user = $user; 53 $this->user = $user;
54 } 54 }
@@ -120,6 +120,32 @@ abstract class AbstractImport implements ImportInterface
120 } 120 }
121 121
122 /** 122 /**
123 * Parse entries and send them to the queue.
124 * It should just be a simple loop on all item, no call to the database should be done
125 * to speedup queuing.
126 *
127 * Faster parse entries for Producer.
128 * We don't care to make check at this time. They'll be done by the consumer.
129 *
130 * @param array $entries
131 */
132 protected function parseEntriesForProducer(array $entries)
133 {
134 foreach ($entries as $importedEntry) {
135 // set userId for the producer (it won't know which user is connected)
136 $importedEntry['userId'] = $this->user->getId();
137
138 if ($this->markAsRead) {
139 $importedEntry = $this->setEntryAsRead($importedEntry);
140 }
141
142 ++$this->importedEntries;
143
144 $this->producer->publish(json_encode($importedEntry));
145 }
146 }
147
148 /**
123 * Parse one entry. 149 * Parse one entry.
124 * 150 *
125 * @param array $importedEntry 151 * @param array $importedEntry
@@ -127,4 +153,14 @@ abstract class AbstractImport implements ImportInterface
127 * @return Entry 153 * @return Entry
128 */ 154 */
129 abstract public function parseEntry(array $importedEntry); 155 abstract public function parseEntry(array $importedEntry);
156
157 /**
158 * Set current imported entry to archived / read.
159 * Implementation is different accross all imports.
160 *
161 * @param array $importedEntry
162 *
163 * @return array
164 */
165 abstract protected function setEntryAsRead(array $importedEntry);
130} 166}
diff --git a/src/Wallabag/ImportBundle/Import/PocketImport.php b/src/Wallabag/ImportBundle/Import/PocketImport.php
index 06a31813..5850deba 100644
--- a/src/Wallabag/ImportBundle/Import/PocketImport.php
+++ b/src/Wallabag/ImportBundle/Import/PocketImport.php
@@ -29,7 +29,7 @@ class PocketImport extends AbstractImport
29 } 29 }
30 30
31 /** 31 /**
32 * Only used for test purpose 32 * Only used for test purpose.
33 * 33 *
34 * @return string 34 * @return string
35 */ 35 */
@@ -258,24 +258,12 @@ class PocketImport extends AbstractImport
258 } 258 }
259 259
260 /** 260 /**
261 * Faster parse entries for Producer. 261 * {@inheritdoc}
262 * We don't care to make check at this time. They'll be done by the consumer.
263 *
264 * @param array $entries
265 */ 262 */
266 public function parseEntriesForProducer($entries) 263 protected function setEntryAsRead(array $importedEntry)
267 { 264 {
268 foreach ($entries as $importedEntry) { 265 $importedEntry['status'] = 1;
269 // set userId for the producer (it won't know which user is connected)
270 $importedEntry['userId'] = $this->user->getId();
271
272 if ($this->markAsRead) {
273 $importedEntry['status'] = 1;
274 }
275 266
276 ++$this->importedEntries; 267 return $importedEntry;
277
278 $this->producer->publish(json_encode($importedEntry));
279 }
280 } 268 }
281} 269}
diff --git a/src/Wallabag/ImportBundle/Import/ReadabilityImport.php b/src/Wallabag/ImportBundle/Import/ReadabilityImport.php
index 18a6631a..64ef62bf 100644
--- a/src/Wallabag/ImportBundle/Import/ReadabilityImport.php
+++ b/src/Wallabag/ImportBundle/Import/ReadabilityImport.php
@@ -3,7 +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;
7 6
8class ReadabilityImport extends AbstractImport 7class ReadabilityImport extends AbstractImport
9{ 8{
@@ -136,31 +135,12 @@ class ReadabilityImport extends AbstractImport
136 } 135 }
137 136
138 /** 137 /**
139 * Faster parse entries for Producer. 138 * {@inheritdoc}
140 * We don't care to make check at this time. They'll be done by the consumer.
141 *
142 * @param array $entries
143 */ 139 */
144 protected function parseEntriesForProducer($entries) 140 protected function setEntryAsRead(array $importedEntry)
145 { 141 {
146 foreach ($entries as $importedEntry) { 142 $importedEntry['archive'] = 1;
147 // set userId for the producer (it won't know which user is connected)
148 $importedEntry['userId'] = $this->user->getId();
149
150 if ($this->markAsRead) {
151 $importedEntry['archive'] = 1;
152 }
153
154 ++$this->importedEntries;
155
156 // flush every 20 entries
157 if (($i % 20) === 0) {
158 $this->em->flush();
159 }
160 ++$i;
161 }
162 143
163 $this->em->flush(); 144 return $importedEntry;
164 $this->em->clear();
165 } 145 }
166} 146}
diff --git a/src/Wallabag/ImportBundle/Import/WallabagImport.php b/src/Wallabag/ImportBundle/Import/WallabagImport.php
index 6ad14e8c..8e18e0ef 100644
--- a/src/Wallabag/ImportBundle/Import/WallabagImport.php
+++ b/src/Wallabag/ImportBundle/Import/WallabagImport.php
@@ -3,11 +3,9 @@
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;
7 6
8abstract class WallabagImport extends AbstractImport 7abstract class WallabagImport extends AbstractImport
9{ 8{
10 protected $user;
11 protected $skippedEntries = 0; 9 protected $skippedEntries = 0;
12 protected $importedEntries = 0; 10 protected $importedEntries = 0;
13 protected $filepath; 11 protected $filepath;
diff --git a/src/Wallabag/ImportBundle/Import/WallabagV1Import.php b/src/Wallabag/ImportBundle/Import/WallabagV1Import.php
index 86734652..292b72a7 100644
--- a/src/Wallabag/ImportBundle/Import/WallabagV1Import.php
+++ b/src/Wallabag/ImportBundle/Import/WallabagV1Import.php
@@ -57,19 +57,13 @@ class WallabagV1Import extends WallabagImport
57 return $data; 57 return $data;
58 } 58 }
59 59
60 protected function parseEntriesForProducer($entries) 60 /**
61 * {@inheritdoc}
62 */
63 protected function setEntryAsRead(array $importedEntry)
61 { 64 {
62 foreach ($entries as $importedEntry) { 65 $importedEntry['is_read'] = 1;
63 // set userId for the producer (it won't know which user is connected)
64 $importedEntry['userId'] = $this->user->getId();
65 66
66 if ($this->markAsRead) { 67 return $importedEntry;
67 $importedEntry['is_read'] = 1;
68 }
69
70 ++$this->importedEntries;
71
72 $this->producer->publish(json_encode($importedEntry));
73 }
74 } 68 }
75} 69}
diff --git a/src/Wallabag/ImportBundle/Import/WallabagV2Import.php b/src/Wallabag/ImportBundle/Import/WallabagV2Import.php
index faf4236f..37c8ca14 100644
--- a/src/Wallabag/ImportBundle/Import/WallabagV2Import.php
+++ b/src/Wallabag/ImportBundle/Import/WallabagV2Import.php
@@ -40,19 +40,13 @@ class WallabagV2Import extends WallabagImport
40 ] + $entry; 40 ] + $entry;
41 } 41 }
42 42
43 protected function parseEntriesForProducer($entries) 43 /**
44 * {@inheritdoc}
45 */
46 protected function setEntryAsRead(array $importedEntry)
44 { 47 {
45 foreach ($entries as $importedEntry) { 48 $importedEntry['is_archived'] = 1;
46 // set userId for the producer (it won't know which user is connected)
47 $importedEntry['userId'] = $this->user->getId();
48
49 if ($this->markAsRead) {
50 $importedEntry['is_archived'] = 1;
51 }
52
53 ++$this->importedEntries;
54 49
55 $this->producer->publish(json_encode($importedEntry)); 50 return $importedEntry;
56 }
57 } 51 }
58} 52}