aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--src/Wallabag/ImportBundle/Import/WallabagV1Import.php22
-rw-r--r--src/Wallabag/ImportBundle/Resources/config/services.yml2
-rw-r--r--src/Wallabag/ImportBundle/Tests/Import/WallabagV1ImportTest.php8
-rw-r--r--src/Wallabag/ImportBundle/Tests/Import/WallabagV2ImportTest.php7
4 files changed, 32 insertions, 7 deletions
diff --git a/src/Wallabag/ImportBundle/Import/WallabagV1Import.php b/src/Wallabag/ImportBundle/Import/WallabagV1Import.php
index 0dac6203..82b52ad3 100644
--- a/src/Wallabag/ImportBundle/Import/WallabagV1Import.php
+++ b/src/Wallabag/ImportBundle/Import/WallabagV1Import.php
@@ -8,20 +8,24 @@ use Doctrine\ORM\EntityManager;
8use Wallabag\CoreBundle\Entity\Entry; 8use Wallabag\CoreBundle\Entity\Entry;
9use Wallabag\UserBundle\Entity\User; 9use Wallabag\UserBundle\Entity\User;
10use Wallabag\CoreBundle\Tools\Utils; 10use Wallabag\CoreBundle\Tools\Utils;
11use Wallabag\CoreBundle\Helper\ContentProxy;
12
11 13
12class WallabagV1Import implements ImportInterface 14class WallabagV1Import implements ImportInterface
13{ 15{
14 protected $user; 16 protected $user;
15 protected $em; 17 protected $em;
16 protected $logger; 18 protected $logger;
19 private $contentProxy;
17 protected $skippedEntries = 0; 20 protected $skippedEntries = 0;
18 protected $importedEntries = 0; 21 protected $importedEntries = 0;
19 protected $filepath; 22 protected $filepath;
20 23
21 public function __construct(EntityManager $em) 24 public function __construct(EntityManager $em, ContentProxy $contentProxy)
22 { 25 {
23 $this->em = $em; 26 $this->em = $em;
24 $this->logger = new NullLogger(); 27 $this->logger = new NullLogger();
28 $this->contentProxy = $contentProxy;
25 } 29 }
26 30
27 public function setLogger(LoggerInterface $logger) 31 public function setLogger(LoggerInterface $logger)
@@ -123,6 +127,10 @@ class WallabagV1Import implements ImportInterface
123 protected function parseEntries($entries) 127 protected function parseEntries($entries)
124 { 128 {
125 $i = 1; 129 $i = 1;
130 /**
131 * Untitled in all languages from v1. This should never have been translated
132 */
133 $untitled = array('Untitled','Sans titre','podle nadpisu','Sin título','با عنوان','per titolo','Sem título','Без названия','po naslovu','Без назви');
126 134
127 foreach ($entries as $importedEntry) { 135 foreach ($entries as $importedEntry) {
128 $existingEntry = $this->em 136 $existingEntry = $this->em
@@ -137,12 +145,16 @@ class WallabagV1Import implements ImportInterface
137 // @see ContentProxy->updateEntry 145 // @see ContentProxy->updateEntry
138 $entry = new Entry($this->user); 146 $entry = new Entry($this->user);
139 $entry->setUrl($importedEntry['url']); 147 $entry->setUrl($importedEntry['url']);
140 $entry->setTitle($importedEntry['title']); 148 if (in_array($importedEntry['title'],$untitled)) {
149 $entry = $this->contentProxy->updateEntry($entry, $entry->getUrl());
150 } else {
151 $entry->setContent($importedEntry['content']);
152 $entry->setTitle($importedEntry['title']);
153 $entry->setReadingTime(Utils::getReadingTime($importedEntry['content']));
154 $entry->setDomainName(parse_url($importedEntry['url'], PHP_URL_HOST));
155 }
141 $entry->setArchived($importedEntry['is_read']); 156 $entry->setArchived($importedEntry['is_read']);
142 $entry->setStarred($importedEntry['is_fav']); 157 $entry->setStarred($importedEntry['is_fav']);
143 $entry->setContent($importedEntry['content']);
144 $entry->setReadingTime(Utils::getReadingTime($importedEntry['content']));
145 $entry->setDomainName(parse_url($importedEntry['url'], PHP_URL_HOST));
146 158
147 $this->em->persist($entry); 159 $this->em->persist($entry);
148 ++$this->importedEntries; 160 ++$this->importedEntries;
diff --git a/src/Wallabag/ImportBundle/Resources/config/services.yml b/src/Wallabag/ImportBundle/Resources/config/services.yml
index e0942b1a..86b44cb3 100644
--- a/src/Wallabag/ImportBundle/Resources/config/services.yml
+++ b/src/Wallabag/ImportBundle/Resources/config/services.yml
@@ -28,6 +28,7 @@ services:
28 class: Wallabag\ImportBundle\Import\WallabagV1Import 28 class: Wallabag\ImportBundle\Import\WallabagV1Import
29 arguments: 29 arguments:
30 - "@doctrine.orm.entity_manager" 30 - "@doctrine.orm.entity_manager"
31 - "@wallabag_core.content_proxy"
31 calls: 32 calls:
32 - [ setLogger, [ "@logger" ]] 33 - [ setLogger, [ "@logger" ]]
33 tags: 34 tags:
@@ -37,6 +38,7 @@ services:
37 class: Wallabag\ImportBundle\Import\WallabagV2Import 38 class: Wallabag\ImportBundle\Import\WallabagV2Import
38 arguments: 39 arguments:
39 - "@doctrine.orm.entity_manager" 40 - "@doctrine.orm.entity_manager"
41 - "@wallabag_core.content_proxy"
40 calls: 42 calls:
41 - [ setLogger, [ "@logger" ]] 43 - [ setLogger, [ "@logger" ]]
42 tags: 44 tags:
diff --git a/src/Wallabag/ImportBundle/Tests/Import/WallabagV1ImportTest.php b/src/Wallabag/ImportBundle/Tests/Import/WallabagV1ImportTest.php
index 1cb5a233..78cc19b6 100644
--- a/src/Wallabag/ImportBundle/Tests/Import/WallabagV1ImportTest.php
+++ b/src/Wallabag/ImportBundle/Tests/Import/WallabagV1ImportTest.php
@@ -12,6 +12,8 @@ class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase
12 protected $user; 12 protected $user;
13 protected $em; 13 protected $em;
14 protected $logHandler; 14 protected $logHandler;
15 protected $contentProxy;
16
15 17
16 private function getWallabagV1Import($unsetUser = false) 18 private function getWallabagV1Import($unsetUser = false)
17 { 19 {
@@ -21,7 +23,11 @@ class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase
21 ->disableOriginalConstructor() 23 ->disableOriginalConstructor()
22 ->getMock(); 24 ->getMock();
23 25
24 $wallabag = new WallabagV1Import($this->em); 26 $this->contentProxy = $this->getMockBuilder('Wallabag\CoreBundle\Helper\ContentProxy')
27 ->disableOriginalConstructor()
28 ->getMock();
29
30 $wallabag = new WallabagV1Import($this->em,$this->contentProxy);
25 31
26 $this->logHandler = new TestHandler(); 32 $this->logHandler = new TestHandler();
27 $logger = new Logger('test', array($this->logHandler)); 33 $logger = new Logger('test', array($this->logHandler));
diff --git a/src/Wallabag/ImportBundle/Tests/Import/WallabagV2ImportTest.php b/src/Wallabag/ImportBundle/Tests/Import/WallabagV2ImportTest.php
index 4ebe93bf..0b33afb6 100644
--- a/src/Wallabag/ImportBundle/Tests/Import/WallabagV2ImportTest.php
+++ b/src/Wallabag/ImportBundle/Tests/Import/WallabagV2ImportTest.php
@@ -12,6 +12,7 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase
12 protected $user; 12 protected $user;
13 protected $em; 13 protected $em;
14 protected $logHandler; 14 protected $logHandler;
15 protected $contentProxy;
15 16
16 private function getWallabagV2Import($unsetUser = false) 17 private function getWallabagV2Import($unsetUser = false)
17 { 18 {
@@ -21,7 +22,11 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase
21 ->disableOriginalConstructor() 22 ->disableOriginalConstructor()
22 ->getMock(); 23 ->getMock();
23 24
24 $wallabag = new WallabagV2Import($this->em); 25 $this->contentProxy = $this->getMockBuilder('Wallabag\CoreBundle\Helper\ContentProxy')
26 ->disableOriginalConstructor()
27 ->getMock();
28
29 $wallabag = new WallabagV2Import($this->em,$this->contentProxy);
25 30
26 $this->logHandler = new TestHandler(); 31 $this->logHandler = new TestHandler();
27 $logger = new Logger('test', array($this->logHandler)); 32 $logger = new Logger('test', array($this->logHandler));