diff options
-rw-r--r-- | src/Wallabag/CoreBundle/Event/Subscriber/DownloadImagesSubscriber.php | 31 | ||||
-rw-r--r-- | src/Wallabag/CoreBundle/Helper/ContentProxy.php | 3 | ||||
-rw-r--r-- | src/Wallabag/CoreBundle/Helper/DownloadImages.php | 21 | ||||
-rw-r--r-- | tests/Wallabag/CoreBundle/Event/Listener/LocaleListenerTest.php (renamed from tests/Wallabag/CoreBundle/EventListener/LocaleListenerTest.php) | 4 | ||||
-rw-r--r-- | tests/Wallabag/CoreBundle/Event/Listener/UserLocaleListenerTest.php (renamed from tests/Wallabag/CoreBundle/EventListener/UserLocaleListenerTest.php) | 4 | ||||
-rw-r--r-- | tests/Wallabag/CoreBundle/Event/Subscriber/TablePrefixSubscriberTest.php (renamed from tests/Wallabag/CoreBundle/Subscriber/TablePrefixSubscriberTest.php) | 4 | ||||
-rw-r--r-- | tests/Wallabag/CoreBundle/Helper/DownloadImagesTest.php | 19 |
7 files changed, 63 insertions, 23 deletions
diff --git a/src/Wallabag/CoreBundle/Event/Subscriber/DownloadImagesSubscriber.php b/src/Wallabag/CoreBundle/Event/Subscriber/DownloadImagesSubscriber.php index 654edf31..09f8e911 100644 --- a/src/Wallabag/CoreBundle/Event/Subscriber/DownloadImagesSubscriber.php +++ b/src/Wallabag/CoreBundle/Event/Subscriber/DownloadImagesSubscriber.php | |||
@@ -49,22 +49,23 @@ class DownloadImagesSubscriber implements EventSubscriber | |||
49 | return; | 49 | return; |
50 | } | 50 | } |
51 | 51 | ||
52 | $em = $args->getEntityManager(); | 52 | $config = new $this->configClass(); |
53 | $config->setEntityManager($args->getEntityManager()); | ||
53 | 54 | ||
54 | // field content has been updated | 55 | // field content has been updated |
55 | if ($args->hasChangedField('content')) { | 56 | if ($args->hasChangedField('content')) { |
56 | $html = $this->downloadImages($em, $entity); | 57 | $html = $this->downloadImages($config, $entity); |
57 | 58 | ||
58 | if (null !== $html) { | 59 | if (false !== $html) { |
59 | $args->setNewValue('content', $html); | 60 | $args->setNewValue('content', $html); |
60 | } | 61 | } |
61 | } | 62 | } |
62 | 63 | ||
63 | // field preview picture has been updated | 64 | // field preview picture has been updated |
64 | if ($args->hasChangedField('previewPicture')) { | 65 | if ($args->hasChangedField('previewPicture')) { |
65 | $previewPicture = $this->downloadPreviewImage($em, $entity); | 66 | $previewPicture = $this->downloadPreviewImage($config, $entity); |
66 | 67 | ||
67 | if (null !== $previewPicture) { | 68 | if (false !== $previewPicture) { |
68 | $entity->setPreviewPicture($previewPicture); | 69 | $entity->setPreviewPicture($previewPicture); |
69 | } | 70 | } |
70 | } | 71 | } |
@@ -88,17 +89,25 @@ class DownloadImagesSubscriber implements EventSubscriber | |||
88 | 89 | ||
89 | // update all images inside the html | 90 | // update all images inside the html |
90 | $html = $this->downloadImages($config, $entity); | 91 | $html = $this->downloadImages($config, $entity); |
91 | if (null !== $html) { | 92 | if (false !== $html) { |
92 | $entity->setContent($html); | 93 | $entity->setContent($html); |
93 | } | 94 | } |
94 | 95 | ||
95 | // update preview picture | 96 | // update preview picture |
96 | $previewPicture = $this->downloadPreviewImage($config, $entity); | 97 | $previewPicture = $this->downloadPreviewImage($config, $entity); |
97 | if (null !== $previewPicture) { | 98 | if (false !== $previewPicture) { |
98 | $entity->setPreviewPicture($previewPicture); | 99 | $entity->setPreviewPicture($previewPicture); |
99 | } | 100 | } |
100 | } | 101 | } |
101 | 102 | ||
103 | /** | ||
104 | * Download all images from the html. | ||
105 | * | ||
106 | * @param Config $config | ||
107 | * @param Entry $entry | ||
108 | * | ||
109 | * @return string|false False in case of async | ||
110 | */ | ||
102 | public function downloadImages(Config $config, Entry $entry) | 111 | public function downloadImages(Config $config, Entry $entry) |
103 | { | 112 | { |
104 | // if ($config->get('download_images_with_rabbitmq')) { | 113 | // if ($config->get('download_images_with_rabbitmq')) { |
@@ -113,6 +122,14 @@ class DownloadImagesSubscriber implements EventSubscriber | |||
113 | ); | 122 | ); |
114 | } | 123 | } |
115 | 124 | ||
125 | /** | ||
126 | * Download the preview picture. | ||
127 | * | ||
128 | * @param Config $config | ||
129 | * @param Entry $entry | ||
130 | * | ||
131 | * @return string|false False in case of async | ||
132 | */ | ||
116 | public function downloadPreviewImage(Config $config, Entry $entry) | 133 | public function downloadPreviewImage(Config $config, Entry $entry) |
117 | { | 134 | { |
118 | // if ($config->get('download_images_with_rabbitmq')) { | 135 | // if ($config->get('download_images_with_rabbitmq')) { |
diff --git a/src/Wallabag/CoreBundle/Helper/ContentProxy.php b/src/Wallabag/CoreBundle/Helper/ContentProxy.php index d90d3dc8..1986ab33 100644 --- a/src/Wallabag/CoreBundle/Helper/ContentProxy.php +++ b/src/Wallabag/CoreBundle/Helper/ContentProxy.php | |||
@@ -65,6 +65,7 @@ class ContentProxy | |||
65 | 65 | ||
66 | $entry->setUrl($content['url'] ?: $url); | 66 | $entry->setUrl($content['url'] ?: $url); |
67 | $entry->setTitle($title); | 67 | $entry->setTitle($title); |
68 | $entry->setContent($html); | ||
68 | 69 | ||
69 | $entry->setLanguage($content['language']); | 70 | $entry->setLanguage($content['language']); |
70 | $entry->setMimetype($content['content_type']); | 71 | $entry->setMimetype($content['content_type']); |
@@ -75,8 +76,6 @@ class ContentProxy | |||
75 | $entry->setDomainName($domainName); | 76 | $entry->setDomainName($domainName); |
76 | } | 77 | } |
77 | 78 | ||
78 | $entry->setContent($html); | ||
79 | |||
80 | if (isset($content['open_graph']['og_image'])) { | 79 | if (isset($content['open_graph']['og_image'])) { |
81 | $entry->setPreviewPicture($content['open_graph']['og_image']); | 80 | $entry->setPreviewPicture($content['open_graph']['og_image']); |
82 | } | 81 | } |
diff --git a/src/Wallabag/CoreBundle/Helper/DownloadImages.php b/src/Wallabag/CoreBundle/Helper/DownloadImages.php index 426cbe48..004bb277 100644 --- a/src/Wallabag/CoreBundle/Helper/DownloadImages.php +++ b/src/Wallabag/CoreBundle/Helper/DownloadImages.php | |||
@@ -91,20 +91,23 @@ class DownloadImages | |||
91 | // build image path | 91 | // build image path |
92 | $absolutePath = $this->getAbsoluteLink($url, $imagePath); | 92 | $absolutePath = $this->getAbsoluteLink($url, $imagePath); |
93 | if (false === $absolutePath) { | 93 | if (false === $absolutePath) { |
94 | $this->logger->log('debug', 'Can not determine the absolute path for that image, skipping.'); | 94 | $this->logger->log('error', 'Can not determine the absolute path for that image, skipping.'); |
95 | 95 | ||
96 | return false; | 96 | return false; |
97 | } | 97 | } |
98 | 98 | ||
99 | $res = $this->client->get( | 99 | try { |
100 | $absolutePath, | 100 | $res = $this->client->get($absolutePath); |
101 | ['exceptions' => false] | 101 | } catch (\Exception $e) { |
102 | ); | 102 | $this->logger->log('error', 'Can not retrieve image, skipping.', ['exception' => $e]); |
103 | |||
104 | return false; | ||
105 | } | ||
103 | 106 | ||
104 | $ext = $this->mimeGuesser->guess($res->getHeader('content-type')); | 107 | $ext = $this->mimeGuesser->guess($res->getHeader('content-type')); |
105 | $this->logger->log('debug', 'Checking extension', ['ext' => $ext, 'header' => $res->getHeader('content-type')]); | 108 | $this->logger->log('debug', 'Checking extension', ['ext' => $ext, 'header' => $res->getHeader('content-type')]); |
106 | if (!in_array($ext, ['jpeg', 'jpg', 'gif', 'png'])) { | 109 | if (!in_array($ext, ['jpeg', 'jpg', 'gif', 'png'], true)) { |
107 | $this->logger->log('debug', 'Processed image with not allowed extension. Skipping '.$imagePath); | 110 | $this->logger->log('error', 'Processed image with not allowed extension. Skipping '.$imagePath); |
108 | 111 | ||
109 | return false; | 112 | return false; |
110 | } | 113 | } |
@@ -117,7 +120,7 @@ class DownloadImages | |||
117 | $im = false; | 120 | $im = false; |
118 | } | 121 | } |
119 | 122 | ||
120 | if ($im === false) { | 123 | if (false === $im) { |
121 | $this->logger->log('error', 'Error while regenerating image', ['path' => $localPath]); | 124 | $this->logger->log('error', 'Error while regenerating image', ['path' => $localPath]); |
122 | 125 | ||
123 | return false; | 126 | return false; |
@@ -193,6 +196,8 @@ class DownloadImages | |||
193 | return $absolute->get_uri(); | 196 | return $absolute->get_uri(); |
194 | } | 197 | } |
195 | 198 | ||
199 | $this->logger->log('error', 'Can not make an absolute link', ['base' => $base, 'url' => $url]); | ||
200 | |||
196 | return false; | 201 | return false; |
197 | } | 202 | } |
198 | } | 203 | } |
diff --git a/tests/Wallabag/CoreBundle/EventListener/LocaleListenerTest.php b/tests/Wallabag/CoreBundle/Event/Listener/LocaleListenerTest.php index 078bb69a..84a54d3a 100644 --- a/tests/Wallabag/CoreBundle/EventListener/LocaleListenerTest.php +++ b/tests/Wallabag/CoreBundle/Event/Listener/LocaleListenerTest.php | |||
@@ -1,6 +1,6 @@ | |||
1 | <?php | 1 | <?php |
2 | 2 | ||
3 | namespace Tests\Wallabag\CoreBundle\EventListener; | 3 | namespace Tests\Wallabag\CoreBundle\Event\Listener; |
4 | 4 | ||
5 | use Symfony\Component\EventDispatcher\EventDispatcher; | 5 | use Symfony\Component\EventDispatcher\EventDispatcher; |
6 | use Symfony\Component\HttpFoundation\Request; | 6 | use Symfony\Component\HttpFoundation\Request; |
@@ -9,7 +9,7 @@ use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage; | |||
9 | use Symfony\Component\HttpKernel\Event\GetResponseEvent; | 9 | use Symfony\Component\HttpKernel\Event\GetResponseEvent; |
10 | use Symfony\Component\HttpKernel\HttpKernelInterface; | 10 | use Symfony\Component\HttpKernel\HttpKernelInterface; |
11 | use Symfony\Component\HttpKernel\KernelEvents; | 11 | use Symfony\Component\HttpKernel\KernelEvents; |
12 | use Wallabag\CoreBundle\EventListener\LocaleListener; | 12 | use Wallabag\CoreBundle\Event\Listener\LocaleListener; |
13 | 13 | ||
14 | class LocaleListenerTest extends \PHPUnit_Framework_TestCase | 14 | class LocaleListenerTest extends \PHPUnit_Framework_TestCase |
15 | { | 15 | { |
diff --git a/tests/Wallabag/CoreBundle/EventListener/UserLocaleListenerTest.php b/tests/Wallabag/CoreBundle/Event/Listener/UserLocaleListenerTest.php index e9ac7c1d..45aecc63 100644 --- a/tests/Wallabag/CoreBundle/EventListener/UserLocaleListenerTest.php +++ b/tests/Wallabag/CoreBundle/Event/Listener/UserLocaleListenerTest.php | |||
@@ -1,6 +1,6 @@ | |||
1 | <?php | 1 | <?php |
2 | 2 | ||
3 | namespace Tests\Wallabag\CoreBundle\EventListener; | 3 | namespace Tests\Wallabag\CoreBundle\Event\Listener; |
4 | 4 | ||
5 | use Symfony\Component\HttpFoundation\Request; | 5 | use Symfony\Component\HttpFoundation\Request; |
6 | use Symfony\Component\HttpFoundation\Session\Session; | 6 | use Symfony\Component\HttpFoundation\Session\Session; |
@@ -8,7 +8,7 @@ use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage; | |||
8 | use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken; | 8 | use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken; |
9 | use Symfony\Component\Security\Http\Event\InteractiveLoginEvent; | 9 | use Symfony\Component\Security\Http\Event\InteractiveLoginEvent; |
10 | use Wallabag\CoreBundle\Entity\Config; | 10 | use Wallabag\CoreBundle\Entity\Config; |
11 | use Wallabag\CoreBundle\EventListener\UserLocaleListener; | 11 | use Wallabag\CoreBundle\Event\Listener\UserLocaleListener; |
12 | use Wallabag\UserBundle\Entity\User; | 12 | use Wallabag\UserBundle\Entity\User; |
13 | 13 | ||
14 | class UserLocaleListenerTest extends \PHPUnit_Framework_TestCase | 14 | class UserLocaleListenerTest extends \PHPUnit_Framework_TestCase |
diff --git a/tests/Wallabag/CoreBundle/Subscriber/TablePrefixSubscriberTest.php b/tests/Wallabag/CoreBundle/Event/Subscriber/TablePrefixSubscriberTest.php index 4ae76703..b8cd0fad 100644 --- a/tests/Wallabag/CoreBundle/Subscriber/TablePrefixSubscriberTest.php +++ b/tests/Wallabag/CoreBundle/Event/Subscriber/TablePrefixSubscriberTest.php | |||
@@ -1,11 +1,11 @@ | |||
1 | <?php | 1 | <?php |
2 | 2 | ||
3 | namespace Tests\Wallabag\CoreBundle\Subscriber; | 3 | namespace Tests\Wallabag\CoreBundle\Event\Subscriber; |
4 | 4 | ||
5 | use Doctrine\Common\EventManager; | 5 | use Doctrine\Common\EventManager; |
6 | use Doctrine\ORM\Event\LoadClassMetadataEventArgs; | 6 | use Doctrine\ORM\Event\LoadClassMetadataEventArgs; |
7 | use Doctrine\ORM\Mapping\ClassMetadata; | 7 | use Doctrine\ORM\Mapping\ClassMetadata; |
8 | use Wallabag\CoreBundle\Subscriber\TablePrefixSubscriber; | 8 | use Wallabag\CoreBundle\Event\Subscriber\TablePrefixSubscriber; |
9 | 9 | ||
10 | class TablePrefixSubscriberTest extends \PHPUnit_Framework_TestCase | 10 | class TablePrefixSubscriberTest extends \PHPUnit_Framework_TestCase |
11 | { | 11 | { |
diff --git a/tests/Wallabag/CoreBundle/Helper/DownloadImagesTest.php b/tests/Wallabag/CoreBundle/Helper/DownloadImagesTest.php index 0273693e..e000d681 100644 --- a/tests/Wallabag/CoreBundle/Helper/DownloadImagesTest.php +++ b/tests/Wallabag/CoreBundle/Helper/DownloadImagesTest.php | |||
@@ -83,6 +83,25 @@ class DownloadImagesTest extends \PHPUnit_Framework_TestCase | |||
83 | $this->assertContains('/assets/images/4/2/4258f71e/ebe60399.'.$extension, $res); | 83 | $this->assertContains('/assets/images/4/2/4258f71e/ebe60399.'.$extension, $res); |
84 | } | 84 | } |
85 | 85 | ||
86 | public function testProcessSingleImageWithBadUrl() | ||
87 | { | ||
88 | $client = new Client(); | ||
89 | |||
90 | $mock = new Mock([ | ||
91 | new Response(404, []), | ||
92 | ]); | ||
93 | |||
94 | $client->getEmitter()->attach($mock); | ||
95 | |||
96 | $logHandler = new TestHandler(); | ||
97 | $logger = new Logger('test', array($logHandler)); | ||
98 | |||
99 | $download = new DownloadImages($client, sys_get_temp_dir().'/wallabag_test', $logger); | ||
100 | $res = $download->processSingleImage('T9qgcHc.jpg', 'http://imgur.com/gallery/WxtWY'); | ||
101 | |||
102 | $this->assertFalse($res, 'Image can not be found, so it will not be replaced'); | ||
103 | } | ||
104 | |||
86 | public function testProcessSingleImageWithBadImage() | 105 | public function testProcessSingleImageWithBadImage() |
87 | { | 106 | { |
88 | $client = new Client(); | 107 | $client = new Client(); |