- $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);
- $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 || $this->markAsRead) {
- $entry->setArchived(true);
- }
-
- // 0 or 1 - 1 If the item is favorited
- 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);
-
- // 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'])
- );
- }
-
- $this->em->persist($entry);
- ++$this->importedEntries;
-
- // flush every 20 entries
- if (($i % 20) === 0) {
- $this->em->flush();
- }
- ++$i;
+ $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)
+ $this->fetchContent($entry, $url);
+
+ // 0, 1, 2 - 1 if the item is archived - 2 if the item should be deleted
+ $entry->setArchived(1 === $importedEntry['status'] || $this->markAsRead);
+
+ // 0 or 1 - 1 If the item is starred
+ $entry->setStarred(1 === $importedEntry['favorite']);
+
+ $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->tagsAssigner->assignTagsToEntry(
+ $entry,
+ array_keys($importedEntry['tags']),
+ $this->em->getUnitOfWork()->getScheduledEntityInsertions()
+ );