]>
Commit | Line | Data |
---|---|---|
6785f4aa NL |
1 | <?php |
2 | ||
3 | namespace Wallabag\ImportBundle\Import; | |
4 | ||
5 | use Wallabag\CoreBundle\Entity\Entry; | |
6 | ||
7 | class WallabagV2Import extends WallabagV1Import implements ImportInterface | |
8 | { | |
9 | /** | |
10 | * {@inheritdoc} | |
11 | */ | |
12 | public function getName() | |
13 | { | |
14 | return 'wallabag v2'; | |
15 | } | |
16 | ||
17 | /** | |
18 | * {@inheritdoc} | |
19 | */ | |
20 | public function getUrl() | |
21 | { | |
22 | return 'import_wallabag_v2'; | |
23 | } | |
24 | ||
25 | /** | |
26 | * {@inheritdoc} | |
27 | */ | |
28 | public function getDescription() | |
29 | { | |
0d42217e | 30 | return 'import.wallabag_v2.description'; |
6785f4aa NL |
31 | } |
32 | ||
33 | /** | |
34 | * @param $entries | |
35 | */ | |
36 | protected function parseEntries($entries) | |
37 | { | |
38 | $i = 1; | |
39 | ||
40 | foreach ($entries as $importedEntry) { | |
41 | $existingEntry = $this->em | |
42 | ->getRepository('WallabagCoreBundle:Entry') | |
43 | ->findByUrlAndUserId($importedEntry['url'], $this->user->getId()); | |
44 | ||
45 | if (false !== $existingEntry) { | |
46 | ++$this->skippedEntries; | |
47 | continue; | |
48 | } | |
49 | ||
8f336fda JB |
50 | $importedEntry['html'] = $importedEntry['content']; |
51 | $importedEntry['content_type'] = $importedEntry['mimetype']; | |
52 | ||
53 | $entry = $this->contentProxy->updateEntry( | |
54 | new Entry($this->user), | |
55 | $importedEntry['url'], | |
56 | $importedEntry | |
57 | ); | |
58 | ||
59 | if (array_key_exists('tags', $importedEntry) && !empty($importedEntry['tags'])) { | |
60 | $this->contentProxy->assignTagsToEntry( | |
61 | $entry, | |
62 | $importedEntry['tags'] | |
63 | ); | |
de3b19b2 | 64 | } |
8f336fda | 65 | |
de3b19b2 NL |
66 | if (isset($importedEntry['preview_picture'])) { |
67 | $entry->setPreviewPicture($importedEntry['preview_picture']); | |
68 | } | |
6785f4aa | 69 | |
8f336fda JB |
70 | $entry->setArchived($importedEntry['is_archived'] || $this->markAsRead); |
71 | $entry->setStarred($importedEntry['is_starred']); | |
72 | ||
6785f4aa NL |
73 | $this->em->persist($entry); |
74 | ++$this->importedEntries; | |
75 | ||
76 | // flush every 20 entries | |
77 | if (($i % 20) === 0) { | |
78 | $this->em->flush(); | |
79 | } | |
80 | ++$i; | |
81 | } | |
82 | ||
83 | $this->em->flush(); | |
84 | } | |
85 | } |