8
8
namespace Magento \MediaGalleryRenditions \Plugin ;
9
9
10
10
use Magento \Framework \App \Config \Value ;
11
+ use Magento \MediaGalleryRenditions \Model \Config ;
11
12
use Magento \MediaGalleryRenditions \Model \Queue \ScheduleRenditionsUpdate ;
12
13
13
14
/**
@@ -25,10 +26,17 @@ class UpdateRenditionsOnConfigChange
25
26
private $ scheduleRenditionsUpdate ;
26
27
27
28
/**
29
+ * @var Config
30
+ */
31
+ private $ config ;
32
+
33
+ /**
34
+ * @param Config $config
28
35
* @param ScheduleRenditionsUpdate $scheduleRenditionsUpdate
29
36
*/
30
- public function __construct (ScheduleRenditionsUpdate $ scheduleRenditionsUpdate )
37
+ public function __construct (Config $ config , ScheduleRenditionsUpdate $ scheduleRenditionsUpdate )
31
38
{
39
+ $ this ->config = $ config ;
32
40
$ this ->scheduleRenditionsUpdate = $ scheduleRenditionsUpdate ;
33
41
}
34
42
@@ -42,8 +50,13 @@ public function __construct(ScheduleRenditionsUpdate $scheduleRenditionsUpdate)
42
50
*/
43
51
public function afterSave (Value $ config , Value $ result ): Value
44
52
{
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 ()) {
47
60
$ this ->scheduleRenditionsUpdate ->execute ();
48
61
}
49
62
@@ -59,8 +72,7 @@ public function afterSave(Value $config, Value $result): Value
59
72
private function isRenditionsValue (Value $ value ): bool
60
73
{
61
74
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 ;
64
76
}
65
77
66
78
/**
@@ -69,8 +81,10 @@ private function isRenditionsValue(Value $value): bool
69
81
* @param Value $value
70
82
* @return bool
71
83
*/
72
- private function isMediaGalleryRenditionsEnabled (Value $ value ): bool
84
+ private function isRenditionsEnabled (Value $ value ): bool
73
85
{
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 ();
75
89
}
76
90
}
0 commit comments