Skip to content

Commit 1066e78

Browse files
committed
Add flag to force enable DIO regardless of the full page cache configuration
1 parent dd786e2 commit 1066e78

File tree

5 files changed

+35
-0
lines changed

5 files changed

+35
-0
lines changed

Model/Config.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,12 @@ class Config extends \Magento\PageCache\Model\Config
331331
const XML_FASTLY_IMAGE_OPTIMIZATIONS
332332
= 'system/full_page_cache/fastly/fastly_image_optimization_configuration/image_optimizations';
333333

334+
/**
335+
* XML path to image optimizations flag forced
336+
*/
337+
const XML_FASTLY_IMAGE_OPTIMIZATIONS_FORCED
338+
= 'system/full_page_cache/fastly/fastly_image_optimization_configuration/image_optimizations_forced';
339+
334340
/**
335341
* XML path to automatic compression flag
336342
*/
@@ -828,6 +834,10 @@ public function getGeoIpRedirectMapping()
828834
*/
829835
public function isImageOptimizationEnabled()
830836
{
837+
if ($this->_scopeConfig->isSetFlag(self::XML_FASTLY_IMAGE_OPTIMIZATIONS_FORCED)) {
838+
return true;
839+
}
840+
831841
if ($this->isFastlyEnabled() !== true) {
832842
return false;
833843
}

Model/Product/Image.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ private function isFastlyImageOptimizationEnabled()
7878
$this->isFastlyEnabled = false;
7979
}
8080

81+
if ($this->_scopeConfig->isSetFlag(Config::XML_FASTLY_IMAGE_OPTIMIZATIONS_FORCED)) {
82+
$this->isFastlyEnabled = true;
83+
}
84+
8185
return $this->isFastlyEnabled;
8286
}
8387

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

107+
if ($this->_scopeConfig->isSetFlag(Config::XML_FASTLY_IMAGE_OPTIMIZATIONS_FORCED)) {
108+
$this->isFastlyEnabled = true;
109+
}
110+
103111
return $this->isForceLossyEnabled;
104112
}
105113

Model/View/Asset/Image.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,10 @@ private function isFastlyImageOptimizationEnabled()
182182
$this->isFastlyEnabled = false;
183183
}
184184

185+
if ($this->scopeConfig->isSetFlag(Config::XML_FASTLY_IMAGE_OPTIMIZATIONS_FORCED)) {
186+
$this->isFastlyEnabled = true;
187+
}
188+
185189
return $this->isFastlyEnabled;
186190
}
187191

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

211+
if ($this->scopeConfig->isSetFlag(Config::XML_FASTLY_IMAGE_OPTIMIZATIONS_FORCED)) {
212+
$this->isFastlyEnabled = true;
213+
}
214+
207215
return $this->isForceLossyEnabled;
208216
}
209217

etc/adminhtml/system.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,14 @@
496496
target="_blank">image optimization guide</a> for caveats and details.]]></comment>
497497
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
498498
</field>
499+
<!-- ===============================================
500+
Force Enable Deep Image Optimization select field
501+
================================================ -->
502+
<field id="image_optimizations_forced" translate="label comment" type="select" sortOrder="20" showInDefault="1" showInWebsite="0" showInStore="0">
503+
<label>Force Enable Deep Image Optimization</label>
504+
<comment><![CDATA[Use this to forcefully enable deep image optimisation on instances that are not connected to fastly, for use on test environments]]></comment>
505+
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
506+
</field>
499507
<!-- ====================================================
500508
JPEG image quality input field
501509
===================================================== -->

etc/config.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
</fastly_blocking>
4646
<fastly_image_optimization_configuration>
4747
<image_optimizations>0</image_optimizations>
48+
<image_optimizations_forced>0</image_optimizations_forced>
4849
<image_optimization_force_lossy>0</image_optimization_force_lossy>
4950
<image_optimization_image_quality>80</image_optimization_image_quality>
5051
<image_optimization_bg_color>1</image_optimization_bg_color>

0 commit comments

Comments
 (0)