diff options
author | Jeremy Benoist <jeremy.benoist@gmail.com> | 2016-09-05 07:50:10 +0200 |
---|---|---|
committer | Jeremy Benoist <jeremy.benoist@gmail.com> | 2016-09-11 21:58:55 +0200 |
commit | 3849a9f3231c0109c87af085452c3ac5e4aed303 (patch) | |
tree | d5b8946a196f98aa438e7a39568b40af4952712e /src/Wallabag/ImportBundle/Import/AbstractImport.php | |
parent | 02f64895728fe9aee2c696a627e0bbe27a24faf2 (diff) | |
download | wallabag-3849a9f3231c0109c87af085452c3ac5e4aed303.tar.gz wallabag-3849a9f3231c0109c87af085452c3ac5e4aed303.tar.zst wallabag-3849a9f3231c0109c87af085452c3ac5e4aed303.zip |
Some cleanup & refactor
Diffstat (limited to 'src/Wallabag/ImportBundle/Import/AbstractImport.php')
-rw-r--r-- | src/Wallabag/ImportBundle/Import/AbstractImport.php | 42 |
1 files changed, 39 insertions, 3 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; | |||
7 | use Doctrine\ORM\EntityManager; | 7 | use Doctrine\ORM\EntityManager; |
8 | use Wallabag\CoreBundle\Helper\ContentProxy; | 8 | use Wallabag\CoreBundle\Helper\ContentProxy; |
9 | use Wallabag\CoreBundle\Entity\Entry; | 9 | use Wallabag\CoreBundle\Entity\Entry; |
10 | use Symfony\Component\Security\Core\User\UserInterface; | 10 | use Wallabag\UserBundle\Entity\User; |
11 | use OldSound\RabbitMqBundle\RabbitMq\Producer; | 11 | use OldSound\RabbitMqBundle\RabbitMq\Producer; |
12 | 12 | ||
13 | abstract class AbstractImport implements ImportInterface | 13 | abstract 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 | } |