Skip to content

Commit 2aa22d6

Browse files
author
Roman Ganin
committed
Merge pull request #73 from magento-troll/develop
[Troll] S29 - Varnish 4 support, CSS minification and performance toolkit updates
2 parents 8876c93 + ea36628 commit 2aa22d6

File tree

75 files changed

+9603
-3180
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+9603
-3180
lines changed

app/code/Magento/Backend/etc/adminhtml/system.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,10 @@
211211
<label>Merge CSS Files</label>
212212
<source_model>Magento\Backend\Model\Config\Source\Yesno</source_model>
213213
</field>
214+
<field id="minify_files" translate="label" type="select" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="1">
215+
<label>Minify CSS Files</label>
216+
<source_model>Magento\Backend\Model\Config\Source\Yesno</source_model>
217+
</field>
214218
</group>
215219
<group id="image" translate="label" type="text" sortOrder="120" showInDefault="1" showInWebsite="0" showInStore="0">
216220
<label>Image Processing Settings</label>

app/code/Magento/Catalog/Helper/Product.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,13 @@ class Product extends \Magento\Core\Helper\Url
8181
*/
8282
protected $_catalogSession;
8383

84+
/**
85+
* Invalidate product category indexer params
86+
*
87+
* @var array
88+
*/
89+
protected $_reindexProductCategoryIndexerData;
90+
8491
/**
8592
* Invalidate price indexer params
8693
*
@@ -109,6 +116,7 @@ class Product extends \Magento\Core\Helper\Url
109116
* @param \Magento\Framework\App\Config\ScopeConfigInterface $coreConfig
110117
* @param string $typeSwitcherLabel
111118
* @param array $reindexPriceIndexerData
119+
* @param array $reindexProductCategoryIndexerData
112120
* @param ProductRepositoryInterface $productRepository
113121
* @param CategoryRepositoryInterface $categoryRepository
114122
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
@@ -124,6 +132,7 @@ public function __construct(
124132
\Magento\Framework\App\Config\ScopeConfigInterface $coreConfig,
125133
$typeSwitcherLabel,
126134
$reindexPriceIndexerData,
135+
$reindexProductCategoryIndexerData,
127136
ProductRepositoryInterface $productRepository,
128137
CategoryRepositoryInterface $categoryRepository
129138
) {
@@ -137,6 +146,7 @@ public function __construct(
137146
$this->_reindexPriceIndexerData = $reindexPriceIndexerData;
138147
$this->productRepository = $productRepository;
139148
$this->categoryRepository = $categoryRepository;
149+
$this->_reindexProductCategoryIndexerData = $reindexProductCategoryIndexerData;
140150
parent::__construct($context, $storeManager);
141151
}
142152

@@ -169,6 +179,22 @@ public function isDataForPriceIndexerWasChanged($data)
169179
return false;
170180
}
171181

182+
/**
183+
* Retrieve data for product category indexer update
184+
*
185+
* @param \Magento\Catalog\Model\Product $data
186+
* @return boolean
187+
*/
188+
public function isDataForProductCategoryIndexerWasChanged(\Magento\Catalog\Model\Product $data)
189+
{
190+
foreach ($this->_reindexProductCategoryIndexerData['byDataChange'] as $param) {
191+
if ($data->dataHasChangedFor($param)) {
192+
return true;
193+
}
194+
}
195+
return false;
196+
}
197+
172198
/**
173199
* Retrieve product view page url
174200
*

app/code/Magento/Catalog/Model/Category.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1024,8 +1024,9 @@ public function reindex()
10241024
$flatIndexer->reindexRow($this->getId());
10251025
}
10261026
}
1027+
$affectedProductIds = $this->getAffectedProductIds();
10271028
$productIndexer = $this->indexerRegistry->get(Indexer\Category\Product::INDEXER_ID);
1028-
if (!$productIndexer->isScheduled()) {
1029+
if (!$productIndexer->isScheduled() && !empty($affectedProductIds)) {
10291030
$productIndexer->reindexList($this->getPathIds());
10301031
}
10311032
}

app/code/Magento/Catalog/Model/Product.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -835,10 +835,12 @@ public function eavReindexCallback()
835835
*/
836836
public function reindex()
837837
{
838-
$this->_productFlatIndexerProcessor->reindexRow($this->getEntityId());
839-
$categoryIndexer = $this->indexerRegistry->get(Indexer\Product\Category::INDEXER_ID);
840-
if (!$categoryIndexer->isScheduled()) {
841-
$categoryIndexer->reindexRow($this->getId());
838+
if ($this->_catalogProduct->isDataForProductCategoryIndexerWasChanged($this) || $this->isDeleted()) {
839+
$this->_productFlatIndexerProcessor->reindexRow($this->getEntityId());
840+
$categoryIndexer = $this->indexerRegistry->get(Indexer\Product\Category::INDEXER_ID);
841+
if (!$categoryIndexer->isScheduled()) {
842+
$categoryIndexer->reindexRow($this->getId());
843+
}
842844
}
843845
}
844846

app/code/Magento/Catalog/etc/adminhtml/di.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,10 @@
6060
</argument>
6161
</arguments>
6262
</type>
63-
<type name="Magento\Catalog\Model\Indexer\Category\Product\AbstractAction">
64-
<plugin name="invalidate_pagecache_after_rows_reindex" type="Magento\Catalog\Plugin\Model\Indexer\Category\Product\Execute" />
63+
<type name="Magento\Catalog\Model\Indexer\Category\Product\Action\Full">
64+
<plugin name="invalidate_pagecache_after_full_reindex" type="Magento\Catalog\Plugin\Model\Indexer\Category\Product\Execute" />
6565
</type>
6666
<type name="Magento\Catalog\Model\Resource\Attribute">
67-
<plugin name="invalidate_cache_after_rows_reindex" type="Magento\Catalog\Plugin\Model\Resource\Attribute\Save" />
67+
<plugin name="invalidate_pagecache_after_attribute_save" type="Magento\Catalog\Plugin\Model\Resource\Attribute\Save" />
6868
</type>
6969
</config>

app/code/Magento/Catalog/etc/di.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,14 @@
8383
<item name="tax_class_id" xsi:type="string">tax_class_id</item>
8484
</item>
8585
</argument>
86+
<argument name="reindexProductCategoryIndexerData" xsi:type="array">
87+
<item name="byDataChange" xsi:type="array">
88+
<item name="category_ids" xsi:type="string">category_ids</item>
89+
<item name="entity_id" xsi:type="string">entity_id</item>
90+
<item name="store_id" xsi:type="string">store_id</item>
91+
<item name="visibility" xsi:type="string">visibility</item>
92+
</item>
93+
</argument>
8694
<argument name="productRepository" xsi:type="object">Magento\Catalog\Api\ProductRepositoryInterface\Proxy</argument>
8795
</arguments>
8896
</type>

app/code/Magento/Core/etc/config.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@
2525
<minify_files>0</minify_files>
2626
<minify_adapter>Magento\Framework\Code\Minifier\Adapter\Js\Jsmin</minify_adapter>
2727
</js>
28+
<css>
29+
<minify_files>0</minify_files>
30+
<minify_adapter>Magento\Framework\Code\Minifier\Adapter\Css\CssMinifier</minify_adapter>
31+
</css>
2832
<image>
2933
<default_adapter>GD2</default_adapter>
3034
<adapters>
@@ -98,6 +102,7 @@
98102
</startup>
99103
<url>
100104
<use_custom>0</use_custom>
105+
<use_custom_path>0</use_custom_path>
101106
<custom />
102107
</url>
103108
<security>

app/code/Magento/PageCache/Block/System/Config/Form/Field/Export.php

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,39 @@ class Export extends \Magento\Backend\Block\System\Config\Form\Field
1515
*
1616
* @param \Magento\Framework\Data\Form\Element\AbstractElement $element
1717
* @return string
18+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
1819
*/
1920
protected function _getElementHtml(\Magento\Framework\Data\Form\Element\AbstractElement $element)
2021
{
2122
/** @var \Magento\Backend\Block\Widget\Button $buttonBlock */
2223
$buttonBlock = $this->getForm()->getLayout()->createBlock('Magento\Backend\Block\Widget\Button');
2324

24-
$params = ['website' => $buttonBlock->getRequest()->getParam('website')];
25+
$params = [
26+
'website' => $buttonBlock->getRequest()->getParam('website'),
27+
'varnish' => $this->getVarnishVersion()
28+
];
2529

2630
$url = $this->getUrl("*/PageCache/exportVarnishConfig", $params);
2731
$data = [
28-
'id' => 'system_full_page_cache_varnish_export_button',
29-
'label' => __('Export VCL'),
32+
'id' => 'system_full_page_cache_varnish_export_button_version' . $this->getVarnishVersion(),
33+
'label' => __('Export VCL for Varnish ') . $this->getVarnishVersion(),
3034
'onclick' => "setLocation('" . $url . "')",
3135
];
3236

3337
$html = $buttonBlock->setData($data)->toHtml();
3438
return $html;
3539
}
3640

41+
/**
42+
* Return Varnish version to this class
43+
*
44+
* @return int
45+
*/
46+
public function getVarnishVersion()
47+
{
48+
return 0;
49+
}
50+
3751
/**
3852
* Return PageCache TTL value from config
3953
* to avoid saving empty field
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\PageCache\Block\System\Config\Form\Field\Export;
7+
8+
/**
9+
* Class Export
10+
*/
11+
class Varnish3 extends \Magento\PageCache\Block\System\Config\Form\Field\Export
12+
{
13+
/**
14+
* Return Varnish version to this class
15+
*
16+
* @return int
17+
*/
18+
public function getVarnishVersion()
19+
{
20+
return 3;
21+
}
22+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\PageCache\Block\System\Config\Form\Field\Export;
7+
8+
/**
9+
* Class Export
10+
*/
11+
class Varnish4 extends \Magento\PageCache\Block\System\Config\Form\Field\Export
12+
{
13+
/**
14+
* Return Varnish version to this class
15+
*
16+
* @return int
17+
*/
18+
public function getVarnishVersion()
19+
{
20+
return 4;
21+
}
22+
}

app/code/Magento/PageCache/Controller/Adminhtml/PageCache/ExportVarnishConfig.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,15 @@ public function __construct(
4343
public function execute()
4444
{
4545
$fileName = 'varnish.vcl';
46-
$content = $this->config->getVclFile();
46+
$varnishVersion = $this->getRequest()->getParam('varnish');
47+
switch ($varnishVersion) {
48+
case 3:
49+
$content = $this->config->getVclFile(\Magento\PageCache\Model\Config::VARNISH_3_CONFIGURATION_PATH);
50+
break;
51+
default:
52+
$content = $this->config->getVclFile(\Magento\PageCache\Model\Config::VARNISH_4_CONFIGURATION_PATH);
53+
break;
54+
}
4755
return $this->fileFactory->create($fileName, $content, DirectoryList::VAR_DIR);
4856
}
4957
}

app/code/Magento/PageCache/Model/Config.php

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,14 @@ class Config
4949
protected $_scopeConfig;
5050

5151
/**
52-
* XML path to value for saving temporary .vcl configuration
52+
* XML path to Varnish 3 config template path
5353
*/
54-
const VARNISH_CONFIGURATION_PATH = 'system/full_page_cache/varnish/path';
54+
const VARNISH_3_CONFIGURATION_PATH = 'system/full_page_cache/varnish3/path';
55+
56+
/**
57+
* XML path to Varnish 4 config template path
58+
*/
59+
const VARNISH_4_CONFIGURATION_PATH = 'system/full_page_cache/varnish4/path';
5560

5661
/**
5762
* @var \Magento\Framework\App\Cache\StateInterface $_cacheState
@@ -101,11 +106,12 @@ public function getTtl()
101106
/**
102107
* Return generated varnish.vcl configuration file
103108
*
109+
* @param string $vclTemplatePath
104110
* @return string
105111
*/
106-
public function getVclFile()
112+
public function getVclFile($vclTemplatePath)
107113
{
108-
$data = $this->_modulesDirectory->readFile($this->_scopeConfig->getValue(self::VARNISH_CONFIGURATION_PATH));
114+
$data = $this->_modulesDirectory->readFile($this->_scopeConfig->getValue($vclTemplatePath));
109115
return strtr($data, $this->_getReplacements());
110116
}
111117

@@ -117,16 +123,16 @@ public function getVclFile()
117123
protected function _getReplacements()
118124
{
119125
return [
120-
'{{ host }}' => $this->_scopeConfig->getValue(
126+
'/* {{ host }} */' => $this->_scopeConfig->getValue(
121127
self::XML_VARNISH_PAGECACHE_BACKEND_HOST,
122128
\Magento\Framework\Store\ScopeInterface::SCOPE_STORE
123129
),
124-
'{{ port }}' => $this->_scopeConfig->getValue(
130+
'/* {{ port }} */' => $this->_scopeConfig->getValue(
125131
self::XML_VARNISH_PAGECACHE_BACKEND_PORT,
126132
\Magento\Framework\Store\ScopeInterface::SCOPE_STORE
127133
),
128-
'{{ ips }}' => $this->_getAccessList(),
129-
'{{ design_exceptions_code }}' => $this->_getDesignExceptions()
134+
'/* {{ ips }} */' => $this->_getAccessList(),
135+
'/* {{ design_exceptions_code }} */' => $this->_getDesignExceptions()
130136
];
131137
}
132138

@@ -149,9 +155,9 @@ protected function _getAccessList()
149155
\Magento\Framework\Store\ScopeInterface::SCOPE_STORE
150156
);
151157
if (!empty($accessList)) {
152-
$ips = explode(', ', $accessList);
158+
$ips = explode(',', $accessList);
153159
foreach ($ips as $ip) {
154-
$result[] = sprintf($tpl, $ip);
160+
$result[] = sprintf($tpl, trim($ip));
155161
}
156162
return implode("\n", $result);
157163
}

app/code/Magento/PageCache/etc/adminhtml/system.xml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,15 @@
4141
<field id="caching_application">1</field>
4242
</depends>
4343
</field>
44-
<field id="export_button" type="button" sortOrder="35" showInDefault="1" showInWebsite="0" showInStore="0">
45-
<label>Export Varnish Configuration</label>
46-
<frontend_model>Magento\PageCache\Block\System\Config\Form\Field\Export</frontend_model>
44+
<field id="export_button_version3" type="button" sortOrder="35" showInDefault="1" showInWebsite="0" showInStore="0">
45+
<label>Export Configuration</label>
46+
<frontend_model>Magento\PageCache\Block\System\Config\Form\Field\Export\Varnish3</frontend_model>
47+
<depends>
48+
<field id="caching_application">1</field>
49+
</depends>
50+
</field>
51+
<field id="export_button_version4" type="button" sortOrder="36" showInDefault="1" showInWebsite="0" showInStore="0">
52+
<frontend_model>Magento\PageCache\Block\System\Config\Form\Field\Export\Varnish4</frontend_model>
4753
<depends>
4854
<field id="caching_application">1</field>
4955
</depends>

app/code/Magento/PageCache/etc/config.xml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,12 @@
99
<default>
1010
<system>
1111
<full_page_cache>
12-
<varnish>
13-
<path>Magento/PageCache/etc/varnish.vcl</path>
14-
</varnish>
12+
<varnish3>
13+
<path>Magento/PageCache/etc/varnish3.vcl</path>
14+
</varnish3>
15+
<varnish4>
16+
<path>Magento/PageCache/etc/varnish4.vcl</path>
17+
</varnish4>
1518
<ttl>120</ttl>
1619
<caching_application>1</caching_application>
1720
<default>

app/code/Magento/PageCache/etc/varnish.vcl renamed to app/code/Magento/PageCache/etc/varnish3.vcl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ import std;
22
# The minimal Varnish version is 3.0.5
33

44
backend default {
5-
.host = "{{ host }}";
6-
.port = "{{ port }}";
5+
.host = "/* {{ host }} */";
6+
.port = "/* {{ port }} */";
77
}
88

99
acl purge {
10-
{{ ips }}
10+
/* {{ ips }} */
1111
}
1212

1313
sub vcl_recv {
@@ -68,7 +68,7 @@ sub vcl_hash {
6868
if (req.http.cookie ~ "X-Magento-Vary=") {
6969
hash_data(regsub(req.http.cookie, "^.*?X-Magento-Vary=([^;]+);*.*$", "\1"));
7070
}
71-
{{ design_exceptions_code }}
71+
/* {{ design_exceptions_code }} */
7272
}
7373

7474
sub vcl_fetch {

0 commit comments

Comments
 (0)