Skip to content

Commit 746ee90

Browse files
committed
#30057: Corrected UpdateRenditionsOnConfigChange plugin logic
1 parent 4e20d29 commit 746ee90

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

app/code/Magento/MediaGalleryRenditions/Plugin/UpdateRenditionsOnConfigChange.php

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
namespace Magento\MediaGalleryRenditions\Plugin;
99

1010
use Magento\Framework\App\Config\Value;
11+
use Magento\MediaGalleryRenditions\Model\Config;
1112
use 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

Comments
 (0)