diff options
Diffstat (limited to 'src/Wallabag/ImportBundle/Import/WallabagV1Import.php')
-rw-r--r-- | src/Wallabag/ImportBundle/Import/WallabagV1Import.php | 28 |
1 files changed, 7 insertions, 21 deletions
diff --git a/src/Wallabag/ImportBundle/Import/WallabagV1Import.php b/src/Wallabag/ImportBundle/Import/WallabagV1Import.php index bbac6eaf..05bdb401 100644 --- a/src/Wallabag/ImportBundle/Import/WallabagV1Import.php +++ b/src/Wallabag/ImportBundle/Import/WallabagV1Import.php | |||
@@ -6,7 +6,6 @@ use Psr\Log\LoggerInterface; | |||
6 | use Psr\Log\NullLogger; | 6 | use Psr\Log\NullLogger; |
7 | use Doctrine\ORM\EntityManager; | 7 | use Doctrine\ORM\EntityManager; |
8 | use Wallabag\CoreBundle\Entity\Entry; | 8 | use Wallabag\CoreBundle\Entity\Entry; |
9 | use Wallabag\CoreBundle\Entity\Tag; | ||
10 | use Wallabag\UserBundle\Entity\User; | 9 | use Wallabag\UserBundle\Entity\User; |
11 | use Wallabag\CoreBundle\Tools\Utils; | 10 | use Wallabag\CoreBundle\Tools\Utils; |
12 | use Wallabag\CoreBundle\Helper\ContentProxy; | 11 | use Wallabag\CoreBundle\Helper\ContentProxy; |
@@ -144,6 +143,7 @@ class WallabagV1Import implements ImportInterface | |||
144 | // @see ContentProxy->updateEntry | 143 | // @see ContentProxy->updateEntry |
145 | $entry = new Entry($this->user); | 144 | $entry = new Entry($this->user); |
146 | $entry->setUrl($importedEntry['url']); | 145 | $entry->setUrl($importedEntry['url']); |
146 | |||
147 | if (in_array($importedEntry['title'], $untitled)) { | 147 | if (in_array($importedEntry['title'], $untitled)) { |
148 | $entry = $this->contentProxy->updateEntry($entry, $importedEntry['url']); | 148 | $entry = $this->contentProxy->updateEntry($entry, $importedEntry['url']); |
149 | } else { | 149 | } else { |
@@ -152,10 +152,14 @@ class WallabagV1Import implements ImportInterface | |||
152 | $entry->setReadingTime(Utils::getReadingTime($importedEntry['content'])); | 152 | $entry->setReadingTime(Utils::getReadingTime($importedEntry['content'])); |
153 | $entry->setDomainName(parse_url($importedEntry['url'], PHP_URL_HOST)); | 153 | $entry->setDomainName(parse_url($importedEntry['url'], PHP_URL_HOST)); |
154 | } | 154 | } |
155 | |||
155 | if (array_key_exists('tags', $importedEntry) && $importedEntry['tags'] != '') { | 156 | if (array_key_exists('tags', $importedEntry) && $importedEntry['tags'] != '') { |
156 | $tags = explode(',', $importedEntry['tags']); | 157 | $this->contentProxy->assignTagsToEntry( |
157 | $this->assignTagsToEntry($entry, $tags); | 158 | $entry, |
159 | $importedEntry['tags'] | ||
160 | ); | ||
158 | } | 161 | } |
162 | |||
159 | $entry->setArchived($importedEntry['is_read']); | 163 | $entry->setArchived($importedEntry['is_read']); |
160 | $entry->setStarred($importedEntry['is_fav']); | 164 | $entry->setStarred($importedEntry['is_fav']); |
161 | 165 | ||
@@ -171,22 +175,4 @@ class WallabagV1Import implements ImportInterface | |||
171 | 175 | ||
172 | $this->em->flush(); | 176 | $this->em->flush(); |
173 | } | 177 | } |
174 | |||
175 | private function assignTagsToEntry(Entry $entry, $tags) | ||
176 | { | ||
177 | foreach ($tags as $tag) { | ||
178 | $label = trim($tag); | ||
179 | $tagEntity = $this->em | ||
180 | ->getRepository('WallabagCoreBundle:Tag') | ||
181 | ->findOneByLabel($label); | ||
182 | if (is_object($tagEntity)) { | ||
183 | $entry->addTag($tagEntity); | ||
184 | } else { | ||
185 | $newTag = new Tag(); | ||
186 | $newTag->setLabel($label); | ||
187 | $entry->addTag($newTag); | ||
188 | } | ||
189 | $this->em->flush(); | ||
190 | } | ||
191 | } | ||
192 | } | 178 | } |