aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/ImportBundle/Import/WallabagV1Import.php
diff options
context:
space:
mode:
authorJeremy Benoist <jeremy.benoist@gmail.com>2015-12-31 11:24:46 +0100
committerJeremy Benoist <jeremy.benoist@gmail.com>2016-01-02 23:27:41 +0100
commit7019c7cf6c6af39c0f458769e20c3f9306477943 (patch)
tree12acceaa458cdf6d24367eba85f690265acddcdb /src/Wallabag/ImportBundle/Import/WallabagV1Import.php
parentb1d05721cf37ab94ec1a6837fe79cf19474dd0ff (diff)
downloadwallabag-7019c7cf6c6af39c0f458769e20c3f9306477943.tar.gz
wallabag-7019c7cf6c6af39c0f458769e20c3f9306477943.tar.zst
wallabag-7019c7cf6c6af39c0f458769e20c3f9306477943.zip
Add tagged services for import
- list services in /import - add url to import service - ImportBundle routing are now prefixed by /import - optimize flush in each import (flushing each 20 contents) - improve design of each import - add more tests
Diffstat (limited to 'src/Wallabag/ImportBundle/Import/WallabagV1Import.php')
-rw-r--r--src/Wallabag/ImportBundle/Import/WallabagV1Import.php26
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();