aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/ImportBundle/Import/WallabagV2Import.php
diff options
context:
space:
mode:
authorJeremy Benoist <jeremy.benoist@gmail.com>2016-03-28 16:43:33 +0200
committerJeremy Benoist <jeremy.benoist@gmail.com>2016-03-28 16:43:33 +0200
commitb787a7757ea73b9d10c14cb21758feb07dfc5885 (patch)
tree13989f7a843332cdee095d456863535a2854862c /src/Wallabag/ImportBundle/Import/WallabagV2Import.php
parent0e49487bb0a004d526eb41e7d3fb44b566441e34 (diff)
downloadwallabag-b787a7757ea73b9d10c14cb21758feb07dfc5885.tar.gz
wallabag-b787a7757ea73b9d10c14cb21758feb07dfc5885.tar.zst
wallabag-b787a7757ea73b9d10c14cb21758feb07dfc5885.zip
Refacto wallabag import
Use an abstract class to store all common action from wallabag vX import. Move specificity in v1 & v2 import.
Diffstat (limited to 'src/Wallabag/ImportBundle/Import/WallabagV2Import.php')
-rw-r--r--src/Wallabag/ImportBundle/Import/WallabagV2Import.php59
1 files changed, 8 insertions, 51 deletions
diff --git a/src/Wallabag/ImportBundle/Import/WallabagV2Import.php b/src/Wallabag/ImportBundle/Import/WallabagV2Import.php
index b31d63a3..d0035b63 100644
--- a/src/Wallabag/ImportBundle/Import/WallabagV2Import.php
+++ b/src/Wallabag/ImportBundle/Import/WallabagV2Import.php
@@ -2,9 +2,7 @@
2 2
3namespace Wallabag\ImportBundle\Import; 3namespace Wallabag\ImportBundle\Import;
4 4
5use Wallabag\CoreBundle\Entity\Entry; 5class WallabagV2Import extends WallabagImport
6
7class WallabagV2Import extends WallabagV1Import implements ImportInterface
8{ 6{
9 /** 7 /**
10 * {@inheritdoc} 8 * {@inheritdoc}
@@ -31,55 +29,14 @@ class WallabagV2Import extends WallabagV1Import implements ImportInterface
31 } 29 }
32 30
33 /** 31 /**
34 * @param $entries 32 * {@inheritdoc}
35 */ 33 */
36 protected function parseEntries($entries) 34 protected function prepareEntry($entry = [], $markAsRead = false)
37 { 35 {
38 $i = 1; 36 return [
39 37 'html' => $entry['content'],
40 foreach ($entries as $importedEntry) { 38 'content_type' => $entry['mimetype'],
41 $existingEntry = $this->em 39 'is_archived' => ($entry['is_archived'] || $markAsRead),
42 ->getRepository('WallabagCoreBundle:Entry') 40 ] + $entry;
43 ->findByUrlAndUserId($importedEntry['url'], $this->user->getId());
44
45 if (false !== $existingEntry) {
46 ++$this->skippedEntries;
47 continue;
48 }
49
50 $importedEntry['html'] = $importedEntry['content'];
51 $importedEntry['content_type'] = $importedEntry['mimetype'];
52
53 $entry = $this->contentProxy->updateEntry(
54 new Entry($this->user),
55 $importedEntry['url'],
56 $importedEntry
57 );
58
59 if (array_key_exists('tags', $importedEntry) && !empty($importedEntry['tags'])) {
60 $this->contentProxy->assignTagsToEntry(
61 $entry,
62 $importedEntry['tags']
63 );
64 }
65
66 if (isset($importedEntry['preview_picture'])) {
67 $entry->setPreviewPicture($importedEntry['preview_picture']);
68 }
69
70 $entry->setArchived($importedEntry['is_archived'] || $this->markAsRead);
71 $entry->setStarred($importedEntry['is_starred']);
72
73 $this->em->persist($entry);
74 ++$this->importedEntries;
75
76 // flush every 20 entries
77 if (($i % 20) === 0) {
78 $this->em->flush();
79 }
80 ++$i;
81 }
82
83 $this->em->flush();
84 } 41 }
85} 42}