aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/ImportBundle/Import/WallabagV2Import.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/Wallabag/ImportBundle/Import/WallabagV2Import.php')
-rw-r--r--src/Wallabag/ImportBundle/Import/WallabagV2Import.php57
1 files changed, 9 insertions, 48 deletions
diff --git a/src/Wallabag/ImportBundle/Import/WallabagV2Import.php b/src/Wallabag/ImportBundle/Import/WallabagV2Import.php
index c4bac561..d0035b63 100644
--- a/src/Wallabag/ImportBundle/Import/WallabagV2Import.php
+++ b/src/Wallabag/ImportBundle/Import/WallabagV2Import.php
@@ -2,9 +2,7 @@
2 2
3namespace Wallabag\ImportBundle\Import; 3namespace Wallabag\ImportBundle\Import;
4 4
5use Wallabag\CoreBundle\Entity\Entry; 5class WallabagV2Import extends WallabagImport
6
7class WallabagV2Import extends WallabagV1Import implements ImportInterface
8{ 6{
9 /** 7 /**
10 * {@inheritdoc} 8 * {@inheritdoc}
@@ -27,55 +25,18 @@ class WallabagV2Import extends WallabagV1Import implements ImportInterface
27 */ 25 */
28 public function getDescription() 26 public function getDescription()
29 { 27 {
30 return 'This importer will import all your wallabag v2 articles. Go to All articles, then, on the export sidebar, click on "JSON". You will have a "All articles.json" file.'; 28 return 'import.wallabag_v2.description';
31 } 29 }
32 30
33 /** 31 /**
34 * @param $entries 32 * {@inheritdoc}
35 */ 33 */
36 protected function parseEntries($entries) 34 protected function prepareEntry($entry = [], $markAsRead = false)
37 { 35 {
38 $i = 1; 36 return [
39 37 'html' => $entry['content'],
40 foreach ($entries as $importedEntry) { 38 'content_type' => $entry['mimetype'],
41 $existingEntry = $this->em 39 'is_archived' => ($entry['is_archived'] || $markAsRead),
42 ->getRepository('WallabagCoreBundle:Entry') 40 ] + $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 } 41 }
81} 42}