diff options
author | Jeremy Benoist <jeremy.benoist@gmail.com> | 2016-10-30 11:27:09 +0100 |
---|---|---|
committer | Jeremy Benoist <jeremy.benoist@gmail.com> | 2016-10-30 11:27:09 +0100 |
commit | 48656e0eaac006a80f21e9aec8900747fe76283a (patch) | |
tree | 8b685bd1b2b68b47a12b2bc17f076683c466603f /src/Wallabag/CoreBundle/Event | |
parent | 7f55941856549a3f5f45c42fdc171d66ff7ee297 (diff) | |
download | wallabag-48656e0eaac006a80f21e9aec8900747fe76283a.tar.gz wallabag-48656e0eaac006a80f21e9aec8900747fe76283a.tar.zst wallabag-48656e0eaac006a80f21e9aec8900747fe76283a.zip |
Fixing tests
Diffstat (limited to 'src/Wallabag/CoreBundle/Event')
-rw-r--r-- | src/Wallabag/CoreBundle/Event/Subscriber/DownloadImagesSubscriber.php | 31 |
1 files changed, 24 insertions, 7 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')) { |