88namespace Magento \MediaGalleryRenditions \Plugin ;
99
1010use Magento \Framework \App \Config \Value ;
11+ use Magento \MediaGalleryRenditions \Model \Config ;
1112use Magento \MediaGalleryRenditions \Model \Queue \ScheduleRenditionsUpdate ;
1213
1314/**
@@ -25,10 +26,17 @@ class UpdateRenditionsOnConfigChange
2526 private $ scheduleRenditionsUpdate ;
2627
2728 /**
29+ * @var Config
30+ */
31+ private $ config ;
32+
33+ /**
34+ * @param Config $config
2835 * @param ScheduleRenditionsUpdate $scheduleRenditionsUpdate
2936 */
30- public function __construct (ScheduleRenditionsUpdate $ scheduleRenditionsUpdate )
37+ public function __construct (Config $ config , ScheduleRenditionsUpdate $ scheduleRenditionsUpdate )
3138 {
39+ $ this ->config = $ config ;
3240 $ this ->scheduleRenditionsUpdate = $ scheduleRenditionsUpdate ;
3341 }
3442
@@ -42,8 +50,13 @@ public function __construct(ScheduleRenditionsUpdate $scheduleRenditionsUpdate)
4250 */
4351 public function afterSave (Value $ config , Value $ result ): Value
4452 {
45- if ($ this ->isMediaGalleryRenditionsEnabled ($ result ) && $ this ->isRenditionsValue ($ result )
46- && $ result ->isValueChanged ()) {
53+ if ($ this ->isRenditionsEnabled ($ result )) {
54+ $ this ->scheduleRenditionsUpdate ->execute ();
55+
56+ return $ result ;
57+ }
58+
59+ if ($ this ->config ->isEnabled () && $ this ->isRenditionsValue ($ result ) && $ result ->isValueChanged ()) {
4760 $ this ->scheduleRenditionsUpdate ->execute ();
4861 }
4962
@@ -59,8 +72,7 @@ public function afterSave(Value $config, Value $result): Value
5972 private function isRenditionsValue (Value $ value ): bool
6073 {
6174 return $ value ->getPath () === self ::XML_PATH_MEDIA_GALLERY_RENDITIONS_WIDTH_PATH
62- || $ value ->getPath () === self ::XML_PATH_MEDIA_GALLERY_RENDITIONS_HEIGHT_PATH
63- || $ value ->getPath () === self ::XML_PATH_MEDIA_GALLERY_RENDITIONS_ENABLE_PATH ;
75+ || $ value ->getPath () === self ::XML_PATH_MEDIA_GALLERY_RENDITIONS_HEIGHT_PATH ;
6476 }
6577
6678 /**
@@ -69,8 +81,10 @@ private function isRenditionsValue(Value $value): bool
6981 * @param Value $value
7082 * @return bool
7183 */
72- private function isMediaGalleryRenditionsEnabled (Value $ value ): bool
84+ private function isRenditionsEnabled (Value $ value ): bool
7385 {
74- return $ value ->getPath () === self ::XML_PATH_MEDIA_GALLERY_RENDITIONS_ENABLE_PATH && $ value ->getValue ();
86+ return $ value ->getPath () === self ::XML_PATH_MEDIA_GALLERY_RENDITIONS_ENABLE_PATH
87+ && $ value ->isValueChanged ()
88+ && $ value ->getValue ();
7589 }
7690}
0 commit comments