diff options
Diffstat (limited to 'src/Wallabag/ImportBundle/Import')
5 files changed, 115 insertions, 3 deletions
diff --git a/src/Wallabag/ImportBundle/Import/ImportChain.php b/src/Wallabag/ImportBundle/Import/ImportChain.php new file mode 100644 index 00000000..9dd77956 --- /dev/null +++ b/src/Wallabag/ImportBundle/Import/ImportChain.php | |||
@@ -0,0 +1,34 @@ | |||
1 | <?php | ||
2 | |||
3 | namespace Wallabag\ImportBundle\Import; | ||
4 | |||
5 | class ImportChain | ||
6 | { | ||
7 | private $imports; | ||
8 | |||
9 | public function __construct() | ||
10 | { | ||
11 | $this->imports = []; | ||
12 | } | ||
13 | |||
14 | /** | ||
15 | * Add an import to the chain. | ||
16 | * | ||
17 | * @param ImportInterface $import | ||
18 | * @param string $alias | ||
19 | */ | ||
20 | public function addImport(ImportInterface $import, $alias) | ||
21 | { | ||
22 | $this->imports[$alias] = $import; | ||
23 | } | ||
24 | |||
25 | /** | ||
26 | * Get all imports. | ||
27 | * | ||
28 | * @return array<ImportInterface> | ||
29 | */ | ||
30 | public function getAll() | ||
31 | { | ||
32 | return $this->imports; | ||
33 | } | ||
34 | } | ||
diff --git a/src/Wallabag/ImportBundle/Import/ImportCompilerPass.php b/src/Wallabag/ImportBundle/Import/ImportCompilerPass.php new file mode 100644 index 00000000..a363a566 --- /dev/null +++ b/src/Wallabag/ImportBundle/Import/ImportCompilerPass.php | |||
@@ -0,0 +1,33 @@ | |||
1 | <?php | ||
2 | |||
3 | namespace Wallabag\ImportBundle\Import; | ||
4 | |||
5 | use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
6 | use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; | ||
7 | use Symfony\Component\DependencyInjection\Reference; | ||
8 | |||
9 | class ImportCompilerPass implements CompilerPassInterface | ||
10 | { | ||
11 | public function process(ContainerBuilder $container) | ||
12 | { | ||
13 | if (!$container->hasDefinition('wallabag_import.chain')) { | ||
14 | return; | ||
15 | } | ||
16 | |||
17 | $definition = $container->getDefinition( | ||
18 | 'wallabag_import.chain' | ||
19 | ); | ||
20 | |||
21 | $taggedServices = $container->findTaggedServiceIds( | ||
22 | 'wallabag_import.import' | ||
23 | ); | ||
24 | foreach ($taggedServices as $id => $tagAttributes) { | ||
25 | foreach ($tagAttributes as $attributes) { | ||
26 | $definition->addMethodCall( | ||
27 | 'addImport', | ||
28 | [new Reference($id), $attributes['alias']] | ||
29 | ); | ||
30 | } | ||
31 | } | ||
32 | } | ||
33 | } | ||
diff --git a/src/Wallabag/ImportBundle/Import/ImportInterface.php b/src/Wallabag/ImportBundle/Import/ImportInterface.php index 8cf238aa..25dc0d85 100644 --- a/src/Wallabag/ImportBundle/Import/ImportInterface.php +++ b/src/Wallabag/ImportBundle/Import/ImportInterface.php | |||
@@ -14,6 +14,13 @@ interface ImportInterface extends LoggerAwareInterface | |||
14 | public function getName(); | 14 | public function getName(); |
15 | 15 | ||
16 | /** | 16 | /** |
17 | * Url to start the import. | ||
18 | * | ||
19 | * @return string | ||
20 | */ | ||
21 | public function getUrl(); | ||
22 | |||
23 | /** | ||
17 | * Description of the import. | 24 | * Description of the import. |
18 | * | 25 | * |
19 | * @return string | 26 | * @return string |
diff --git a/src/Wallabag/ImportBundle/Import/PocketImport.php b/src/Wallabag/ImportBundle/Import/PocketImport.php index aeccc7bd..b1c5bb00 100644 --- a/src/Wallabag/ImportBundle/Import/PocketImport.php +++ b/src/Wallabag/ImportBundle/Import/PocketImport.php | |||
@@ -48,9 +48,17 @@ class PocketImport implements ImportInterface | |||
48 | /** | 48 | /** |
49 | * {@inheritdoc} | 49 | * {@inheritdoc} |
50 | */ | 50 | */ |
51 | public function getUrl() | ||
52 | { | ||
53 | return 'import_pocket'; | ||
54 | } | ||
55 | |||
56 | /** | ||
57 | * {@inheritdoc} | ||
58 | */ | ||
51 | public function getDescription() | 59 | public function getDescription() |
52 | { | 60 | { |
53 | return 'This importer will import all your <a href="https://getpocket.com">Pocket</a> data.'; | 61 | return 'This importer will import all your <a href="https://getpocket.com">Pocket</a> data. Pocket doesn\'t allow us to retrieve content from their service, so the readable content of each article will be re-fetched by Wallabag.'; |
54 | } | 62 | } |
55 | 63 | ||
56 | /** | 64 | /** |
@@ -196,6 +204,8 @@ class PocketImport implements ImportInterface | |||
196 | */ | 204 | */ |
197 | private function parseEntries($entries) | 205 | private function parseEntries($entries) |
198 | { | 206 | { |
207 | $i = 1; | ||
208 | |||
199 | foreach ($entries as $pocketEntry) { | 209 | foreach ($entries as $pocketEntry) { |
200 | $url = isset($pocketEntry['resolved_url']) && $pocketEntry['resolved_url'] != '' ? $pocketEntry['resolved_url'] : $pocketEntry['given_url']; | 210 | $url = isset($pocketEntry['resolved_url']) && $pocketEntry['resolved_url'] != '' ? $pocketEntry['resolved_url'] : $pocketEntry['given_url']; |
201 | 211 | ||
@@ -241,6 +251,12 @@ class PocketImport implements ImportInterface | |||
241 | 251 | ||
242 | $this->em->persist($entry); | 252 | $this->em->persist($entry); |
243 | ++$this->importedEntries; | 253 | ++$this->importedEntries; |
254 | |||
255 | // flush every 20 entries | ||
256 | if (($i % 20) === 0) { | ||
257 | $em->flush(); | ||
258 | } | ||
259 | ++$i; | ||
244 | } | 260 | } |
245 | 261 | ||
246 | $this->em->flush(); | 262 | $this->em->flush(); |
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(); |