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 parseEntry(array $importedEntry)
94 $existingEntry = $this->em
95 ->getRepository('WallabagCoreBundle:Entry')
96 ->findByUrlAndUserId($importedEntry['url'], $this->user
->getId());
98 if (false !== $existingEntry) {
99 ++
$this->skippedEntries
;
104 $data = $this->prepareEntry($importedEntry);
106 $entry = new Entry($this->user
);
107 $entry->setUrl($data['url']);
108 $entry->setTitle($data['title']);
110 // update entry with content (in case fetching failed, the given entry will be return)
111 $this->fetchContent($entry, $data['url'], $data);
113 if (array_key_exists('tags', $data)) {
114 $this->tagsAssigner
->assignTagsToEntry(
117 $this->em
->getUnitOfWork()->getScheduledEntityInsertions()
121 if (isset($importedEntry['preview_picture'])) {
122 $entry->setPreviewPicture($importedEntry['preview_picture']);
125 $entry->setArchived($data['is_archived']);
126 $entry->setStarred($data['is_starred']);
128 if (!empty($data['created_at'])) {
129 $entry->setCreatedAt(new \
DateTime($data['created_at']));
132 $this->em
->persist($entry);
133 ++
$this->importedEntries
;
139 * This should return a cleaned array for a given entry to be given to `updateEntry`.
141 * @param array $entry Data from the imported file
145 abstract protected function prepareEntry($entry = []);