diff options
author | Jeremy Benoist <j0k3r@users.noreply.github.com> | 2016-02-01 14:17:20 +0100 |
---|---|---|
committer | Jeremy Benoist <j0k3r@users.noreply.github.com> | 2016-02-01 14:17:20 +0100 |
commit | 85ad629a3ca209907effd75f5fd7f384f42361bc (patch) | |
tree | 6fde1374b404567153478373f3e65e63af9c1120 /src/Wallabag/ImportBundle/Import/WallabagV2Import.php | |
parent | e43d27f8450dcdf79850e935b762ac390a19dd63 (diff) | |
parent | 6785f4aa749e381081b93e3db46424cc7475eab8 (diff) | |
download | wallabag-85ad629a3ca209907effd75f5fd7f384f42361bc.tar.gz wallabag-85ad629a3ca209907effd75f5fd7f384f42361bc.tar.zst wallabag-85ad629a3ca209907effd75f5fd7f384f42361bc.zip |
Merge pull request #1601 from wallabag/v2-import-from-v2
[#1590] Add JSON import from wallabag v2
Diffstat (limited to 'src/Wallabag/ImportBundle/Import/WallabagV2Import.php')
-rw-r--r-- | src/Wallabag/ImportBundle/Import/WallabagV2Import.php | 75 |
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 | |||
3 | namespace Wallabag\ImportBundle\Import; | ||
4 | |||
5 | use Wallabag\CoreBundle\Entity\Entry; | ||
6 | |||
7 | class 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 | } | ||