3 namespace Wallabag\ImportBundle\Import
;
5 use Wallabag\CoreBundle\Entity\Entry
;
7 abstract class WallabagImport
extends AbstractImport
9 protected $skippedEntries = 0;
10 protected $importedEntries = 0;
12 // untitled in all languages from v1
13 protected $untitled = [
31 abstract public function getName();
36 abstract public function getUrl();
41 abstract public function getDescription();
46 public function import()
49 $this->logger
->error('WallabagImport: user is not defined');
54 if (!file_exists($this->filepath
) || !is_readable($this->filepath
)) {
55 $this->logger
->error('WallabagImport: unable to read file', ['filepath' => $this->filepath
]);
60 $data = json_decode(file_get_contents($this->filepath
), true);
66 if ($this->producer
) {
67 $this->parseEntriesForProducer($data);
72 $this->parseEntries($data);
80 public function getSummary()
83 'skipped' => $this->skippedEntries
,
84 'imported' => $this->importedEntries
,
89 * Set file path to the json file.
91 * @param string $filepath
93 public function setFilepath($filepath)
95 $this->filepath
= $filepath;
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 $data = $this->prepareEntry($importedEntry);
117 $entry = $this->fetchContent(
118 new Entry($this->user
),
119 $importedEntry['url'],
123 // jump to next entry in case of problem while getting content
124 if (false === $entry) {
125 ++
$this->skippedEntries
;
130 if (array_key_exists('tags', $data)) {
131 $this->contentProxy
->assignTagsToEntry(
137 if (isset($importedEntry['preview_picture'])) {
138 $entry->setPreviewPicture($importedEntry['preview_picture']);
141 $entry->setArchived($data['is_archived']);
142 $entry->setStarred($data['is_starred']);
144 $this->em
->persist($entry);
145 ++
$this->importedEntries
;
151 * This should return a cleaned array for a given entry to be given to `updateEntry`.
153 * @param array $entry Data from the imported file
157 abstract protected function prepareEntry($entry = []);