]> git.immae.eu Git - github/wallabag/wallabag.git/blobdiff - src/Wallabag/CoreBundle/Helper/ContentProxy.php
Fix tests
[github/wallabag/wallabag.git] / src / Wallabag / CoreBundle / Helper / ContentProxy.php
index 88873bd5305bab6dba0f553b158c0a862468bc22..cd18c668f7ea3b1b342260bca27591a6022c4103 100644 (file)
@@ -34,13 +34,17 @@ class ContentProxy
     /**
      * Update existing entry by fetching from URL using Graby.
      *
-     * @param Entry  $entry   Entry to update
-     * @param string $url     Url to grab content for
+     * @param Entry  $entry Entry to update
+     * @param string $url   Url to grab content for
      */
     public function updateEntry(Entry $entry, $url)
     {
         $content = $this->graby->fetchContent($url);
 
+        // be sure to keep the url in case of error
+        // so we'll be able to refetch it in the future
+        $content['url'] = $content['url'] ?: $url;
+
         $this->stockEntry($entry, $content);
     }
 
@@ -53,7 +57,14 @@ class ContentProxy
      */
     public function importEntry(Entry $entry, array $content, $disableContentUpdate = false)
     {
-        $this->validateContent($content);
+        try {
+            $this->validateContent($content);
+        } catch (\Exception $e) {
+            // validation failed but do we want to disable updating content?
+            if (true === $disableContentUpdate) {
+                throw $e;
+            }
+        }
 
         if (false === $disableContentUpdate) {
             try {
@@ -79,8 +90,8 @@ class ContentProxy
      * Stock entry with fetched or imported content.
      * Will fall back to OpenGraph data if available.
      *
-     * @param Entry  $entry   Entry to stock
-     * @param array  $content Array with at least title and URL
+     * @param Entry $entry   Entry to stock
+     * @param array $content Array with at least title and URL
      */
     private function stockEntry(Entry $entry, array $content)
     {
@@ -162,15 +173,15 @@ class ContentProxy
      */
     private function validateContent(array $content)
     {
-        if (!empty($content['title']))) {
+        if (empty($content['title'])) {
             throw new Exception('Missing title from imported entry!');
         }
 
-        if (!empty($content['url']))) {
+        if (empty($content['url'])) {
             throw new Exception('Missing URL from imported entry!');
         }
 
-        if (!empty($content['html']))) {
+        if (empty($content['html'])) {
             throw new Exception('Missing html from imported entry!');
         }
     }