Skip to content

Commit e0f3f49

Browse files
authored
Merge pull request #469 from favicode/fix/issue-466
Fix/issue 466
2 parents a787f86 + b9fc59c commit e0f3f49

File tree

6 files changed

+88
-25
lines changed

6 files changed

+88
-25
lines changed

Diff for: Model/Config.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class Config extends \Magento\PageCache\Model\Config
4545
/**
4646
* Cache types
4747
*/
48-
const FASTLY = 'fastly';
48+
const FASTLY = 42;
4949

5050
/**
5151
* Magento module prefix used for naming vcl snippets, condition and request

Diff for: Model/PageCache/ConfigPlugin.php

+30
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
* @copyright Copyright (c) 2016 Fastly, Inc. (http://www.fastly.com)
1919
* @license BSD, see LICENSE_FASTLY_CDN.txt
2020
*/
21+
2122
namespace Fastly\Cdn\Model\PageCache;
2223

2324
use \Magento\PageCache\Model\Config;
@@ -36,6 +37,18 @@
3637
*/
3738
class ConfigPlugin
3839
{
40+
protected $_scopeConfig;
41+
42+
/**
43+
* ConfigPlugin constructor.
44+
*
45+
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
46+
*/
47+
public function __construct(\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig)
48+
{
49+
$this->_scopeConfig = $scopeConfig;
50+
}
51+
3952
/**
4053
* Return cache type "Varnish" if Fastly is configured.
4154
*
@@ -53,4 +66,21 @@ public function afterGetType(Config $config, $result)
5366
}
5467
return $result;
5568
}
69+
70+
/**
71+
* Change return value from string to int, 'fastly' is old value
72+
*
73+
* @param Config $config
74+
* @param callable $proceed
75+
* @return string|int
76+
*/
77+
public function aroundGetType(Config $config, callable $proceed)
78+
{
79+
if ($this->_scopeConfig->getValue(Config::XML_PAGECACHE_TYPE) === 'fastly') {
80+
$result = \Fastly\Cdn\Model\Config::FASTLY;
81+
} else {
82+
$result = $proceed();
83+
}
84+
return $result;
85+
}
5686
}

Diff for: Setup/UpgradeData.php

+53-20
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
* @copyright Copyright (c) 2016 Fastly, Inc. (http://www.fastly.com)
1919
* @license BSD, see LICENSE_FASTLY_CDN.txt
2020
*/
21+
2122
namespace Fastly\Cdn\Setup;
2223

2324
use Fastly\Cdn\Helper\Data;
@@ -94,7 +95,8 @@ public function __construct(
9495
Data $helper,
9596
ProductMetadataInterface $productMetadata,
9697
SerializerInterface $serializeInterface
97-
) {
98+
)
99+
{
98100
$this->date = $date;
99101
$this->scopeConfig = $scopeConfig;
100102
$this->configWriter = $configWriter;
@@ -111,7 +113,7 @@ public function __construct(
111113
*
112114
*
113115
* @param ModuleDataSetupInterface $setup
114-
* @param ModuleContextInterface $context*
116+
* @param ModuleContextInterface $context *
115117
*/
116118
public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
117119
{
@@ -122,36 +124,36 @@ public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface
122124
}
123125

124126
$oldConfigPaths = [
125-
'stale_ttl' => 'system/full_page_cache/fastly/stale_ttl',
126-
'stale_error_ttl' => 'system/full_page_cache/fastly/stale_error_ttl',
127-
'purge_catalog_category' => 'system/full_page_cache/fastly/purge_catalog_category',
128-
'purge_catalog_product' => 'system/full_page_cache/fastly/purge_catalog_product',
129-
'purge_cms_page' => 'system/full_page_cache/fastly/purge_cms_page',
130-
'soft_purge' => 'system/full_page_cache/fastly/soft_purge',
131-
'enable_geoip' => 'system/full_page_cache/fastly/enable_geoip',
132-
'geoip_action' => 'system/full_page_cache/fastly/geoip_action',
133-
'geoip_country_mapping' => 'system/full_page_cache/fastly/geoip_country_mapping',
127+
'stale_ttl' => 'system/full_page_cache/fastly/stale_ttl',
128+
'stale_error_ttl' => 'system/full_page_cache/fastly/stale_error_ttl',
129+
'purge_catalog_category' => 'system/full_page_cache/fastly/purge_catalog_category',
130+
'purge_catalog_product' => 'system/full_page_cache/fastly/purge_catalog_product',
131+
'purge_cms_page' => 'system/full_page_cache/fastly/purge_cms_page',
132+
'soft_purge' => 'system/full_page_cache/fastly/soft_purge',
133+
'enable_geoip' => 'system/full_page_cache/fastly/enable_geoip',
134+
'geoip_action' => 'system/full_page_cache/fastly/geoip_action',
135+
'geoip_country_mapping' => 'system/full_page_cache/fastly/geoip_country_mapping',
134136
];
135137

136138
$newConfigPaths = [
137139
'stale_ttl'
138-
=> 'system/full_page_cache/fastly/fastly_advanced_configuration/stale_ttl',
140+
=> 'system/full_page_cache/fastly/fastly_advanced_configuration/stale_ttl',
139141
'stale_error_ttl'
140-
=> 'system/full_page_cache/fastly/fastly_advanced_configuration/stale_error_ttl',
142+
=> 'system/full_page_cache/fastly/fastly_advanced_configuration/stale_error_ttl',
141143
'purge_catalog_category'
142-
=> 'system/full_page_cache/fastly/fastly_advanced_configuration/purge_catalog_category',
144+
=> 'system/full_page_cache/fastly/fastly_advanced_configuration/purge_catalog_category',
143145
'purge_catalog_product'
144-
=> 'system/full_page_cache/fastly/fastly_advanced_configuration/purge_catalog_product',
146+
=> 'system/full_page_cache/fastly/fastly_advanced_configuration/purge_catalog_product',
145147
'purge_cms_page'
146-
=> 'system/full_page_cache/fastly/fastly_advanced_configuration/purge_cms_page',
148+
=> 'system/full_page_cache/fastly/fastly_advanced_configuration/purge_cms_page',
147149
'soft_purge'
148-
=> 'system/full_page_cache/fastly/fastly_advanced_configuration/soft_purge',
150+
=> 'system/full_page_cache/fastly/fastly_advanced_configuration/soft_purge',
149151
'enable_geoip'
150-
=> 'system/full_page_cache/fastly/fastly_advanced_configuration/enable_geoip',
152+
=> 'system/full_page_cache/fastly/fastly_advanced_configuration/enable_geoip',
151153
'geoip_action'
152-
=> 'system/full_page_cache/fastly/fastly_advanced_configuration/geoip_action',
154+
=> 'system/full_page_cache/fastly/fastly_advanced_configuration/geoip_action',
153155
'geoip_country_mapping'
154-
=> 'system/full_page_cache/fastly/fastly_advanced_configuration/geoip_country_mapping'
156+
=> 'system/full_page_cache/fastly/fastly_advanced_configuration/geoip_country_mapping'
155157
];
156158

157159
$setup->startSetup();
@@ -173,6 +175,10 @@ public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface
173175
} elseif (version_compare($magVer, '2.2', '<')) {
174176
$setup->endSetup();
175177
}
178+
179+
if (version_compare($version, '1.0.15', '<=')) {
180+
$this->changeConstValueInDb($setup);
181+
}
176182
}
177183

178184
/**
@@ -241,4 +247,31 @@ private function upgrade1010($newConfigPaths)
241247
$this->configWriter->save($newConfigPaths['geoip_country_mapping'], $newData);
242248
$this->cacheManager->clean([\Magento\Framework\App\Cache\Type\Config::TYPE_IDENTIFIER]);
243249
}
250+
251+
/**
252+
* Chanhe old const value from 'fastly' to '42'
253+
*
254+
* @param ModuleDataSetupInterface $setup
255+
*/
256+
private function changeConstValueInDb(ModuleDataSetupInterface $setup): void
257+
{
258+
$select = $setup->getConnection()->select()->from(
259+
$setup->getTable('core_config_data'),
260+
['value']
261+
)->where(
262+
'path = ?',
263+
\Magento\PageCache\Model\Config::XML_PAGECACHE_TYPE
264+
);
265+
$value = $setup->getConnection()->fetchOne($select);
266+
if ($value == 'fastly') {
267+
$row = [
268+
'value' => \Fastly\Cdn\Model\Config::FASTLY
269+
];
270+
$setup->getConnection()->update(
271+
$setup->getTable('core_config_data'),
272+
$row,
273+
['path = ?' => \Magento\PageCache\Model\Config::XML_PAGECACHE_TYPE]
274+
);
275+
}
276+
}
244277
}

Diff for: composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "fastly/magento2",
33
"description": "Fastly CDN Module for Magento 2.x",
44
"require": {
5-
"php": "~5.5.0|~5.6.0|~7.0.0|~7.1.0|~7.2.0|~7.3.0|~7.4.0",
5+
"php": "~7.0.0|~7.1.0|~7.2.0|~7.3.0|~7.4.0",
66
"magento/module-config": ">=100.0.0",
77
"magento/module-store": ">=100.0.0",
88
"magento/module-page-cache": ">=100.0.0",

Diff for: etc/adminhtml/system.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -935,7 +935,7 @@
935935
</field>
936936
</group>
937937
<depends>
938-
<field id="caching_application">fastly</field>
938+
<field id="caching_application">42</field>
939939
</depends>
940940
</group>
941941
<!-- =============================
@@ -945,7 +945,7 @@
945945
<label>Fastly Edge Modules</label>
946946
<comment><![CDATA[Fastly Edge module allow you to enable specific functionality like CORS headers, etc. For more details <a href="https://github.com/fastly/fastly-magento2/blob/master/Documentation/Guides/Edge-Modules/EDGE-MODULES.md" target="_blank">click here.</a>]]></comment>
947947
<depends>
948-
<field id="caching_application">fastly</field>
948+
<field id="caching_application">42</field>
949949
<field id="system/full_page_cache/fastly/fastly_advanced_configuration/enable_fastly_edge_modules">1</field>
950950
</depends>
951951
<!-- =========================

Diff for: etc/module.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
*/
2222
-->
2323
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
24-
<module name="Fastly_Cdn" setup_version="1.0.14">
24+
<module name="Fastly_Cdn" setup_version="1.0.15">
2525
<sequence>
2626
<module name="Magento_Store"/>
2727
<module name="Magento_PageCache" />

0 commit comments

Comments
 (0)