3 namespace Wallabag\ImportBundle\Import
;
5 use Wallabag\CoreBundle\Entity\Entry
;
7 class ReadabilityImport
extends AbstractImport
14 public function getName()
22 public function getUrl()
24 return 'import_readability';
30 public function getDescription()
32 return 'import.readability.description';
36 * Set file path to the json file.
38 * @param string $filepath
40 public function setFilepath($filepath)
42 $this->filepath
= $filepath;
50 public function getSummary()
53 'skipped' => $this->skippedEntries
,
54 'imported' => $this->importedEntries
,
61 public function import()
64 $this->logger
->error('ReadabilityImport: user is not defined');
69 if (!file_exists($this->filepath
) || !is_readable($this->filepath
)) {
70 $this->logger
->error('ReadabilityImport: unable to read file', ['filepath' => $this->filepath
]);
75 $data = json_decode(file_get_contents($this->filepath
), true);
77 if (empty($data) || empty($data['bookmarks'])) {
81 if ($this->producer
) {
82 $this->parseEntriesForProducer($data['bookmarks']);
87 $this->parseEntries($data['bookmarks']);
92 public function parseEntry(array $importedEntry)
94 $existingEntry = $this->em
95 ->getRepository('WallabagCoreBundle:Entry')
96 ->findByUrlAndUserId($importedEntry['article__url'], $this->user
->getId());
98 if (false !== $existingEntry) {
99 ++
$this->skippedEntries
;
105 'title' => $importedEntry['article__title'],
106 'url' => $importedEntry['article__url'],
107 'content_type' => '',
109 'is_archived' => $importedEntry['archive'] || $this->markAsRead
,
110 'is_starred' => $importedEntry['favorite'],
113 $entry = $this->fetchContent(
114 new Entry($this->user
),
119 // jump to next entry in case of problem while getting content
120 if (false === $entry) {
121 ++
$this->skippedEntries
;
126 $entry->setArchived($data['is_archived']);
127 $entry->setStarred($data['is_starred']);
129 $this->em
->persist($entry);
130 ++
$this->importedEntries
;
138 protected function setEntryAsRead(array $importedEntry)
140 $importedEntry['archive'] = 1;
142 return $importedEntry;