3 namespace Wallabag\ImportBundle\Import
;
5 use Wallabag\CoreBundle\Entity\Entry
;
7 class InstapaperImport
extends AbstractImport
14 public function getName()
22 public function getUrl()
24 return 'import_instapaper';
30 public function getDescription()
32 return 'import.instapaper.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('InstapaperImport: user is not defined');
58 if (!file_exists($this->filepath
) || !is_readable($this->filepath
)) {
59 $this->logger
->error('InstapaperImport: unable to read file', ['filepath' => $this->filepath
]);
65 $handle = fopen($this->filepath
, 'r');
66 while (false !== ($data = fgetcsv($handle, 10240))) {
67 if ('URL' === $data[0]) {
71 // last element in the csv is the folder where the content belong
72 // BUT it can also be the status (since status = folder in Instapaper)
73 // and we don't want archive, unread & starred to become a tag
75 if (false === in_array($data[3], ['Archive', 'Unread', 'Starred'], true)) {
83 'is_archived' => 'Archive' === $data[3] || 'Starred' === $data[3],
84 'is_starred' => 'Starred' === $data[3],
91 if (empty($entries)) {
92 $this->logger
->error('InstapaperImport: no entries in imported file');
97 if ($this->producer
) {
98 $this->parseEntriesForProducer($entries);
103 $this->parseEntries($entries);
111 public function parseEntry(array $importedEntry)
113 $existingEntry = $this->em
114 ->getRepository('WallabagCoreBundle:Entry')
115 ->findByUrlAndUserId($importedEntry['url'], $this->user
->getId());
117 if (false !== $existingEntry) {
118 ++
$this->skippedEntries
;
123 $entry = new Entry($this->user
);
124 $entry->setUrl($importedEntry['url']);
125 $entry->setTitle($importedEntry['title']);
127 // update entry with content (in case fetching failed, the given entry will be return)
128 $this->fetchContent($entry, $importedEntry['url'], $importedEntry);
130 if (!empty($importedEntry['tags'])) {
131 $this->tagsAssigner
->assignTagsToEntry(
133 $importedEntry['tags'],
134 $this->em
->getUnitOfWork()->getScheduledEntityInsertions()
138 $entry->setArchived($importedEntry['is_archived']);
139 $entry->setStarred($importedEntry['is_starred']);
141 $this->em
->persist($entry);
142 ++
$this->importedEntries
;
150 protected function setEntryAsRead(array $importedEntry)
152 $importedEntry['is_archived'] = 1;
154 return $importedEntry;