Errors in the automatic tagging do not prevent the entry from being added

This commit is contained in:
Kévin Gomez 2015-10-17 17:45:51 +02:00
parent 1dc4e5da2e
commit 1c9cd2a7f0
3 changed files with 21 additions and 5 deletions

View File

@ -3,6 +3,7 @@
namespace Wallabag\CoreBundle\Helper; namespace Wallabag\CoreBundle\Helper;
use Graby\Graby; use Graby\Graby;
use Psr\Log\LoggerInterface as Logger;
use Wallabag\CoreBundle\Entity\Entry; use Wallabag\CoreBundle\Entity\Entry;
use Wallabag\CoreBundle\Tools\Utils; use Wallabag\CoreBundle\Tools\Utils;
@ -14,11 +15,13 @@ class ContentProxy
{ {
protected $graby; protected $graby;
protected $tagger; protected $tagger;
protected $logger;
public function __construct(Graby $graby, RuleBasedTagger $tagger) public function __construct(Graby $graby, RuleBasedTagger $tagger, Logger $logger)
{ {
$this->graby = $graby; $this->graby = $graby;
$this->tagger = $tagger; $this->tagger = $tagger;
$this->logger = $logger;
} }
/** /**
@ -61,7 +64,14 @@ class ContentProxy
$entry->setPreviewPicture($content['open_graph']['og_image']); $entry->setPreviewPicture($content['open_graph']['og_image']);
} }
try {
$this->tagger->tag($entry); $this->tagger->tag($entry);
} catch (\Exception $e) {
$this->logger->error('Error while trying to automatically tag an entry.', array(
'entry_url' => $url,
'error_msg' => $e->getMessage(),
));
}
return $entry; return $entry;
} }

View File

@ -54,6 +54,7 @@ services:
arguments: arguments:
- @wallabag_core.graby - @wallabag_core.graby
- @wallabag_core.rule_based_tagger - @wallabag_core.rule_based_tagger
- @logger
wallabag_core.rule_based_tagger: wallabag_core.rule_based_tagger:
class: Wallabag\CoreBundle\Helper\RuleBasedTagger class: Wallabag\CoreBundle\Helper\RuleBasedTagger

View File

@ -29,7 +29,7 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase
'language' => '', 'language' => '',
)); ));
$proxy = new ContentProxy($graby, $tagger); $proxy = new ContentProxy($graby, $tagger, $this->getLoggerMock());
$entry = $proxy->updateEntry(new Entry(new User()), 'http://0.0.0.0'); $entry = $proxy->updateEntry(new Entry(new User()), 'http://0.0.0.0');
$this->assertEquals('http://0.0.0.0', $entry->getUrl()); $this->assertEquals('http://0.0.0.0', $entry->getUrl());
@ -67,7 +67,7 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase
), ),
)); ));
$proxy = new ContentProxy($graby, $tagger); $proxy = new ContentProxy($graby, $tagger, $this->getLoggerMock());
$entry = $proxy->updateEntry(new Entry(new User()), 'http://domain.io'); $entry = $proxy->updateEntry(new Entry(new User()), 'http://domain.io');
$this->assertEquals('http://domain.io', $entry->getUrl()); $this->assertEquals('http://domain.io', $entry->getUrl());
@ -106,7 +106,7 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase
), ),
)); ));
$proxy = new ContentProxy($graby, $tagger); $proxy = new ContentProxy($graby, $tagger, $this->getLoggerMock());
$entry = $proxy->updateEntry(new Entry(new User()), 'http://0.0.0.0'); $entry = $proxy->updateEntry(new Entry(new User()), 'http://0.0.0.0');
$this->assertEquals('http://1.1.1.1', $entry->getUrl()); $this->assertEquals('http://1.1.1.1', $entry->getUrl());
@ -126,4 +126,9 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock(); ->getMock();
} }
private function getLoggerMock()
{
return $this->getMock('Psr\Log\LoggerInterface');
}
} }