From 746ee90c22a28b4d1aad6a41a8ced0855246d560 Mon Sep 17 00:00:00 2001 From: Sergii Ivashchenko Date: Wed, 16 Sep 2020 19:22:05 +0300 Subject: [PATCH] magento/magento2#30057: Corrected UpdateRenditionsOnConfigChange plugin logic --- .../Plugin/UpdateRenditionsOnConfigChange.php | 28 ++++++++++++++----- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/app/code/Magento/MediaGalleryRenditions/Plugin/UpdateRenditionsOnConfigChange.php b/app/code/Magento/MediaGalleryRenditions/Plugin/UpdateRenditionsOnConfigChange.php index 2b7645473535a..6fcb37398f3ad 100644 --- a/app/code/Magento/MediaGalleryRenditions/Plugin/UpdateRenditionsOnConfigChange.php +++ b/app/code/Magento/MediaGalleryRenditions/Plugin/UpdateRenditionsOnConfigChange.php @@ -8,6 +8,7 @@ namespace Magento\MediaGalleryRenditions\Plugin; use Magento\Framework\App\Config\Value; +use Magento\MediaGalleryRenditions\Model\Config; use Magento\MediaGalleryRenditions\Model\Queue\ScheduleRenditionsUpdate; /** @@ -25,10 +26,17 @@ class UpdateRenditionsOnConfigChange private $scheduleRenditionsUpdate; /** + * @var Config + */ + private $config; + + /** + * @param Config $config * @param ScheduleRenditionsUpdate $scheduleRenditionsUpdate */ - public function __construct(ScheduleRenditionsUpdate $scheduleRenditionsUpdate) + public function __construct(Config $config, ScheduleRenditionsUpdate $scheduleRenditionsUpdate) { + $this->config = $config; $this->scheduleRenditionsUpdate = $scheduleRenditionsUpdate; } @@ -42,8 +50,13 @@ public function __construct(ScheduleRenditionsUpdate $scheduleRenditionsUpdate) */ public function afterSave(Value $config, Value $result): Value { - if ($this->isMediaGalleryRenditionsEnabled($result) && $this->isRenditionsValue($result) - && $result->isValueChanged()) { + if ($this->isRenditionsEnabled($result)) { + $this->scheduleRenditionsUpdate->execute(); + + return $result; + } + + if ($this->config->isEnabled() && $this->isRenditionsValue($result) && $result->isValueChanged()) { $this->scheduleRenditionsUpdate->execute(); } @@ -59,8 +72,7 @@ public function afterSave(Value $config, Value $result): Value private function isRenditionsValue(Value $value): bool { return $value->getPath() === self::XML_PATH_MEDIA_GALLERY_RENDITIONS_WIDTH_PATH - || $value->getPath() === self::XML_PATH_MEDIA_GALLERY_RENDITIONS_HEIGHT_PATH - || $value->getPath() === self::XML_PATH_MEDIA_GALLERY_RENDITIONS_ENABLE_PATH; + || $value->getPath() === self::XML_PATH_MEDIA_GALLERY_RENDITIONS_HEIGHT_PATH; } /** @@ -69,8 +81,10 @@ private function isRenditionsValue(Value $value): bool * @param Value $value * @return bool */ - private function isMediaGalleryRenditionsEnabled(Value $value): bool + private function isRenditionsEnabled(Value $value): bool { - return $value->getPath() === self::XML_PATH_MEDIA_GALLERY_RENDITIONS_ENABLE_PATH && $value->getValue(); + return $value->getPath() === self::XML_PATH_MEDIA_GALLERY_RENDITIONS_ENABLE_PATH + && $value->isValueChanged() + && $value->getValue(); } }