aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/ImportBundle/Import
diff options
context:
space:
mode:
authorThomas Citharel <tcit@tcit.fr>2016-02-12 14:49:41 +0100
committerThomas Citharel <tcit@tcit.fr>2016-02-12 14:49:41 +0100
commitfca2b05200f3e681c3ee195b8bb00088a8de0cf8 (patch)
tree657ce9546d3904df849e17824987b9dca37d7a5f /src/Wallabag/ImportBundle/Import
parent06c190887fd38c314db8d240ab2e46f5777ed59e (diff)
downloadwallabag-fca2b05200f3e681c3ee195b8bb00088a8de0cf8.tar.gz
wallabag-fca2b05200f3e681c3ee195b8bb00088a8de0cf8.tar.zst
wallabag-fca2b05200f3e681c3ee195b8bb00088a8de0cf8.zip
import tags from v1 (#1657)
Diffstat (limited to 'src/Wallabag/ImportBundle/Import')
-rw-r--r--src/Wallabag/ImportBundle/Import/WallabagV1Import.php23
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;
6use Psr\Log\NullLogger; 6use Psr\Log\NullLogger;
7use Doctrine\ORM\EntityManager; 7use Doctrine\ORM\EntityManager;
8use Wallabag\CoreBundle\Entity\Entry; 8use Wallabag\CoreBundle\Entity\Entry;
9use Wallabag\CoreBundle\Entity\Tag;
9use Wallabag\UserBundle\Entity\User; 10use Wallabag\UserBundle\Entity\User;
10use Wallabag\CoreBundle\Tools\Utils; 11use Wallabag\CoreBundle\Tools\Utils;
11use Wallabag\CoreBundle\Helper\ContentProxy; 12use 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}