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 = $this->fetchContent(
105 new Entry($this->user
),
106 $importedEntry['url'],
110 // jump to next entry in case of problem while getting content
111 if (false === $entry) {
112 ++
$this->skippedEntries
;
117 if (array_key_exists('tags', $data)) {
118 $this->contentProxy
->assignTagsToEntry(
124 if (isset($importedEntry['preview_picture'])) {
125 $entry->setPreviewPicture($importedEntry['preview_picture']);
128 $entry->setArchived($data['is_archived']);
129 $entry->setStarred($data['is_starred']);
131 if (!empty($data['created_at'])) {
132 $entry->setCreatedAt(new \
DateTime($data['created_at']));
135 $this->em
->persist($entry);
136 ++
$this->importedEntries
;
142 * This should return a cleaned array for a given entry to be given to `updateEntry`.
144 * @param array $entry Data from the imported file
148 abstract protected function prepareEntry($entry = []);