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']);
95 public function parseEntry(array $importedEntry)
97 $existingEntry = $this->em
98 ->getRepository('WallabagCoreBundle:Entry')
99 ->findByUrlAndUserId($importedEntry['article__url'], $this->user
->getId());
101 if (false !== $existingEntry) {
102 ++
$this->skippedEntries
;
108 'title' => $importedEntry['article__title'],
109 'url' => $importedEntry['article__url'],
110 'content_type' => '',
112 'is_archived' => $importedEntry['archive'] || $this->markAsRead
,
113 'is_starred' => $importedEntry['favorite'],
114 'created_at' => $importedEntry['date_added'],
117 $entry = $this->fetchContent(
118 new Entry($this->user
),
123 // jump to next entry in case of problem while getting content
124 if (false === $entry) {
125 ++
$this->skippedEntries
;
130 $entry->setArchived($data['is_archived']);
131 $entry->setStarred($data['is_starred']);
132 $entry->setCreatedAt(new \
DateTime($data['created_at']));
134 $this->em
->persist($entry);
135 ++
$this->importedEntries
;
143 protected function setEntryAsRead(array $importedEntry)
145 $importedEntry['archive'] = 1;
147 return $importedEntry;