From 0783c99a196d1626d91119f715285150662fbe6e Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Thu, 11 Feb 2016 13:27:17 +0100 Subject: reimport v1 entries if they were not fetched --- .../ImportBundle/Import/WallabagV1Import.php | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'src/Wallabag/ImportBundle/Import') 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; use Wallabag\CoreBundle\Entity\Entry; use Wallabag\UserBundle\Entity\User; use Wallabag\CoreBundle\Tools\Utils; +use Wallabag\CoreBundle\Helper\ContentProxy; + class WallabagV1Import implements ImportInterface { protected $user; protected $em; protected $logger; + private $contentProxy; protected $skippedEntries = 0; protected $importedEntries = 0; protected $filepath; - public function __construct(EntityManager $em) + public function __construct(EntityManager $em, ContentProxy $contentProxy) { $this->em = $em; $this->logger = new NullLogger(); + $this->contentProxy = $contentProxy; } public function setLogger(LoggerInterface $logger) @@ -123,6 +127,10 @@ class WallabagV1Import implements ImportInterface protected function parseEntries($entries) { $i = 1; + /** + * Untitled in all languages from v1. This should never have been translated + */ + $untitled = array('Untitled','Sans titre','podle nadpisu','Sin título','با عنوان','per titolo','Sem título','Без названия','po naslovu','Без назви'); foreach ($entries as $importedEntry) { $existingEntry = $this->em @@ -137,12 +145,16 @@ class WallabagV1Import implements ImportInterface // @see ContentProxy->updateEntry $entry = new Entry($this->user); $entry->setUrl($importedEntry['url']); - $entry->setTitle($importedEntry['title']); + if (in_array($importedEntry['title'],$untitled)) { + $entry = $this->contentProxy->updateEntry($entry, $entry->getUrl()); + } else { + $entry->setContent($importedEntry['content']); + $entry->setTitle($importedEntry['title']); + $entry->setReadingTime(Utils::getReadingTime($importedEntry['content'])); + $entry->setDomainName(parse_url($importedEntry['url'], PHP_URL_HOST)); + } $entry->setArchived($importedEntry['is_read']); $entry->setStarred($importedEntry['is_fav']); - $entry->setContent($importedEntry['content']); - $entry->setReadingTime(Utils::getReadingTime($importedEntry['content'])); - $entry->setDomainName(parse_url($importedEntry['url'], PHP_URL_HOST)); $this->em->persist($entry); ++$this->importedEntries; -- cgit v1.2.3 From da0a9e01e9b6ef52656aa47367bfc30b1905fe40 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Thu, 11 Feb 2016 13:39:21 +0100 Subject: CS --- src/Wallabag/ImportBundle/Import/WallabagV1Import.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'src/Wallabag/ImportBundle/Import') diff --git a/src/Wallabag/ImportBundle/Import/WallabagV1Import.php b/src/Wallabag/ImportBundle/Import/WallabagV1Import.php index 82b52ad3..02327312 100644 --- a/src/Wallabag/ImportBundle/Import/WallabagV1Import.php +++ b/src/Wallabag/ImportBundle/Import/WallabagV1Import.php @@ -10,7 +10,6 @@ use Wallabag\UserBundle\Entity\User; use Wallabag\CoreBundle\Tools\Utils; use Wallabag\CoreBundle\Helper\ContentProxy; - class WallabagV1Import implements ImportInterface { protected $user; @@ -127,10 +126,10 @@ class WallabagV1Import implements ImportInterface protected function parseEntries($entries) { $i = 1; - /** + /* * Untitled in all languages from v1. This should never have been translated */ - $untitled = array('Untitled','Sans titre','podle nadpisu','Sin título','با عنوان','per titolo','Sem título','Без названия','po naslovu','Без назви'); + $untitled = array('Untitled', 'Sans titre', 'podle nadpisu', 'Sin título', 'با عنوان', 'per titolo', 'Sem título', 'Без названия', 'po naslovu', 'Без назви'); foreach ($entries as $importedEntry) { $existingEntry = $this->em @@ -145,7 +144,7 @@ class WallabagV1Import implements ImportInterface // @see ContentProxy->updateEntry $entry = new Entry($this->user); $entry->setUrl($importedEntry['url']); - if (in_array($importedEntry['title'],$untitled)) { + if (in_array($importedEntry['title'], $untitled)) { $entry = $this->contentProxy->updateEntry($entry, $entry->getUrl()); } else { $entry->setContent($importedEntry['content']); -- cgit v1.2.3 From eaf9dad777e84d50e8b3e5877b05605ad9138fee Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Thu, 11 Feb 2016 15:48:20 +0100 Subject: add tests --- src/Wallabag/ImportBundle/Import/WallabagV1Import.php | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'src/Wallabag/ImportBundle/Import') diff --git a/src/Wallabag/ImportBundle/Import/WallabagV1Import.php b/src/Wallabag/ImportBundle/Import/WallabagV1Import.php index 02327312..c54e73b2 100644 --- a/src/Wallabag/ImportBundle/Import/WallabagV1Import.php +++ b/src/Wallabag/ImportBundle/Import/WallabagV1Import.php @@ -15,7 +15,7 @@ class WallabagV1Import implements ImportInterface protected $user; protected $em; protected $logger; - private $contentProxy; + protected $contentProxy; protected $skippedEntries = 0; protected $importedEntries = 0; protected $filepath; @@ -126,10 +126,9 @@ class WallabagV1Import implements ImportInterface protected function parseEntries($entries) { $i = 1; - /* - * Untitled in all languages from v1. This should never have been translated - */ - $untitled = array('Untitled', 'Sans titre', 'podle nadpisu', 'Sin título', 'با عنوان', 'per titolo', 'Sem título', 'Без названия', 'po naslovu', 'Без назви'); + + //Untitled in all languages from v1. This should never have been translated + $untitled = array('Untitled', 'Sans titre', 'podle nadpisu', 'Sin título', 'با عنوان', 'per titolo', 'Sem título', 'Без названия', 'po naslovu', 'Без назви', 'No title found', ''); foreach ($entries as $importedEntry) { $existingEntry = $this->em @@ -145,7 +144,7 @@ class WallabagV1Import implements ImportInterface $entry = new Entry($this->user); $entry->setUrl($importedEntry['url']); if (in_array($importedEntry['title'], $untitled)) { - $entry = $this->contentProxy->updateEntry($entry, $entry->getUrl()); + $entry = $this->contentProxy->updateEntry($entry, $importedEntry['url']); } else { $entry->setContent($importedEntry['content']); $entry->setTitle($importedEntry['title']); -- cgit v1.2.3