X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;ds=sidebyside;f=src%2FWallabag%2FImportBundle%2FImport%2FPocketImport.php;h=72b9047c8fdc3acc39267b67a4af11adc31f2634;hb=86719c63bf47686ca55020e6b0443344de36d45a;hp=1710d9d3dcb2653f0a12824f732a0a2a750117cf;hpb=252ebd60719d32ec954d0519c9edf2b52b03310c;p=github%2Fwallabag%2Fwallabag.git diff --git a/src/Wallabag/ImportBundle/Import/PocketImport.php b/src/Wallabag/ImportBundle/Import/PocketImport.php index 1710d9d3..72b9047c 100644 --- a/src/Wallabag/ImportBundle/Import/PocketImport.php +++ b/src/Wallabag/ImportBundle/Import/PocketImport.php @@ -18,10 +18,12 @@ class PocketImport implements ImportInterface private $em; private $contentProxy; private $logger; + private $client; private $consumerKey; private $skippedEntries = 0; private $importedEntries = 0; protected $accessToken; + private $translator; public function __construct(TokenStorageInterface $tokenStorage, EntityManager $em, ContentProxy $contentProxy, $consumerKey) { @@ -45,12 +47,20 @@ class PocketImport implements ImportInterface return 'Pocket'; } + /** + * {@inheritdoc} + */ + public function getUrl() + { + return 'import_pocket'; + } + /** * {@inheritdoc} */ public function getDescription() { - return 'This importer will import all your Pocket data.'; + return '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.'; } /** @@ -141,7 +151,7 @@ class PocketImport implements ImportInterface $entries = $response->json(); - $this->parsePocketEntries($entries['list']); + $this->parseEntries($entries['list']); return true; } @@ -176,13 +186,14 @@ class PocketImport implements ImportInterface $label = trim($tag['tag']); $tagEntity = $this->em ->getRepository('WallabagCoreBundle:Tag') - ->findOneByLabelAndUserId($label, $this->user->getId()); + ->findOneByLabel($label); if (is_object($tagEntity)) { $entry->addTag($tagEntity); } else { - $newTag = new Tag($this->user); + $newTag = new Tag(); $newTag->setLabel($label); + $entry->addTag($newTag); } $this->em->flush(); @@ -194,22 +205,23 @@ class PocketImport implements ImportInterface * * @param $entries */ - private function parsePocketEntries($entries) + private function parseEntries($entries) { - foreach ($entries as $pocketEntry) { - $entry = new Entry($this->user); + $i = 1; + foreach ($entries as $pocketEntry) { $url = isset($pocketEntry['resolved_url']) && $pocketEntry['resolved_url'] != '' ? $pocketEntry['resolved_url'] : $pocketEntry['given_url']; $existingEntry = $this->em ->getRepository('WallabagCoreBundle:Entry') - ->existByUrlAndUserId($url, $this->user->getId()); + ->findByUrlAndUserId($url, $this->user->getId()); if (false !== $existingEntry) { ++$this->skippedEntries; continue; } + $entry = new Entry($this->user); $entry = $this->contentProxy->updateEntry($entry, $url); // 0, 1, 2 - 1 if the item is archived - 2 if the item should be deleted @@ -242,6 +254,12 @@ class PocketImport implements ImportInterface $this->em->persist($entry); ++$this->importedEntries; + + // flush every 20 entries + if (($i % 20) === 0) { + $this->em->flush(); + } + ++$i; } $this->em->flush();