]> git.immae.eu Git - github/wallabag/wallabag.git/commitdiff
Errors in the automatic tagging do not prevent the entry from being added
authorKévin Gomez <contact@kevingomez.fr>
Sat, 17 Oct 2015 15:45:51 +0000 (17:45 +0200)
committerKévin Gomez <contact@kevingomez.fr>
Wed, 11 Nov 2015 15:23:49 +0000 (16:23 +0100)
src/Wallabag/CoreBundle/Helper/ContentProxy.php
src/Wallabag/CoreBundle/Resources/config/services.yml
src/Wallabag/CoreBundle/Tests/Helper/ContentProxyTest.php

index dc6e1184cd34e08fc10797f20668879ed94e63f8..3d585e6180786222603cb3f0be2e76b3ac18c8af 100644 (file)
@@ -3,6 +3,7 @@
 namespace Wallabag\CoreBundle\Helper;
 
 use Graby\Graby;
+use Psr\Log\LoggerInterface as Logger;
 use Wallabag\CoreBundle\Entity\Entry;
 use Wallabag\CoreBundle\Tools\Utils;
 
@@ -14,11 +15,13 @@ class ContentProxy
 {
     protected $graby;
     protected $tagger;
+    protected $logger;
 
-    public function __construct(Graby $graby, RuleBasedTagger $tagger)
+    public function __construct(Graby $graby, RuleBasedTagger $tagger, Logger $logger)
     {
         $this->graby  = $graby;
         $this->tagger = $tagger;
+        $this->logger = $logger;
     }
 
     /**
@@ -61,7 +64,14 @@ class ContentProxy
             $entry->setPreviewPicture($content['open_graph']['og_image']);
         }
 
-        $this->tagger->tag($entry);
+        try {
+            $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;
     }
index 4cf46b33984e7f59d35e0b3d2b305597954108b7..0100a62d967486955769f0d2f9a05236e7321cb8 100644 (file)
@@ -54,6 +54,7 @@ services:
         arguments:
             - @wallabag_core.graby
             - @wallabag_core.rule_based_tagger
+            - @logger
 
     wallabag_core.rule_based_tagger:
         class: Wallabag\CoreBundle\Helper\RuleBasedTagger
index 1688a48a7c974e31ecf2943f30285656e3ee5329..f59edb0c9746ff55d7f122df4c3529f252defbc6 100644 (file)
@@ -29,7 +29,7 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase
                 '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');
 
         $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');
 
         $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');
 
         $this->assertEquals('http://1.1.1.1', $entry->getUrl());
@@ -126,4 +126,9 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase
             ->disableOriginalConstructor()
             ->getMock();
     }
+
+    private function getLoggerMock()
+    {
+        return $this->getMock('Psr\Log\LoggerInterface');
+    }
 }