Skip to content

Commit

Permalink
Merge pull request #4491 from magento-techdivision/varnish6_update
Browse files Browse the repository at this point in the history
[TechDivision] Varnish 6 update
  • Loading branch information
danielrenaud authored Jul 23, 2019
2 parents 9b7e0cb + 0b71e69 commit 777b0b0
Show file tree
Hide file tree
Showing 7 changed files with 326 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\PageCache\Block\System\Config\Form\Field\Export;

/**
* Class Export
*/
class Varnish6 extends \Magento\PageCache\Block\System\Config\Form\Field\Export
{
/**
* Return Varnish version to this class
*
* @return int
*/
public function getVarnishVersion()
{
return 6;
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
<?php
/**
*
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\PageCache\Controller\Adminhtml\PageCache;

use Magento\Framework\App\Action\HttpGetActionInterface;
use Magento\Framework\App\Filesystem\DirectoryList;

class ExportVarnishConfig extends \Magento\Backend\App\Action
/**
* Class ExportVarnishConfig action which exports vcl config file
*/
class ExportVarnishConfig extends \Magento\Backend\App\Action implements HttpGetActionInterface
{
/**
* Authorization level of a basic admin session
Expand Down Expand Up @@ -50,6 +53,9 @@ public function execute()
$fileName = 'varnish.vcl';
$varnishVersion = $this->getRequest()->getParam('varnish');
switch ($varnishVersion) {
case 6:
$content = $this->config->getVclFile(\Magento\PageCache\Model\Config::VARNISH_6_CONFIGURATION_PATH);
break;
case 5:
$content = $this->config->getVclFile(\Magento\PageCache\Model\Config::VARNISH_5_CONFIGURATION_PATH);
break;
Expand Down
45 changes: 30 additions & 15 deletions app/code/Magento/PageCache/Model/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\PageCache\Model;

use Magento\Framework\App\ObjectManager;
Expand All @@ -12,8 +13,7 @@
use Magento\PageCache\Model\Varnish\VclGeneratorFactory;

/**
* Model is responsible for replacing default vcl template
* file configuration with user-defined from configuration
* Model is responsible for replacing default vcl template file configuration with user-defined from configuration
*
* @api
* @since 100.0.2
Expand Down Expand Up @@ -49,6 +49,11 @@ class Config
*/
protected $_scopeConfig;

/**
* XML path to Varnish 6 config template path
*/
const VARNISH_6_CONFIGURATION_PATH = 'system/full_page_cache/varnish6/path';

/**
* XML path to Varnish 5 config template path
*/
Expand Down Expand Up @@ -145,19 +150,29 @@ public function getVclFile($vclTemplatePath)
self::XML_VARNISH_PAGECACHE_DESIGN_THEME_REGEX,
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
);

$version = $vclTemplatePath === self::VARNISH_5_CONFIGURATION_PATH ? 5 : 4;
switch ($vclTemplatePath) {
case self::VARNISH_6_CONFIGURATION_PATH:
$version = 6;
break;
case self::VARNISH_5_CONFIGURATION_PATH:
$version = 5;
break;
default:
$version = 4;
}
$sslOffloadedHeader = $this->_scopeConfig->getValue(
\Magento\Framework\HTTP\PhpEnvironment\Request::XML_PATH_OFFLOADER_HEADER
);
$vclGenerator = $this->vclGeneratorFactory->create([
'backendHost' => $this->_scopeConfig->getValue(self::XML_VARNISH_PAGECACHE_BACKEND_HOST),
'backendPort' => $this->_scopeConfig->getValue(self::XML_VARNISH_PAGECACHE_BACKEND_PORT),
'accessList' => $accessList ? explode(',', $accessList) : [],
'designExceptions' => $designExceptions ? $this->serializer->unserialize($designExceptions) : [],
'sslOffloadedHeader' => $sslOffloadedHeader,
'gracePeriod' => $this->_scopeConfig->getValue(self::XML_VARNISH_PAGECACHE_GRACE_PERIOD)
]);
$vclGenerator = $this->vclGeneratorFactory->create(
[
'backendHost' => $this->_scopeConfig->getValue(self::XML_VARNISH_PAGECACHE_BACKEND_HOST),
'backendPort' => $this->_scopeConfig->getValue(self::XML_VARNISH_PAGECACHE_BACKEND_PORT),
'accessList' => $accessList ? explode(',', $accessList) : [],
'designExceptions' => $designExceptions ? $this->serializer->unserialize($designExceptions) : [],
'sslOffloadedHeader' => $sslOffloadedHeader,
'gracePeriod' => $this->_scopeConfig->getValue(self::XML_VARNISH_PAGECACHE_GRACE_PERIOD)
]
);
return $vclGenerator->generateVcl($version);
}

Expand Down Expand Up @@ -187,12 +202,12 @@ protected function _getReplacements()
}

/**
* Get IPs access list that can purge Varnish configuration for config file generation
* and transform it to appropriate view
* Get IPs access list allowed purge Varnish config for config file generation and transform it to appropriate view
*
* acl purge{
* Example acl_purge{
* "127.0.0.1";
* "127.0.0.2";
* }
*
* @return mixed|null|string
* @deprecated 100.2.0 see \Magento\PageCache\Model\VclGeneratorInterface::generateVcl
Expand Down
20 changes: 17 additions & 3 deletions app/code/Magento/PageCache/Model/Varnish/VclTemplateLocator.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,16 @@
use Magento\PageCache\Model\VclTemplateLocatorInterface;
use Magento\PageCache\Exception\UnsupportedVarnishVersion;

/**
* Class VclTemplateLocator provides vcl template path
*/
class VclTemplateLocator implements VclTemplateLocatorInterface
{
/**
* XML path to Varnish 5 config template path
*/
const VARNISH_6_CONFIGURATION_PATH = 'system/full_page_cache/varnish6/path';

/**
* XML path to Varnish 5 config template path
*/
Expand All @@ -26,21 +34,27 @@ class VclTemplateLocator implements VclTemplateLocatorInterface
const VARNISH_4_CONFIGURATION_PATH = 'system/full_page_cache/varnish4/path';

/**
*
* Varnish 4 supported version
*/
const VARNISH_SUPPORTED_VERSION_4 = '4';

/**
*
* Varnish 5 supported version
*/
const VARNISH_SUPPORTED_VERSION_5 = '5';

/**
* Varnish 6 supported version
*/
const VARNISH_SUPPORTED_VERSION_6 = '6';

/**
* @var array
*/
private $supportedVarnishVersions = [
self::VARNISH_SUPPORTED_VERSION_4 => self::VARNISH_4_CONFIGURATION_PATH,
self::VARNISH_SUPPORTED_VERSION_5 => self::VARNISH_5_CONFIGURATION_PATH,
self::VARNISH_SUPPORTED_VERSION_6 => self::VARNISH_6_CONFIGURATION_PATH,
];

/**
Expand Down Expand Up @@ -73,7 +87,7 @@ public function __construct(Reader $reader, ReadFactory $readFactory, ScopeConfi
}

/**
* {@inheritdoc}
* @inheritdoc
*/
public function getTemplate($version)
{
Expand Down
6 changes: 6 additions & 0 deletions app/code/Magento/PageCache/etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@
<field id="caching_application">1</field>
</depends>
</field>
<field id="export_button_version6" type="button" sortOrder="40" showInDefault="1" showInWebsite="0" showInStore="0">
<frontend_model>Magento\PageCache\Block\System\Config\Form\Field\Export\Varnish6</frontend_model>
<depends>
<field id="caching_application">1</field>
</depends>
</field>
<depends>
<field id="caching_application">2</field>
</depends>
Expand Down
3 changes: 3 additions & 0 deletions app/code/Magento/PageCache/etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
</design>
<system>
<full_page_cache>
<varnish6>
<path>varnish6.vcl</path>
</varnish6>
<varnish5>
<path>varnish5.vcl</path>
</varnish5>
Expand Down
Loading

0 comments on commit 777b0b0

Please sign in to comment.