mirror of
https://github.com/wallabag/wallabag.git
synced 2024-11-15 21:41:06 +00:00
Merge pull request #1666 from wallabag/v2-reimport-v1-articles-if-not-fetched
reimport v1 entries if they were not fetched
This commit is contained in:
commit
6896ae1dda
6 changed files with 99 additions and 13 deletions
|
@ -8,20 +8,23 @@ 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;
|
||||
protected $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)
|
||||
|
@ -124,6 +127,9 @@ class WallabagV1Import implements ImportInterface
|
|||
{
|
||||
$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', 'Без назви', 'No title found', '');
|
||||
|
||||
foreach ($entries as $importedEntry) {
|
||||
$existingEntry = $this->em
|
||||
->getRepository('WallabagCoreBundle:Entry')
|
||||
|
@ -137,12 +143,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, $importedEntry['url']);
|
||||
} 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;
|
||||
|
|
|
@ -28,6 +28,7 @@ services:
|
|||
class: Wallabag\ImportBundle\Import\WallabagV1Import
|
||||
arguments:
|
||||
- "@doctrine.orm.entity_manager"
|
||||
- "@wallabag_core.content_proxy"
|
||||
calls:
|
||||
- [ setLogger, [ "@logger" ]]
|
||||
tags:
|
||||
|
@ -37,6 +38,7 @@ services:
|
|||
class: Wallabag\ImportBundle\Import\WallabagV2Import
|
||||
arguments:
|
||||
- "@doctrine.orm.entity_manager"
|
||||
- "@wallabag_core.content_proxy"
|
||||
calls:
|
||||
- [ setLogger, [ "@logger" ]]
|
||||
tags:
|
||||
|
|
|
@ -12,6 +12,7 @@ class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase
|
|||
protected $user;
|
||||
protected $em;
|
||||
protected $logHandler;
|
||||
protected $contentProxy;
|
||||
|
||||
private function getWallabagV1Import($unsetUser = false)
|
||||
{
|
||||
|
@ -21,7 +22,11 @@ class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase
|
|||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$wallabag = new WallabagV1Import($this->em);
|
||||
$this->contentProxy = $this->getMockBuilder('Wallabag\CoreBundle\Helper\ContentProxy')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$wallabag = new WallabagV1Import($this->em, $this->contentProxy);
|
||||
|
||||
$this->logHandler = new TestHandler();
|
||||
$logger = new Logger('test', array($this->logHandler));
|
||||
|
@ -52,19 +57,28 @@ class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase
|
|||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$entryRepo->expects($this->exactly(3))
|
||||
$entryRepo->expects($this->exactly(4))
|
||||
->method('findByUrlAndUserId')
|
||||
->will($this->onConsecutiveCalls(false, true, false));
|
||||
->will($this->onConsecutiveCalls(false, true, false, false));
|
||||
|
||||
$this->em
|
||||
->expects($this->any())
|
||||
->method('getRepository')
|
||||
->willReturn($entryRepo);
|
||||
|
||||
$entry = $this->getMockBuilder('Wallabag\CoreBundle\Entity\Entry')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$this->contentProxy
|
||||
->expects($this->once())
|
||||
->method('updateEntry')
|
||||
->willReturn($entry);
|
||||
|
||||
$res = $wallabagV1Import->import();
|
||||
|
||||
$this->assertTrue($res);
|
||||
$this->assertEquals(['skipped' => 1, 'imported' => 2], $wallabagV1Import->getSummary());
|
||||
$this->assertEquals(['skipped' => 1, 'imported' => 3], $wallabagV1Import->getSummary());
|
||||
}
|
||||
|
||||
public function testImportBadFile()
|
||||
|
|
|
@ -12,6 +12,7 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase
|
|||
protected $user;
|
||||
protected $em;
|
||||
protected $logHandler;
|
||||
protected $contentProxy;
|
||||
|
||||
private function getWallabagV2Import($unsetUser = false)
|
||||
{
|
||||
|
@ -21,7 +22,11 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase
|
|||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$wallabag = new WallabagV2Import($this->em);
|
||||
$this->contentProxy = $this->getMockBuilder('Wallabag\CoreBundle\Helper\ContentProxy')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$wallabag = new WallabagV2Import($this->em, $this->contentProxy);
|
||||
|
||||
$this->logHandler = new TestHandler();
|
||||
$logger = new Logger('test', array($this->logHandler));
|
||||
|
@ -52,7 +57,7 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase
|
|||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$entryRepo->expects($this->exactly(2))
|
||||
$entryRepo->expects($this->exactly(3))
|
||||
->method('findByUrlAndUserId')
|
||||
->will($this->onConsecutiveCalls(false, true, false));
|
||||
|
||||
|
@ -64,7 +69,7 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase
|
|||
$res = $wallabagV2Import->import();
|
||||
|
||||
$this->assertTrue($res);
|
||||
$this->assertEquals(['skipped' => 1, 'imported' => 1], $wallabagV2Import->getSummary());
|
||||
$this->assertEquals(['skipped' => 1, 'imported' => 2], $wallabagV2Import->getSummary());
|
||||
}
|
||||
|
||||
public function testImportBadFile()
|
||||
|
|
|
@ -46,5 +46,21 @@
|
|||
"is_fav": "0",
|
||||
"content": "\n<div class=\"row\">\n<div class=\"col-lg-8 col-md-12 col-xs-12 col-sm-12\">\n<p>wallabag (formerly poche) is a <strong>self hostable application for saving web pages</strong>. Unlike other services, wallabag is free (as in freedom) and open source.</p>\n</div>\n\n</div>\n<div class=\"row\">\n<div class=\"col-lg-8 col-md-12 col-xs-12 col-sm-12\">\n<p>With this application you will not miss content anymore. <strong>Click, save, read it when you want</strong>. It saves the content you select so that you can read it when you have time.</p>\n</div>\n\n</div>\n<div class=\"row\">\n<div class=\"col-lg-6 col-md-12 col-xs-12 col-sm-12\">\n<h2>How it works</h2>\n<p>Thanks to the bookmarklet or <a title=\"Downloads\" href=\"http://www.wallabag.org/downloads/\">third-party applications</a>, you save an article in your wallabag to read it later. Then, when you open your wallabag, <strong>you can comfortably read your articles</strong>.</p>\n<h2>How to use wallabag</h2>\n<p>There are two ways to use wallabag: you can <a href=\"http://www.wallabag.org/frequently-asked-questions/#How_can_I_install_wallabag_and_what_are_the_requirements\">install it</a> on your web server or you can <a href=\"http://app.inthepoche.com\">create an account</a> at Framabag (we install and upgrade wallabag for you).</p>\n</div>\n\n</div>\n",
|
||||
"user_id": "1"
|
||||
},
|
||||
{
|
||||
"0": "4",
|
||||
"1": "Sans titre",
|
||||
"2": "http:\/\/www.konradlischka.info\/2016\/01\/blog\/wie-ein-deutsches-start-up-mit-wagniskapital-die-marktluecke-fuer-lokalen-digitaljournalismus-schliessen-will\/",
|
||||
"3": "0",
|
||||
"4": "0",
|
||||
"5": "[unable to retrieve full-text content]",
|
||||
"6": "1",
|
||||
"id": "4",
|
||||
"title": "Sans titre",
|
||||
"url": "http:\/\/www.konradlischka.info\/2016\/01\/blog\/wie-ein-deutsches-start-up-mit-wagniskapital-die-marktluecke-fuer-lokalen-digitaljournalismus-schliessen-will\/",
|
||||
"is_read": "0",
|
||||
"is_fav": "0",
|
||||
"content": "[unable to retrieve full-text content]",
|
||||
"user_id": "1"
|
||||
}
|
||||
]
|
||||
|
|
File diff suppressed because one or more lines are too long
Loading…
Reference in a new issue