X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=src%2FWallabag%2FImportBundle%2FImport%2FWallabagV1Import.php;h=1d773d3bb58e2094ac057c490121c5dc9883479d;hb=fe8b37c137adbe036f58616c15dbcffd07dd2cd4;hp=bbac6eafc8dbd2a8137b66122facb7f3f9adbac6;hpb=fca2b05200f3e681c3ee195b8bb00088a8de0cf8;p=github%2Fwallabag%2Fwallabag.git diff --git a/src/Wallabag/ImportBundle/Import/WallabagV1Import.php b/src/Wallabag/ImportBundle/Import/WallabagV1Import.php index bbac6eaf..1d773d3b 100644 --- a/src/Wallabag/ImportBundle/Import/WallabagV1Import.php +++ b/src/Wallabag/ImportBundle/Import/WallabagV1Import.php @@ -6,7 +6,6 @@ use Psr\Log\LoggerInterface; use Psr\Log\NullLogger; use Doctrine\ORM\EntityManager; use Wallabag\CoreBundle\Entity\Entry; -use Wallabag\CoreBundle\Entity\Tag; use Wallabag\UserBundle\Entity\User; use Wallabag\CoreBundle\Tools\Utils; use Wallabag\CoreBundle\Helper\ContentProxy; @@ -20,6 +19,7 @@ class WallabagV1Import implements ImportInterface protected $skippedEntries = 0; protected $importedEntries = 0; protected $filepath; + protected $markAsRead; public function __construct(EntityManager $em, ContentProxy $contentProxy) { @@ -121,6 +121,18 @@ class WallabagV1Import implements ImportInterface return $this; } + /** + * Set whether articles must be all marked as read. + * + * @param bool $markAsRead + */ + public function setMarkAsRead($markAsRead) + { + $this->markAsRead = $markAsRead; + + return $this; + } + /** * @param $entries */ @@ -144,6 +156,7 @@ class WallabagV1Import implements ImportInterface // @see ContentProxy->updateEntry $entry = new Entry($this->user); $entry->setUrl($importedEntry['url']); + if (in_array($importedEntry['title'], $untitled)) { $entry = $this->contentProxy->updateEntry($entry, $importedEntry['url']); } else { @@ -152,11 +165,15 @@ class WallabagV1Import implements ImportInterface $entry->setReadingTime(Utils::getReadingTime($importedEntry['content'])); $entry->setDomainName(parse_url($importedEntry['url'], PHP_URL_HOST)); } + if (array_key_exists('tags', $importedEntry) && $importedEntry['tags'] != '') { - $tags = explode(',', $importedEntry['tags']); - $this->assignTagsToEntry($entry, $tags); + $this->contentProxy->assignTagsToEntry( + $entry, + $importedEntry['tags'] + ); } - $entry->setArchived($importedEntry['is_read']); + + $entry->setArchived($importedEntry['is_read'] || $this->markAsRead); $entry->setStarred($importedEntry['is_fav']); $this->em->persist($entry); @@ -171,22 +188,4 @@ class WallabagV1Import implements ImportInterface $this->em->flush(); } - - private function assignTagsToEntry(Entry $entry, $tags) - { - foreach ($tags as $tag) { - $label = trim($tag); - $tagEntity = $this->em - ->getRepository('WallabagCoreBundle:Tag') - ->findOneByLabel($label); - if (is_object($tagEntity)) { - $entry->addTag($tagEntity); - } else { - $newTag = new Tag(); - $newTag->setLabel($label); - $entry->addTag($newTag); - } - $this->em->flush(); - } - } }