]> git.immae.eu Git - github/wallabag/wallabag.git/blobdiff - src/Wallabag/CoreBundle/Event/Subscriber/DownloadImagesSubscriber.php
Fixing tests
[github/wallabag/wallabag.git] / src / Wallabag / CoreBundle / Event / Subscriber / DownloadImagesSubscriber.php
index 654edf31078184e1e13e46dba4b4de85a966e596..09f8e9119767d5f9870ff76091e42a4a9b6c7d2b 100644 (file)
@@ -49,22 +49,23 @@ class DownloadImagesSubscriber implements EventSubscriber
             return;
         }
 
-        $em = $args->getEntityManager();
+        $config = new $this->configClass();
+        $config->setEntityManager($args->getEntityManager());
 
         // field content has been updated
         if ($args->hasChangedField('content')) {
-            $html = $this->downloadImages($em, $entity);
+            $html = $this->downloadImages($config, $entity);
 
-            if (null !== $html) {
+            if (false !== $html) {
                 $args->setNewValue('content', $html);
             }
         }
 
         // field preview picture has been updated
         if ($args->hasChangedField('previewPicture')) {
-            $previewPicture = $this->downloadPreviewImage($em, $entity);
+            $previewPicture = $this->downloadPreviewImage($config, $entity);
 
-            if (null !== $previewPicture) {
+            if (false !== $previewPicture) {
                 $entity->setPreviewPicture($previewPicture);
             }
         }
@@ -88,17 +89,25 @@ class DownloadImagesSubscriber implements EventSubscriber
 
         // update all images inside the html
         $html = $this->downloadImages($config, $entity);
-        if (null !== $html) {
+        if (false !== $html) {
             $entity->setContent($html);
         }
 
         // update preview picture
         $previewPicture = $this->downloadPreviewImage($config, $entity);
-        if (null !== $previewPicture) {
+        if (false !== $previewPicture) {
             $entity->setPreviewPicture($previewPicture);
         }
     }
 
+    /**
+     * Download all images from the html.
+     *
+     * @param Config $config
+     * @param Entry  $entry
+     *
+     * @return string|false False in case of async
+     */
     public function downloadImages(Config $config, Entry $entry)
     {
         // if ($config->get('download_images_with_rabbitmq')) {
@@ -113,6 +122,14 @@ class DownloadImagesSubscriber implements EventSubscriber
         );
     }
 
+    /**
+     * Download the preview picture.
+     *
+     * @param Config $config
+     * @param Entry  $entry
+     *
+     * @return string|false False in case of async
+     */
     public function downloadPreviewImage(Config $config, Entry $entry)
     {
         // if ($config->get('download_images_with_rabbitmq')) {