Skip to content

Fix/issue 466 #469

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Aug 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Model/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class Config extends \Magento\PageCache\Model\Config
/**
* Cache types
*/
const FASTLY = 'fastly';
const FASTLY = 42;

/**
* Magento module prefix used for naming vcl snippets, condition and request
Expand Down
30 changes: 30 additions & 0 deletions Model/PageCache/ConfigPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
* @copyright Copyright (c) 2016 Fastly, Inc. (http://www.fastly.com)
* @license BSD, see LICENSE_FASTLY_CDN.txt
*/

namespace Fastly\Cdn\Model\PageCache;

use \Magento\PageCache\Model\Config;
Expand All @@ -36,6 +37,18 @@
*/
class ConfigPlugin
{
protected $_scopeConfig;

/**
* ConfigPlugin constructor.
*
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
*/
public function __construct(\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig)
{
$this->_scopeConfig = $scopeConfig;
}

/**
* Return cache type "Varnish" if Fastly is configured.
*
Expand All @@ -53,4 +66,21 @@ public function afterGetType(Config $config, $result)
}
return $result;
}

/**
* Change return value from string to int, 'fastly' is old value
*
* @param Config $config
* @param callable $proceed
* @return string|int
*/
public function aroundGetType(Config $config, callable $proceed)
{
if ($this->_scopeConfig->getValue(Config::XML_PAGECACHE_TYPE) === 'fastly') {
$result = \Fastly\Cdn\Model\Config::FASTLY;
} else {
$result = $proceed();
}
return $result;
}
}
73 changes: 53 additions & 20 deletions Setup/UpgradeData.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
* @copyright Copyright (c) 2016 Fastly, Inc. (http://www.fastly.com)
* @license BSD, see LICENSE_FASTLY_CDN.txt
*/

namespace Fastly\Cdn\Setup;

use Fastly\Cdn\Helper\Data;
Expand Down Expand Up @@ -94,7 +95,8 @@ public function __construct(
Data $helper,
ProductMetadataInterface $productMetadata,
SerializerInterface $serializeInterface
) {
)
{
$this->date = $date;
$this->scopeConfig = $scopeConfig;
$this->configWriter = $configWriter;
Expand All @@ -111,7 +113,7 @@ public function __construct(
*
*
* @param ModuleDataSetupInterface $setup
* @param ModuleContextInterface $context*
* @param ModuleContextInterface $context *
*/
public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
{
Expand All @@ -122,36 +124,36 @@ public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface
}

$oldConfigPaths = [
'stale_ttl' => 'system/full_page_cache/fastly/stale_ttl',
'stale_error_ttl' => 'system/full_page_cache/fastly/stale_error_ttl',
'purge_catalog_category' => 'system/full_page_cache/fastly/purge_catalog_category',
'purge_catalog_product' => 'system/full_page_cache/fastly/purge_catalog_product',
'purge_cms_page' => 'system/full_page_cache/fastly/purge_cms_page',
'soft_purge' => 'system/full_page_cache/fastly/soft_purge',
'enable_geoip' => 'system/full_page_cache/fastly/enable_geoip',
'geoip_action' => 'system/full_page_cache/fastly/geoip_action',
'geoip_country_mapping' => 'system/full_page_cache/fastly/geoip_country_mapping',
'stale_ttl' => 'system/full_page_cache/fastly/stale_ttl',
'stale_error_ttl' => 'system/full_page_cache/fastly/stale_error_ttl',
'purge_catalog_category' => 'system/full_page_cache/fastly/purge_catalog_category',
'purge_catalog_product' => 'system/full_page_cache/fastly/purge_catalog_product',
'purge_cms_page' => 'system/full_page_cache/fastly/purge_cms_page',
'soft_purge' => 'system/full_page_cache/fastly/soft_purge',
'enable_geoip' => 'system/full_page_cache/fastly/enable_geoip',
'geoip_action' => 'system/full_page_cache/fastly/geoip_action',
'geoip_country_mapping' => 'system/full_page_cache/fastly/geoip_country_mapping',
];

$newConfigPaths = [
'stale_ttl'
=> 'system/full_page_cache/fastly/fastly_advanced_configuration/stale_ttl',
=> 'system/full_page_cache/fastly/fastly_advanced_configuration/stale_ttl',
'stale_error_ttl'
=> 'system/full_page_cache/fastly/fastly_advanced_configuration/stale_error_ttl',
=> 'system/full_page_cache/fastly/fastly_advanced_configuration/stale_error_ttl',
'purge_catalog_category'
=> 'system/full_page_cache/fastly/fastly_advanced_configuration/purge_catalog_category',
=> 'system/full_page_cache/fastly/fastly_advanced_configuration/purge_catalog_category',
'purge_catalog_product'
=> 'system/full_page_cache/fastly/fastly_advanced_configuration/purge_catalog_product',
=> 'system/full_page_cache/fastly/fastly_advanced_configuration/purge_catalog_product',
'purge_cms_page'
=> 'system/full_page_cache/fastly/fastly_advanced_configuration/purge_cms_page',
=> 'system/full_page_cache/fastly/fastly_advanced_configuration/purge_cms_page',
'soft_purge'
=> 'system/full_page_cache/fastly/fastly_advanced_configuration/soft_purge',
=> 'system/full_page_cache/fastly/fastly_advanced_configuration/soft_purge',
'enable_geoip'
=> 'system/full_page_cache/fastly/fastly_advanced_configuration/enable_geoip',
=> 'system/full_page_cache/fastly/fastly_advanced_configuration/enable_geoip',
'geoip_action'
=> 'system/full_page_cache/fastly/fastly_advanced_configuration/geoip_action',
=> 'system/full_page_cache/fastly/fastly_advanced_configuration/geoip_action',
'geoip_country_mapping'
=> 'system/full_page_cache/fastly/fastly_advanced_configuration/geoip_country_mapping'
=> 'system/full_page_cache/fastly/fastly_advanced_configuration/geoip_country_mapping'
];

$setup->startSetup();
Expand All @@ -173,6 +175,10 @@ public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface
} elseif (version_compare($magVer, '2.2', '<')) {
$setup->endSetup();
}

if (version_compare($version, '1.0.15', '<=')) {
$this->changeConstValueInDb($setup);
}
}

/**
Expand Down Expand Up @@ -241,4 +247,31 @@ private function upgrade1010($newConfigPaths)
$this->configWriter->save($newConfigPaths['geoip_country_mapping'], $newData);
$this->cacheManager->clean([\Magento\Framework\App\Cache\Type\Config::TYPE_IDENTIFIER]);
}

/**
* Chanhe old const value from 'fastly' to '42'
*
* @param ModuleDataSetupInterface $setup
*/
private function changeConstValueInDb(ModuleDataSetupInterface $setup): void
{
$select = $setup->getConnection()->select()->from(
$setup->getTable('core_config_data'),
['value']
)->where(
'path = ?',
\Magento\PageCache\Model\Config::XML_PAGECACHE_TYPE
);
$value = $setup->getConnection()->fetchOne($select);
if ($value == 'fastly') {
$row = [
'value' => \Fastly\Cdn\Model\Config::FASTLY
];
$setup->getConnection()->update(
$setup->getTable('core_config_data'),
$row,
['path = ?' => \Magento\PageCache\Model\Config::XML_PAGECACHE_TYPE]
);
}
}
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "fastly/magento2",
"description": "Fastly CDN Module for Magento 2.x",
"require": {
"php": "~5.5.0|~5.6.0|~7.0.0|~7.1.0|~7.2.0|~7.3.0|~7.4.0",
"php": "~7.0.0|~7.1.0|~7.2.0|~7.3.0|~7.4.0",
"magento/module-config": ">=100.0.0",
"magento/module-store": ">=100.0.0",
"magento/module-page-cache": ">=100.0.0",
Expand Down
4 changes: 2 additions & 2 deletions etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -935,7 +935,7 @@
</field>
</group>
<depends>
<field id="caching_application">fastly</field>
<field id="caching_application">42</field>
</depends>
</group>
<!-- =============================
Expand All @@ -945,7 +945,7 @@
<label>Fastly Edge Modules</label>
<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>
<depends>
<field id="caching_application">fastly</field>
<field id="caching_application">42</field>
<field id="system/full_page_cache/fastly/fastly_advanced_configuration/enable_fastly_edge_modules">1</field>
</depends>
<!-- =========================
Expand Down
2 changes: 1 addition & 1 deletion etc/module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Fastly_Cdn" setup_version="1.0.14">
<module name="Fastly_Cdn" setup_version="1.0.15">
<sequence>
<module name="Magento_Store"/>
<module name="Magento_PageCache" />
Expand Down