3 namespace Wallabag\ImportBundle\Import
;
5 use Wallabag\CoreBundle\Entity\Entry
;
7 class PinboardImport
extends AbstractImport
14 public function getName()
22 public function getUrl()
24 return 'import_pinboard';
30 public function getDescription()
32 return 'import.pinboard.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('PinboardImport: user is not defined');
58 if (!file_exists($this->filepath
) || !is_readable($this->filepath
)) {
59 $this->logger
->error('PinboardImport: unable to read file', ['filepath' => $this->filepath
]);
64 $data = json_decode(file_get_contents($this->filepath
), true);
67 $this->logger
->error('PinboardImport: no entries in imported file');
72 if ($this->producer
) {
73 $this->parseEntriesForProducer($data);
78 $this->parseEntries($data);
86 public function parseEntry(array $importedEntry)
88 $existingEntry = $this->em
89 ->getRepository('WallabagCoreBundle:Entry')
90 ->findByUrlAndUserId($importedEntry['href'], $this->user
->getId());
92 if (false !== $existingEntry) {
93 ++
$this->skippedEntries
;
99 'title' => $importedEntry['description'],
100 'url' => $importedEntry['href'],
101 'content_type' => '',
103 'is_archived' => ('no' === $importedEntry['toread']) || $this->markAsRead
,
104 'is_starred' => false,
105 'created_at' => $importedEntry['time'],
106 'tags' => explode(' ', $importedEntry['tags']),
109 $entry = new Entry($this->user
);
110 $entry->setUrl($data['url']);
111 $entry->setTitle($data['title']);
113 // update entry with content (in case fetching failed, the given entry will be return)
114 $entry = $this->fetchContent($entry, $data['url'], $data);
116 if (!empty($data['tags'])) {
117 $this->contentProxy
->assignTagsToEntry(
120 $this->em
->getUnitOfWork()->getScheduledEntityInsertions()
124 $entry->setArchived($data['is_archived']);
125 $entry->setStarred($data['is_starred']);
126 $entry->setCreatedAt(new \
DateTime($data['created_at']));
128 $this->em
->persist($entry);
129 ++
$this->importedEntries
;
137 protected function setEntryAsRead(array $importedEntry)
139 $importedEntry['toread'] = 'no';
141 return $importedEntry;