diff options
Diffstat (limited to 'src/Wallabag/ImportBundle/Import')
-rw-r--r-- | src/Wallabag/ImportBundle/Import/WallabagV1Import.php | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/Wallabag/ImportBundle/Import/WallabagV1Import.php b/src/Wallabag/ImportBundle/Import/WallabagV1Import.php index c54e73b2..bbac6eaf 100644 --- a/src/Wallabag/ImportBundle/Import/WallabagV1Import.php +++ b/src/Wallabag/ImportBundle/Import/WallabagV1Import.php | |||
@@ -6,6 +6,7 @@ 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; | ||
9 | use Wallabag\UserBundle\Entity\User; | 10 | use Wallabag\UserBundle\Entity\User; |
10 | use Wallabag\CoreBundle\Tools\Utils; | 11 | use Wallabag\CoreBundle\Tools\Utils; |
11 | use Wallabag\CoreBundle\Helper\ContentProxy; | 12 | use Wallabag\CoreBundle\Helper\ContentProxy; |
@@ -151,6 +152,10 @@ class WallabagV1Import implements ImportInterface | |||
151 | $entry->setReadingTime(Utils::getReadingTime($importedEntry['content'])); | 152 | $entry->setReadingTime(Utils::getReadingTime($importedEntry['content'])); |
152 | $entry->setDomainName(parse_url($importedEntry['url'], PHP_URL_HOST)); | 153 | $entry->setDomainName(parse_url($importedEntry['url'], PHP_URL_HOST)); |
153 | } | 154 | } |
155 | if (array_key_exists('tags', $importedEntry) && $importedEntry['tags'] != '') { | ||
156 | $tags = explode(',', $importedEntry['tags']); | ||
157 | $this->assignTagsToEntry($entry, $tags); | ||
158 | } | ||
154 | $entry->setArchived($importedEntry['is_read']); | 159 | $entry->setArchived($importedEntry['is_read']); |
155 | $entry->setStarred($importedEntry['is_fav']); | 160 | $entry->setStarred($importedEntry['is_fav']); |
156 | 161 | ||
@@ -166,4 +171,22 @@ class WallabagV1Import implements ImportInterface | |||
166 | 171 | ||
167 | $this->em->flush(); | 172 | $this->em->flush(); |
168 | } | 173 | } |
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 | } | ||
169 | } | 192 | } |