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 (($data = fgetcsv($handle, 10240)) !== false) {
67 if ('URL' === $data[0]) {
75 'is_archived' => $data[3] === 'Archive' || $data[3] === 'Starred',
76 'is_starred' => $data[3] === 'Starred',
83 if (empty($entries)) {
84 $this->logger
->error('InstapaperImport: no entries in imported file');
89 if ($this->producer
) {
90 $this->parseEntriesForProducer($entries);
95 $this->parseEntries($entries);
103 public function parseEntry(array $importedEntry)
105 $existingEntry = $this->em
106 ->getRepository('WallabagCoreBundle:Entry')
107 ->findByUrlAndUserId($importedEntry['url'], $this->user
->getId());
109 if (false !== $existingEntry) {
110 ++
$this->skippedEntries
;
115 $entry = new Entry($this->user
);
116 $entry->setUrl($importedEntry['url']);
117 $entry->setTitle($importedEntry['title']);
119 // update entry with content (in case fetching failed, the given entry will be return)
120 $entry = $this->fetchContent($entry, $importedEntry['url'], $importedEntry);
122 $entry->setArchived($importedEntry['is_archived']);
123 $entry->setStarred($importedEntry['is_starred']);
125 $this->em
->persist($entry);
126 ++
$this->importedEntries
;
134 protected function setEntryAsRead(array $importedEntry)
136 $importedEntry['is_archived'] = 1;
138 return $importedEntry;