Skip to content

Commit

Permalink
Add flag to force enable DIO regardless of the full page cache config…
Browse files Browse the repository at this point in the history
…uration
  • Loading branch information
convenient committed Jul 4, 2024
1 parent dd786e2 commit 1066e78
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 0 deletions.
10 changes: 10 additions & 0 deletions Model/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,12 @@ class Config extends \Magento\PageCache\Model\Config
const XML_FASTLY_IMAGE_OPTIMIZATIONS
= 'system/full_page_cache/fastly/fastly_image_optimization_configuration/image_optimizations';

/**
* XML path to image optimizations flag forced
*/
const XML_FASTLY_IMAGE_OPTIMIZATIONS_FORCED
= 'system/full_page_cache/fastly/fastly_image_optimization_configuration/image_optimizations_forced';

/**
* XML path to automatic compression flag
*/
Expand Down Expand Up @@ -828,6 +834,10 @@ public function getGeoIpRedirectMapping()
*/
public function isImageOptimizationEnabled()
{
if ($this->_scopeConfig->isSetFlag(self::XML_FASTLY_IMAGE_OPTIMIZATIONS_FORCED)) {
return true;
}

if ($this->isFastlyEnabled() !== true) {
return false;
}
Expand Down
8 changes: 8 additions & 0 deletions Model/Product/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ private function isFastlyImageOptimizationEnabled()
$this->isFastlyEnabled = false;
}

if ($this->_scopeConfig->isSetFlag(Config::XML_FASTLY_IMAGE_OPTIMIZATIONS_FORCED)) {
$this->isFastlyEnabled = true;
}

return $this->isFastlyEnabled;
}

Expand All @@ -100,6 +104,10 @@ public function isForceLossyEnabled()
$this->isForceLossyEnabled = false;
}

if ($this->_scopeConfig->isSetFlag(Config::XML_FASTLY_IMAGE_OPTIMIZATIONS_FORCED)) {
$this->isFastlyEnabled = true;
}

return $this->isForceLossyEnabled;
}

Expand Down
8 changes: 8 additions & 0 deletions Model/View/Asset/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,10 @@ private function isFastlyImageOptimizationEnabled()
$this->isFastlyEnabled = false;
}

if ($this->scopeConfig->isSetFlag(Config::XML_FASTLY_IMAGE_OPTIMIZATIONS_FORCED)) {
$this->isFastlyEnabled = true;
}

return $this->isFastlyEnabled;
}

Expand All @@ -204,6 +208,10 @@ public function isForceLossyEnabled()
$this->isForceLossyEnabled = false;
}

if ($this->scopeConfig->isSetFlag(Config::XML_FASTLY_IMAGE_OPTIMIZATIONS_FORCED)) {
$this->isFastlyEnabled = true;
}

return $this->isForceLossyEnabled;
}

Expand Down
8 changes: 8 additions & 0 deletions etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,14 @@
target="_blank">image optimization guide</a> for caveats and details.]]></comment>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
<!-- ===============================================
Force Enable Deep Image Optimization select field
================================================ -->
<field id="image_optimizations_forced" translate="label comment" type="select" sortOrder="20" showInDefault="1" showInWebsite="0" showInStore="0">
<label>Force Enable Deep Image Optimization</label>
<comment><![CDATA[Use this to forcefully enable deep image optimisation on instances that are not connected to fastly, for use on test environments]]></comment>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
<!-- ====================================================
JPEG image quality input field
===================================================== -->
Expand Down
1 change: 1 addition & 0 deletions etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
</fastly_blocking>
<fastly_image_optimization_configuration>
<image_optimizations>0</image_optimizations>
<image_optimizations_forced>0</image_optimizations_forced>
<image_optimization_force_lossy>0</image_optimization_force_lossy>
<image_optimization_image_quality>80</image_optimization_image_quality>
<image_optimization_bg_color>1</image_optimization_bg_color>
Expand Down

0 comments on commit 1066e78

Please sign in to comment.