X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=src%2FWallabag%2FImportBundle%2FImport%2FPocketImport.php;h=4499ce6993563f41d1eccfddbf1b22f1743cb9e7;hb=439b36323e37f669b056cc5228c44bb91196256c;hp=9b82720a9a0eb7aa3c14a992e34d9aa122db1fa3;hpb=d1af8ad4dbf7f3ce5170655c2fa8403406283039;p=github%2Fwallabag%2Fwallabag.git diff --git a/src/Wallabag/ImportBundle/Import/PocketImport.php b/src/Wallabag/ImportBundle/Import/PocketImport.php index 9b82720a..4499ce69 100644 --- a/src/Wallabag/ImportBundle/Import/PocketImport.php +++ b/src/Wallabag/ImportBundle/Import/PocketImport.php @@ -9,9 +9,8 @@ use GuzzleHttp\Client; use GuzzleHttp\Exception\RequestException; use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; use Wallabag\CoreBundle\Entity\Entry; -use Wallabag\CoreBundle\Entity\Tag; use Wallabag\CoreBundle\Helper\ContentProxy; -use Symfony\Component\Translation\TranslatorInterface; +use Craue\ConfigBundle\Util\Config; class PocketImport implements ImportInterface { @@ -23,17 +22,16 @@ class PocketImport implements ImportInterface private $consumerKey; private $skippedEntries = 0; private $importedEntries = 0; + private $markAsRead; protected $accessToken; - private $translator; - public function __construct(TokenStorageInterface $tokenStorage, EntityManager $em, ContentProxy $contentProxy, $consumerKey, TranslatorInterface $translator) + public function __construct(TokenStorageInterface $tokenStorage, EntityManager $em, ContentProxy $contentProxy, Config $craueConfig) { $this->user = $tokenStorage->getToken()->getUser(); $this->em = $em; $this->contentProxy = $contentProxy; - $this->consumerKey = $consumerKey; + $this->consumerKey = $craueConfig->get('pocket_consumer_key'); $this->logger = new NullLogger(); - $this->translator = $translator; } public function setLogger(LoggerInterface $logger) @@ -62,7 +60,7 @@ class PocketImport implements ImportInterface */ public function getDescription() { - return $this->translator->trans("This importer will import all your Pocket data. Pocket doesn't allow us to retrieve content from their service, so the readable content of each article will be re-fetched by wallabag."); + return 'import.pocket.description'; } /** @@ -126,6 +124,26 @@ class PocketImport implements ImportInterface return true; } + /** + * Set whether articles must be all marked as read. + * + * @param bool $markAsRead + */ + public function setMarkAsRead($markAsRead) + { + $this->markAsRead = $markAsRead; + + return $this; + } + + /** + * Get whether articles must be all marked as read. + */ + public function getMarkAsRead() + { + return $this->markAsRead; + } + /** * {@inheritdoc} */ @@ -179,29 +197,6 @@ class PocketImport implements ImportInterface $this->client = $client; } - /** - * @todo move that in a more global place - */ - private function assignTagsToEntry(Entry $entry, $tags) - { - foreach ($tags as $tag) { - $label = trim($tag['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(); - } - } - /** * @see https://getpocket.com/developer/docs/v3/retrieve * @@ -216,7 +211,7 @@ class PocketImport implements ImportInterface $existingEntry = $this->em ->getRepository('WallabagCoreBundle:Entry') - ->existByUrlAndUserId($url, $this->user->getId()); + ->findByUrlAndUserId($url, $this->user->getId()); if (false !== $existingEntry) { ++$this->skippedEntries; @@ -227,7 +222,7 @@ class PocketImport implements ImportInterface $entry = $this->contentProxy->updateEntry($entry, $url); // 0, 1, 2 - 1 if the item is archived - 2 if the item should be deleted - if ($pocketEntry['status'] == 1) { + if ($pocketEntry['status'] == 1 || $this->markAsRead) { $entry->setArchived(true); } @@ -251,7 +246,10 @@ class PocketImport implements ImportInterface } if (isset($pocketEntry['tags']) && !empty($pocketEntry['tags'])) { - $this->assignTagsToEntry($entry, $pocketEntry['tags']); + $this->contentProxy->assignTagsToEntry( + $entry, + array_keys($pocketEntry['tags']) + ); } $this->em->persist($entry);