]> git.immae.eu Git - github/wallabag/wallabag.git/blob - src/Wallabag/ImportBundle/Import/WallabagV2Import.php
0a32864eb04ae16a7efaa0c188fe860343f6d3e3
[github/wallabag/wallabag.git] / src / Wallabag / ImportBundle / Import / WallabagV2Import.php
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 {
30 return 'import.wallabag_v2.description';
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
50 // @see ContentProxy->updateEntry
51 $entry = new Entry($this->user);
52 $entry->setUrl($importedEntry['url']);
53 $entry->setTitle($importedEntry['title']);
54 $entry->setArchived($importedEntry['is_archived'] || $this->markAsRead);
55 $entry->setStarred($importedEntry['is_starred']);
56 $entry->setContent($importedEntry['content']);
57 $entry->setReadingTime($importedEntry['reading_time']);
58 $entry->setDomainName($importedEntry['domain_name']);
59 if (isset($importedEntry['mimetype'])) {
60 $entry->setMimetype($importedEntry['mimetype']);
61 }
62 if (isset($importedEntry['language'])) {
63 $entry->setLanguage($importedEntry['language']);
64 }
65 if (isset($importedEntry['preview_picture'])) {
66 $entry->setPreviewPicture($importedEntry['preview_picture']);
67 }
68
69 $this->em->persist($entry);
70 ++$this->importedEntries;
71
72 // flush every 20 entries
73 if (($i % 20) === 0) {
74 $this->em->flush();
75 }
76 ++$i;
77 }
78
79 $this->em->flush();
80 }
81 }