+ // if we retrieve exactly the amount of items requested it means we can get more
+ // re-call import and offset item by the amount previous received:
+ // - first call get 5k offset 0
+ // - second call get 5k offset 5k
+ // - and so on
+ if (count($entries['list']) === self::NB_ELEMENTS) {
+ ++$run;
+
+ return $this->import(self::NB_ELEMENTS * $run);
+ }
+
+ return true;
+ }
+
+ /**
+ * Set the Guzzle client.
+ *
+ * @param Client $client
+ */
+ public function setClient(Client $client)
+ {
+ $this->client = $client;
+ }
+
+ /**
+ * {@inheritdoc}
+ *
+ * @see https://getpocket.com/developer/docs/v3/retrieve
+ */
+ public function parseEntry(array $importedEntry)
+ {
+ $url = isset($importedEntry['resolved_url']) && $importedEntry['resolved_url'] != '' ? $importedEntry['resolved_url'] : $importedEntry['given_url'];
+
+ $existingEntry = $this->em
+ ->getRepository('WallabagCoreBundle:Entry')
+ ->findByUrlAndUserId($url, $this->user->getId());
+
+ if (false !== $existingEntry) {
+ ++$this->skippedEntries;
+
+ return;
+ }
+
+ $entry = new Entry($this->user);
+ $entry->setUrl($url);
+
+ // update entry with content (in case fetching failed, the given entry will be return)
+ $entry = $this->fetchContent($entry, $url);
+
+ // 0, 1, 2 - 1 if the item is archived - 2 if the item should be deleted
+ $entry->setArchived($importedEntry['status'] == 1 || $this->markAsRead);
+
+ // 0 or 1 - 1 If the item is starred
+ $entry->setStarred($importedEntry['favorite'] == 1);
+
+ $title = 'Untitled';
+ if (isset($importedEntry['resolved_title']) && $importedEntry['resolved_title'] != '') {
+ $title = $importedEntry['resolved_title'];
+ } elseif (isset($importedEntry['given_title']) && $importedEntry['given_title'] != '') {
+ $title = $importedEntry['given_title'];
+ }
+
+ $entry->setTitle($title);
+
+ // 0, 1, or 2 - 1 if the item has images in it - 2 if the item is an image
+ if (isset($importedEntry['has_image']) && $importedEntry['has_image'] > 0 && isset($importedEntry['images'][1])) {
+ $entry->setPreviewPicture($importedEntry['images'][1]['src']);
+ }
+
+ if (isset($importedEntry['tags']) && !empty($importedEntry['tags'])) {
+ $this->contentProxy->assignTagsToEntry(
+ $entry,
+ array_keys($importedEntry['tags']),
+ $this->em->getUnitOfWork()->getScheduledEntityInsertions()
+ );
+ }
+
+ if (!empty($importedEntry['time_added'])) {
+ $entry->setCreatedAt((new \DateTime())->setTimestamp($importedEntry['time_added']));
+ }
+
+ $this->em->persist($entry);
+ ++$this->importedEntries;
+
+ return $entry;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function setEntryAsRead(array $importedEntry)
+ {
+ $importedEntry['status'] = '1';
+
+ return $importedEntry;