aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/ImportBundle/Import
diff options
context:
space:
mode:
Diffstat (limited to 'src/Wallabag/ImportBundle/Import')
-rw-r--r--src/Wallabag/ImportBundle/Import/AbstractImport.php4
-rw-r--r--src/Wallabag/ImportBundle/Import/BrowserImport.php2
-rw-r--r--src/Wallabag/ImportBundle/Import/InstapaperImport.php140
-rw-r--r--src/Wallabag/ImportBundle/Import/ReadabilityImport.php2
-rw-r--r--src/Wallabag/ImportBundle/Import/WallabagImport.php2
5 files changed, 150 insertions, 0 deletions
diff --git a/src/Wallabag/ImportBundle/Import/AbstractImport.php b/src/Wallabag/ImportBundle/Import/AbstractImport.php
index a1a14576..764b390a 100644
--- a/src/Wallabag/ImportBundle/Import/AbstractImport.php
+++ b/src/Wallabag/ImportBundle/Import/AbstractImport.php
@@ -106,6 +106,10 @@ abstract class AbstractImport implements ImportInterface
106 $i = 1; 106 $i = 1;
107 107
108 foreach ($entries as $importedEntry) { 108 foreach ($entries as $importedEntry) {
109 if ($this->markAsRead) {
110 $importedEntry = $this->setEntryAsRead($importedEntry);
111 }
112
109 $entry = $this->parseEntry($importedEntry); 113 $entry = $this->parseEntry($importedEntry);
110 114
111 if (null === $entry) { 115 if (null === $entry) {
diff --git a/src/Wallabag/ImportBundle/Import/BrowserImport.php b/src/Wallabag/ImportBundle/Import/BrowserImport.php
index e15443c4..9d75685b 100644
--- a/src/Wallabag/ImportBundle/Import/BrowserImport.php
+++ b/src/Wallabag/ImportBundle/Import/BrowserImport.php
@@ -45,6 +45,8 @@ abstract class BrowserImport extends AbstractImport
45 $data = json_decode(file_get_contents($this->filepath), true); 45 $data = json_decode(file_get_contents($this->filepath), true);
46 46
47 if (empty($data)) { 47 if (empty($data)) {
48 $this->logger->error('Wallabag Browser: no entries in imported file');
49
48 return false; 50 return false;
49 } 51 }
50 52
diff --git a/src/Wallabag/ImportBundle/Import/InstapaperImport.php b/src/Wallabag/ImportBundle/Import/InstapaperImport.php
new file mode 100644
index 00000000..cf4c785c
--- /dev/null
+++ b/src/Wallabag/ImportBundle/Import/InstapaperImport.php
@@ -0,0 +1,140 @@
1<?php
2
3namespace Wallabag\ImportBundle\Import;
4
5use Wallabag\CoreBundle\Entity\Entry;
6
7class InstapaperImport extends AbstractImport
8{
9 private $filepath;
10
11 /**
12 * {@inheritdoc}
13 */
14 public function getName()
15 {
16 return 'Instapaper';
17 }
18
19 /**
20 * {@inheritdoc}
21 */
22 public function getUrl()
23 {
24 return 'import_instapaper';
25 }
26
27 /**
28 * {@inheritdoc}
29 */
30 public function getDescription()
31 {
32 return 'import.instapaper.description';
33 }
34
35 /**
36 * Set file path to the json file.
37 *
38 * @param string $filepath
39 */
40 public function setFilepath($filepath)
41 {
42 $this->filepath = $filepath;
43
44 return $this;
45 }
46
47 /**
48 * {@inheritdoc}
49 */
50 public function import()
51 {
52 if (!$this->user) {
53 $this->logger->error('InstapaperImport: user is not defined');
54
55 return false;
56 }
57
58 if (!file_exists($this->filepath) || !is_readable($this->filepath)) {
59 $this->logger->error('InstapaperImport: unable to read file', ['filepath' => $this->filepath]);
60
61 return false;
62 }
63
64 $entries = [];
65 $handle = fopen($this->filepath, 'r');
66 while (($data = fgetcsv($handle, 10240)) !== false) {
67 if ('URL' === $data[0]) {
68 continue;
69 }
70
71 $entries[] = [
72 'url' => $data[0],
73 'title' => $data[1],
74 'status' => $data[3],
75 'is_archived' => $data[3] === 'Archive' || $data[3] === 'Starred',
76 'is_starred' => $data[3] === 'Starred',
77 'content_type' => '',
78 'language' => '',
79 ];
80 }
81 fclose($handle);
82
83 if (empty($entries)) {
84 $this->logger->error('InstapaperImport: no entries in imported file');
85
86 return false;
87 }
88
89 if ($this->producer) {
90 $this->parseEntriesForProducer($entries);
91
92 return true;
93 }
94
95 $this->parseEntries($entries);
96
97 return true;
98 }
99
100 /**
101 * {@inheritdoc}
102 */
103 public function parseEntry(array $importedEntry)
104 {
105 $existingEntry = $this->em
106 ->getRepository('WallabagCoreBundle:Entry')
107 ->findByUrlAndUserId($importedEntry['url'], $this->user->getId());
108
109 if (false !== $existingEntry) {
110 ++$this->skippedEntries;
111
112 return;
113 }
114
115 $entry = new Entry($this->user);
116 $entry->setUrl($importedEntry['url']);
117 $entry->setTitle($importedEntry['title']);
118
119 // update entry with content (in case fetching failed, the given entry will be return)
120 $entry = $this->fetchContent($entry, $importedEntry['url'], $importedEntry);
121
122 $entry->setArchived($importedEntry['is_archived']);
123 $entry->setStarred($importedEntry['is_starred']);
124
125 $this->em->persist($entry);
126 ++$this->importedEntries;
127
128 return $entry;
129 }
130
131 /**
132 * {@inheritdoc}
133 */
134 protected function setEntryAsRead(array $importedEntry)
135 {
136 $importedEntry['is_archived'] = 1;
137
138 return $importedEntry;
139 }
140}
diff --git a/src/Wallabag/ImportBundle/Import/ReadabilityImport.php b/src/Wallabag/ImportBundle/Import/ReadabilityImport.php
index fa2b7053..b8c0f777 100644
--- a/src/Wallabag/ImportBundle/Import/ReadabilityImport.php
+++ b/src/Wallabag/ImportBundle/Import/ReadabilityImport.php
@@ -64,6 +64,8 @@ class ReadabilityImport extends AbstractImport
64 $data = json_decode(file_get_contents($this->filepath), true); 64 $data = json_decode(file_get_contents($this->filepath), true);
65 65
66 if (empty($data) || empty($data['bookmarks'])) { 66 if (empty($data) || empty($data['bookmarks'])) {
67 $this->logger->error('ReadabilityImport: no entries in imported file');
68
67 return false; 69 return false;
68 } 70 }
69 71
diff --git a/src/Wallabag/ImportBundle/Import/WallabagImport.php b/src/Wallabag/ImportBundle/Import/WallabagImport.php
index 3754e4a9..702da057 100644
--- a/src/Wallabag/ImportBundle/Import/WallabagImport.php
+++ b/src/Wallabag/ImportBundle/Import/WallabagImport.php
@@ -58,6 +58,8 @@ abstract class WallabagImport extends AbstractImport
58 $data = json_decode(file_get_contents($this->filepath), true); 58 $data = json_decode(file_get_contents($this->filepath), true);
59 59
60 if (empty($data)) { 60 if (empty($data)) {
61 $this->logger->error('WallabagImport: no entries in imported file');
62
61 return false; 63 return false;
62 } 64 }
63 65