diff options
Diffstat (limited to 'src/Wallabag/ImportBundle/Import/WallabagV1Import.php')
-rw-r--r-- | src/Wallabag/ImportBundle/Import/WallabagV1Import.php | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/src/Wallabag/ImportBundle/Import/WallabagV1Import.php b/src/Wallabag/ImportBundle/Import/WallabagV1Import.php index 7b012674..aff5af40 100644 --- a/src/Wallabag/ImportBundle/Import/WallabagV1Import.php +++ b/src/Wallabag/ImportBundle/Import/WallabagV1Import.php | |||
@@ -53,9 +53,17 @@ class WallabagV1Import implements ImportInterface | |||
53 | /** | 53 | /** |
54 | * {@inheritdoc} | 54 | * {@inheritdoc} |
55 | */ | 55 | */ |
56 | public function getUrl() | ||
57 | { | ||
58 | return 'import_wallabag_v1'; | ||
59 | } | ||
60 | |||
61 | /** | ||
62 | * {@inheritdoc} | ||
63 | */ | ||
56 | public function getDescription() | 64 | public function getDescription() |
57 | { | 65 | { |
58 | return 'This importer will import all your wallabag v1 articles.'; | 66 | return 'This importer will import all your wallabag v1 articles. On your config page, click on "JSON export" in the "Export your wallabag data" section. You will have a "wallabag-export-1-xxxx-xx-xx.json" file.'; |
59 | } | 67 | } |
60 | 68 | ||
61 | /** | 69 | /** |
@@ -75,7 +83,13 @@ class WallabagV1Import implements ImportInterface | |||
75 | return false; | 83 | return false; |
76 | } | 84 | } |
77 | 85 | ||
78 | $this->parseEntries(json_decode(file_get_contents($this->filepath), true)); | 86 | $data = json_decode(file_get_contents($this->filepath), true); |
87 | |||
88 | if (empty($data)) { | ||
89 | return false; | ||
90 | } | ||
91 | |||
92 | $this->parseEntries($data); | ||
79 | 93 | ||
80 | return true; | 94 | return true; |
81 | } | 95 | } |
@@ -108,6 +122,8 @@ class WallabagV1Import implements ImportInterface | |||
108 | */ | 122 | */ |
109 | private function parseEntries($entries) | 123 | private function parseEntries($entries) |
110 | { | 124 | { |
125 | $i = 1; | ||
126 | |||
111 | foreach ($entries as $importedEntry) { | 127 | foreach ($entries as $importedEntry) { |
112 | $existingEntry = $this->em | 128 | $existingEntry = $this->em |
113 | ->getRepository('WallabagCoreBundle:Entry') | 129 | ->getRepository('WallabagCoreBundle:Entry') |
@@ -130,6 +146,12 @@ class WallabagV1Import implements ImportInterface | |||
130 | 146 | ||
131 | $this->em->persist($entry); | 147 | $this->em->persist($entry); |
132 | ++$this->importedEntries; | 148 | ++$this->importedEntries; |
149 | |||
150 | // flush every 20 entries | ||
151 | if (($i % 20) === 0) { | ||
152 | $em->flush(); | ||
153 | } | ||
154 | ++$i; | ||
133 | } | 155 | } |
134 | 156 | ||
135 | $this->em->flush(); | 157 | $this->em->flush(); |