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);
61 $this->logger
->error('WallabagImport: no entries in imported file');
66 if ($this->producer
) {
67 $this->parseEntriesForProducer($data);
72 $this->parseEntries($data);
78 * Set file path to the json file.
80 * @param string $filepath
82 public function setFilepath($filepath)
84 $this->filepath
= $filepath;
92 public function validateEntry(array $importedEntry)
94 if (empty($importedEntry['url'])) {
104 public function parseEntry(array $importedEntry)
106 $existingEntry = $this->em
107 ->getRepository('WallabagCoreBundle:Entry')
108 ->findByUrlAndUserId($importedEntry['url'], $this->user
->getId());
110 if (false !== $existingEntry) {
111 ++
$this->skippedEntries
;
116 $data = $this->prepareEntry($importedEntry);
118 $entry = new Entry($this->user
);
119 $entry->setUrl($data['url']);
120 $entry->setTitle($data['title']);
122 // update entry with content (in case fetching failed, the given entry will be return)
123 $this->fetchContent($entry, $data['url'], $data);
125 if (array_key_exists('tags', $data)) {
126 $this->tagsAssigner
->assignTagsToEntry(
129 $this->em
->getUnitOfWork()->getScheduledEntityInsertions()
133 if (isset($importedEntry['preview_picture'])) {
134 $entry->setPreviewPicture($importedEntry['preview_picture']);
137 $entry->updateArchived($data['is_archived']);
138 $entry->setStarred($data['is_starred']);
140 if (!empty($data['created_at'])) {
141 $entry->setCreatedAt(new \
DateTime($data['created_at']));
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 = []);