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 import()
53 $this->logger
->error('ReadabilityImport: user is not defined');
58 if (!file_exists($this->filepath
) || !is_readable($this->filepath
)) {
59 $this->logger
->error('ReadabilityImport: unable to read file', ['filepath' => $this->filepath
]);
64 $data = json_decode(file_get_contents($this->filepath
), true);
66 if (empty($data) || empty($data['bookmarks'])) {
70 if ($this->producer
) {
71 $this->parseEntriesForProducer($data['bookmarks']);
76 $this->parseEntries($data['bookmarks']);
84 public function parseEntry(array $importedEntry)
86 $existingEntry = $this->em
87 ->getRepository('WallabagCoreBundle:Entry')
88 ->findByUrlAndUserId($importedEntry['article__url'], $this->user
->getId());
90 if (false !== $existingEntry) {
91 ++
$this->skippedEntries
;
97 'title' => $importedEntry['article__title'],
98 'url' => $importedEntry['article__url'],
101 'is_archived' => $importedEntry['archive'] || $this->markAsRead
,
102 'is_starred' => $importedEntry['favorite'],
103 'created_at' => $importedEntry['date_added'],
106 $entry = new Entry($this->user
);
107 $entry->setUrl($data['url']);
108 $entry->setTitle($data['title']);
110 // update entry with content (in case fetching failed, the given entry will be return)
111 $entry = $this->fetchContent($entry, $data['url'], $data);
113 $entry->setArchived($data['is_archived']);
114 $entry->setStarred($data['is_starred']);
115 $entry->setCreatedAt(new \
DateTime($data['created_at']));
117 $this->em
->persist($entry);
118 ++
$this->importedEntries
;
126 protected function setEntryAsRead(array $importedEntry)
128 $importedEntry['archive'] = 1;
130 return $importedEntry;