+ return true;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getSummary()
+ {
+ return [
+ 'skipped' => $this->skippedEntries,
+ 'imported' => $this->importedEntries,
+ ];
+ }
+
+ /**
+ * Set the Guzzle client.
+ *
+ * @param Client $client
+ */
+ public function setClient(Client $client)
+ {
+ $this->client = $client;
+ }
+
+ /**
+ * @see https://getpocket.com/developer/docs/v3/retrieve
+ *
+ * @param $entries
+ */
+ private function parseEntries($entries)
+ {
+ $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')
+ ->findByUrlAndUserId($url, $this->user->getId());
+
+ if (false !== $existingEntry) {
+ ++$this->skippedEntries;
+ continue;
+ }
+
+ $entry = new Entry($this->user);
+
+ if (!$this->rabbitMQ) {
+ $entry = $this->fetchContent($entry, $url);
+
+ // jump to next entry in case of problem while getting content
+ if (false === $entry) {
+ ++$this->skippedEntries;
+ continue;
+ }
+ }
+
+ // 0, 1, 2 - 1 if the item is archived - 2 if the item should be deleted
+ if ($pocketEntry['status'] == 1 || $this->markAsRead) {
+ $entry->setArchived(true);
+ }
+
+ // 0 or 1 - 1 If the item is starred
+ if ($pocketEntry['favorite'] == 1) {
+ $entry->setStarred(true);
+ }
+
+ $title = 'Untitled';
+ if (isset($pocketEntry['resolved_title']) && $pocketEntry['resolved_title'] != '') {
+ $title = $pocketEntry['resolved_title'];
+ } elseif (isset($pocketEntry['given_title']) && $pocketEntry['given_title'] != '') {
+ $title = $pocketEntry['given_title'];
+ }
+
+ $entry->setTitle($title);
+ $entry->setUrl($url);
+
+ // 0, 1, or 2 - 1 if the item has images in it - 2 if the item is an image
+ if (isset($pocketEntry['has_image']) && $pocketEntry['has_image'] > 0 && isset($pocketEntry['images'][1])) {
+ $entry->setPreviewPicture($pocketEntry['images'][1]['src']);
+ }
+
+ if (isset($pocketEntry['tags']) && !empty($pocketEntry['tags'])) {
+ $this->contentProxy->assignTagsToEntry(
+ $entry,
+ array_keys($pocketEntry['tags'])
+ );
+ }
+
+ $pocketEntry['url'] = $url;
+ $pocketEntry['userId'] = $this->user->getId();
+
+ $this->em->persist($entry);
+ ++$this->importedEntries;
+
+ // flush every 20 entries
+ if (($i % 20) === 0) {
+ $this->em->flush();
+ }
+
+ ++$i;
+ }
+
+ $this->em->flush();
+
+ if ($this->rabbitMQ) {
+ foreach ($entries as $entry) {
+ $this->producer->publish(serialize($entry));
+ }
+ }