3 namespace Wallabag\ImportBundle\Import
;
5 use Wallabag\CoreBundle\Entity\Entry
;
6 use Wallabag\UserBundle\Entity\User
;
8 abstract class WallabagImport
extends AbstractImport
11 protected $skippedEntries = 0;
12 protected $importedEntries = 0;
14 // untitled in all languages from v1
15 protected $untitled = [
33 abstract public function getName();
38 abstract public function getUrl();
43 abstract public function getDescription();
48 public function import()
51 $this->logger
->error('WallabagImport: user is not defined');
56 if (!file_exists($this->filepath
) || !is_readable($this->filepath
)) {
57 $this->logger
->error('WallabagImport: unable to read file', ['filepath' => $this->filepath
]);
62 $data = json_decode(file_get_contents($this->filepath
), true);
68 if ($this->producer
) {
69 $this->parseEntriesForProducer($data);
74 $this->parseEntries($data);
82 public function getSummary()
85 'skipped' => $this->skippedEntries
,
86 'imported' => $this->importedEntries
,
91 * Set file path to the json file.
93 * @param string $filepath
95 public function setFilepath($filepath)
97 $this->filepath
= $filepath;
105 public function parseEntry(array $importedEntry)
107 $existingEntry = $this->em
108 ->getRepository('WallabagCoreBundle:Entry')
109 ->findByUrlAndUserId($importedEntry['url'], $this->user
->getId());
111 if (false !== $existingEntry) {
112 ++
$this->skippedEntries
;
117 $data = $this->prepareEntry($importedEntry);
119 $entry = $this->fetchContent(
120 new Entry($this->user
),
121 $importedEntry['url'],
125 // jump to next entry in case of problem while getting content
126 if (false === $entry) {
127 ++
$this->skippedEntries
;
132 if (array_key_exists('tags', $data)) {
133 $this->contentProxy
->assignTagsToEntry(
139 if (isset($importedEntry['preview_picture'])) {
140 $entry->setPreviewPicture($importedEntry['preview_picture']);
143 $entry->setArchived($data['is_archived']);
144 $entry->setStarred($data['is_starred']);
146 $this->em
->persist($entry);
147 ++
$this->importedEntries
;
153 * This should return a cleaned array for a given entry to be given to `updateEntry`.
155 * @param array $entry Data from the imported file
159 abstract protected function prepareEntry($entry = []);