3 namespace Wallabag\ImportBundle\Import
;
5 use Wallabag\CoreBundle\Entity\Entry
;
7 abstract class WallabagImport
extends AbstractImport
10 // untitled in all languages from v1
11 protected $untitled = [
29 abstract public function getName();
34 abstract public function getUrl();
39 abstract public function getDescription();
44 public function import()
47 $this->logger
->error('WallabagImport: user is not defined');
52 if (!file_exists($this->filepath
) || !is_readable($this->filepath
)) {
53 $this->logger
->error('WallabagImport: unable to read file', ['filepath' => $this->filepath
]);
58 $data = json_decode(file_get_contents($this->filepath
), true);
64 if ($this->producer
) {
65 $this->parseEntriesForProducer($data);
70 $this->parseEntries($data);
78 public function getSummary()
81 'skipped' => $this->skippedEntries
,
82 'imported' => $this->importedEntries
,
87 * Set file path to the json file.
89 * @param string $filepath
91 public function setFilepath($filepath)
93 $this->filepath
= $filepath;
101 public function parseEntry(array $importedEntry)
103 $existingEntry = $this->em
104 ->getRepository('WallabagCoreBundle:Entry')
105 ->findByUrlAndUserId($importedEntry['url'], $this->user
->getId());
107 if (false !== $existingEntry) {
108 ++
$this->skippedEntries
;
113 $data = $this->prepareEntry($importedEntry);
115 $entry = $this->fetchContent(
116 new Entry($this->user
),
117 $importedEntry['url'],
121 // jump to next entry in case of problem while getting content
122 if (false === $entry) {
123 ++
$this->skippedEntries
;
128 if (array_key_exists('tags', $data)) {
129 $this->contentProxy
->assignTagsToEntry(
135 if (isset($importedEntry['preview_picture'])) {
136 $entry->setPreviewPicture($importedEntry['preview_picture']);
139 $entry->setArchived($data['is_archived']);
140 $entry->setStarred($data['is_starred']);
142 if (!empty($data['created_at'])) {
143 $entry->setCreatedAt(new \
DateTime($data['created_at']));
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 = []);