3 namespace Wallabag\ImportBundle\Import
;
5 use Wallabag\CoreBundle\Entity\Entry
;
7 class ReadabilityImport
extends AbstractImport
9 private $skippedEntries = 0;
10 private $importedEntries = 0;
16 public function getName()
24 public function getUrl()
26 return 'import_readability';
32 public function getDescription()
34 return 'import.readability.description';
38 * Set file path to the json file.
40 * @param string $filepath
42 public function setFilepath($filepath)
44 $this->filepath
= $filepath;
52 public function getSummary()
55 'skipped' => $this->skippedEntries
,
56 'imported' => $this->importedEntries
,
63 public function import()
66 $this->logger
->error('ReadabilityImport: user is not defined');
71 if (!file_exists($this->filepath
) || !is_readable($this->filepath
)) {
72 $this->logger
->error('ReadabilityImport: unable to read file', ['filepath' => $this->filepath
]);
77 $data = json_decode(file_get_contents($this->filepath
), true);
79 if (empty($data) || empty($data['bookmarks'])) {
83 if ($this->producer
) {
84 $this->parseEntriesForProducer($data['bookmarks']);
89 $this->parseEntries($data['bookmarks']);
94 public function parseEntry(array $importedEntry)
96 $existingEntry = $this->em
97 ->getRepository('WallabagCoreBundle:Entry')
98 ->findByUrlAndUserId($importedEntry['article__url'], $this->user
->getId());
100 if (false !== $existingEntry) {
101 ++
$this->skippedEntries
;
107 'title' => $importedEntry['article__title'],
108 'url' => $importedEntry['article__url'],
109 'content_type' => '',
111 'is_archived' => $importedEntry['archive'] || $this->markAsRead
,
112 'is_starred' => $importedEntry['favorite'],
115 $entry = $this->fetchContent(
116 new Entry($this->user
),
121 // jump to next entry in case of problem while getting content
122 if (false === $entry) {
123 ++
$this->skippedEntries
;
128 $entry->setArchived($data['is_archived']);
129 $entry->setStarred($data['is_starred']);
131 $this->em
->persist($entry);
132 ++
$this->importedEntries
;
140 protected function setEntryAsRead(array $importedEntry)
142 $importedEntry['archive'] = 1;
144 return $importedEntry;