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);
76 * Set file path to the json file.
78 * @param string $filepath
80 public function setFilepath($filepath)
82 $this->filepath
= $filepath;
90 public function parseEntry(array $importedEntry)
92 $existingEntry = $this->em
93 ->getRepository('WallabagCoreBundle:Entry')
94 ->findByUrlAndUserId($importedEntry['url'], $this->user
->getId());
96 if (false !== $existingEntry) {
97 ++
$this->skippedEntries
;
102 $data = $this->prepareEntry($importedEntry);
104 $entry = new Entry($this->user
);
105 $entry->setUrl($data['url']);
106 $entry->setTitle($data['title']);
108 // update entry with content (in case fetching failed, the given entry will be return)
109 $entry = $this->fetchContent($entry, $data['url'], $data);
111 if (array_key_exists('tags', $data)) {
112 $this->contentProxy
->assignTagsToEntry(
115 $this->em
->getUnitOfWork()->getScheduledEntityInsertions()
119 if (isset($importedEntry['preview_picture'])) {
120 $entry->setPreviewPicture($importedEntry['preview_picture']);
123 $entry->setArchived($data['is_archived']);
124 $entry->setStarred($data['is_starred']);
126 if (!empty($data['created_at'])) {
127 $entry->setCreatedAt(new \
DateTime($data['created_at']));
130 $this->em
->persist($entry);
131 ++
$this->importedEntries
;
137 * This should return a cleaned array for a given entry to be given to `updateEntry`.
139 * @param array $entry Data from the imported file
143 abstract protected function prepareEntry($entry = []);