aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/ImportBundle/Import/WallabagV2Import.php
diff options
context:
space:
mode:
authorNicolas LÅ“uillet <nicolas.loeuillet@smile.fr>2016-01-20 14:37:01 +0100
committerNicolas LÅ“uillet <nicolas.loeuillet@smile.fr>2016-01-20 14:37:01 +0100
commit6785f4aa749e381081b93e3db46424cc7475eab8 (patch)
treef8fb914c4febb93ee229c4b13f2488ee0c9fe2fc /src/Wallabag/ImportBundle/Import/WallabagV2Import.php
parentd481f42b7d383eb6211d1d3049d1a2c8288d9edb (diff)
downloadwallabag-6785f4aa749e381081b93e3db46424cc7475eab8.tar.gz
wallabag-6785f4aa749e381081b93e3db46424cc7475eab8.tar.zst
wallabag-6785f4aa749e381081b93e3db46424cc7475eab8.zip
[#1590] Add JSON import from wallabag v2
Diffstat (limited to 'src/Wallabag/ImportBundle/Import/WallabagV2Import.php')
-rw-r--r--src/Wallabag/ImportBundle/Import/WallabagV2Import.php75
1 files changed, 75 insertions, 0 deletions
diff --git a/src/Wallabag/ImportBundle/Import/WallabagV2Import.php b/src/Wallabag/ImportBundle/Import/WallabagV2Import.php
new file mode 100644
index 00000000..979c671e
--- /dev/null
+++ b/src/Wallabag/ImportBundle/Import/WallabagV2Import.php
@@ -0,0 +1,75 @@
1<?php
2
3namespace Wallabag\ImportBundle\Import;
4
5use Wallabag\CoreBundle\Entity\Entry;
6
7class 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 'This importer will import all your wallabag v2 articles. On the export sidebar, click on "JSON". You will have a "Unread articles.json" file.';
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']);
55 $entry->setStarred($importedEntry['is_starred']);
56 $entry->setContent($importedEntry['content']);
57 $entry->setReadingTime($importedEntry['reading_time']);
58 $entry->setDomainName($importedEntry['domain_name']);
59 $entry->setMimetype($importedEntry['mimetype']);
60 $entry->setLanguage($importedEntry['language']);
61 $entry->setPreviewPicture($importedEntry['preview_picture']);
62
63 $this->em->persist($entry);
64 ++$this->importedEntries;
65
66 // flush every 20 entries
67 if (($i % 20) === 0) {
68 $this->em->flush();
69 }
70 ++$i;
71 }
72
73 $this->em->flush();
74 }
75}