Skip to content

Commit

Permalink
#30057: Corrected UpdateRenditionsOnConfigChange plugin logic
Browse files Browse the repository at this point in the history
  • Loading branch information
sivaschenko committed Sep 16, 2020
1 parent 4e20d29 commit 746ee90
Showing 1 changed file with 21 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -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;
}

Expand All @@ -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();
}

Expand All @@ -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;
}

/**
Expand All @@ -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();
}
}

0 comments on commit 746ee90

Please sign in to comment.