Skip to content

Commit 668b6ca

Browse files
author
Elena Marchenko
committed
Merge branch 'develop' of github.corp.ebay.com:magento2/magento2ce into MTA-559
Conflicts: dev/tests/functional/tests/app/Magento/Checkout/Test/TestStep/PlaceOrderStep.php
2 parents be747b7 + d017af6 commit 668b6ca

File tree

318 files changed

+12816
-3258
lines changed

Some content is hidden

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

318 files changed

+12816
-3258
lines changed
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\CacheInvalidate\Model;
7+
8+
/**
9+
* Class Observer
10+
*/
11+
class Observer
12+
{
13+
/**
14+
* Application config object
15+
*
16+
* @var \Magento\Framework\App\Config\ScopeConfigInterface
17+
*/
18+
protected $_config;
19+
20+
/**
21+
* @var \Magento\PageCache\Helper\Data
22+
*/
23+
protected $_helper;
24+
25+
/**
26+
* @var \Magento\Framework\HTTP\Adapter\Curl
27+
*/
28+
protected $_curlAdapter;
29+
30+
/**
31+
* Constructor
32+
*
33+
* @param \Magento\PageCache\Model\Config $config
34+
* @param \Magento\PageCache\Helper\Data $helper
35+
* @param \Magento\Framework\HTTP\Adapter\Curl $curlAdapter
36+
*/
37+
public function __construct(
38+
\Magento\PageCache\Model\Config $config,
39+
\Magento\PageCache\Helper\Data $helper,
40+
\Magento\Framework\HTTP\Adapter\Curl $curlAdapter
41+
) {
42+
$this->_config = $config;
43+
$this->_helper = $helper;
44+
$this->_curlAdapter = $curlAdapter;
45+
}
46+
47+
/**
48+
* If Varnish caching is enabled it collects array of tags
49+
* of incoming object and asks to clean cache.
50+
*
51+
* @param \Magento\Framework\Event\Observer $observer
52+
* @return void
53+
*/
54+
public function invalidateVarnish(\Magento\Framework\Event\Observer $observer)
55+
{
56+
if ($this->_config->getType() == \Magento\PageCache\Model\Config::VARNISH && $this->_config->isEnabled()) {
57+
$object = $observer->getEvent()->getObject();
58+
if ($object instanceof \Magento\Framework\Object\IdentityInterface) {
59+
$tags = [];
60+
$pattern = "((^|,)%s(,|$))";
61+
foreach ($object->getIdentities() as $tag) {
62+
$tags[] = sprintf($pattern, preg_replace("~_\\d+$~", '', $tag));
63+
$tags[] = sprintf($pattern, $tag);
64+
}
65+
$this->sendPurgeRequest(implode('|', array_unique($tags)));
66+
}
67+
}
68+
}
69+
70+
/**
71+
* Flash Varnish cache
72+
*
73+
* @param \Magento\Framework\Event\Observer $observer
74+
* @return void
75+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
76+
*/
77+
public function flushAllCache(\Magento\Framework\Event\Observer $observer)
78+
{
79+
if ($this->_config->getType() == \Magento\PageCache\Model\Config::VARNISH && $this->_config->isEnabled()) {
80+
$this->sendPurgeRequest('.*');
81+
}
82+
}
83+
84+
/**
85+
* Send curl purge request
86+
* to invalidate cache by tags pattern
87+
*
88+
* @param string $tagsPattern
89+
* @return void
90+
*/
91+
protected function sendPurgeRequest($tagsPattern)
92+
{
93+
$headers = ["X-Magento-Tags-Pattern: {$tagsPattern}"];
94+
$this->_curlAdapter->setOptions([CURLOPT_CUSTOMREQUEST => 'PURGE']);
95+
$this->_curlAdapter->write('', $this->_helper->getUrl('*'), '1.1', $headers);
96+
$this->_curlAdapter->read();
97+
$this->_curlAdapter->close();
98+
}
99+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
The CacheInvalidate module is used to invalidate the Varnish cache if it is configured.
2+
It listens for events that request the cache to be flushed or cause the cache to be invalid, then sends Varnish a purge request using cURL.
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\CacheInvalidate\Test\Unit\Model;
7+
8+
class ObserverTest extends \PHPUnit_Framework_TestCase
9+
{
10+
/** @var \PHPUnit_Framework_MockObject_MockObject | \Magento\CacheInvalidate\Model\Observer */
11+
protected $_model;
12+
13+
/** @var \PHPUnit_Framework_MockObject_MockObject | \Magento\Framework\Event\Observer */
14+
protected $_observerMock;
15+
16+
/** @var \PHPUnit_Framework_MockObject_MockObject | \Magento\Framework\HTTP\Adapter\Curl */
17+
protected $_curlMock;
18+
19+
/** @var \PHPUnit_Framework_MockObject_MockObject | \Magento\PageCache\Model\Config */
20+
protected $_configMock;
21+
22+
/** @var \PHPUnit_Framework_MockObject_MockObject | \Magento\PageCache\Helper\Data */
23+
protected $_helperMock;
24+
25+
/** @var \PHPUnit_Framework_MockObject_MockObject | \Magento\Framework\Object\ */
26+
protected $_observerObject;
27+
28+
/**
29+
* Set up all mocks and data for test
30+
*/
31+
public function setUp()
32+
{
33+
$this->_configMock = $this->getMock(
34+
'Magento\PageCache\Model\Config',
35+
['getType', 'isEnabled'],
36+
[],
37+
'',
38+
false
39+
);
40+
$this->_helperMock = $this->getMock('Magento\PageCache\Helper\Data', ['getUrl'], [], '', false);
41+
$this->_curlMock = $this->getMock(
42+
'\Magento\Framework\HTTP\Adapter\Curl',
43+
['setOptions', 'write', 'read', 'close'],
44+
[],
45+
'',
46+
false
47+
);
48+
$this->_model = new \Magento\CacheInvalidate\Model\Observer(
49+
$this->_configMock,
50+
$this->_helperMock,
51+
$this->_curlMock
52+
);
53+
$this->_observerMock = $this->getMock(
54+
'Magento\Framework\Event\Observer',
55+
['getEvent'],
56+
[],
57+
'',
58+
false
59+
);
60+
$this->_observerObject = $this->getMock('\Magento\Store\Model\Store', [], [], '', false);
61+
}
62+
63+
/**
64+
* Test case for cache invalidation
65+
*/
66+
public function testInvalidateVarnish()
67+
{
68+
$tags = ['cache_1', 'cache_group'];
69+
$pattern = '((^|,)cache(,|$))|((^|,)cache_1(,|$))|((^|,)cache_group(,|$))';
70+
71+
$this->_configMock->expects($this->once())->method('isEnabled')->will($this->returnValue(true));
72+
$this->_configMock->expects(
73+
$this->once()
74+
)->method(
75+
'getType'
76+
)->will(
77+
$this->returnValue(\Magento\PageCache\Model\Config::VARNISH)
78+
);
79+
$eventMock = $this->getMock('Magento\Framework\Event', ['getObject'], [], '', false);
80+
$eventMock->expects($this->once())->method('getObject')->will($this->returnValue($this->_observerObject));
81+
$this->_observerMock->expects($this->once())->method('getEvent')->will($this->returnValue($eventMock));
82+
$this->_observerObject->expects($this->once())->method('getIdentities')->will($this->returnValue($tags));
83+
$this->sendPurgeRequest($pattern);
84+
85+
$this->_model->invalidateVarnish($this->_observerMock);
86+
}
87+
88+
/**
89+
* Test case for flushing all the cache
90+
*/
91+
public function testFlushAllCache()
92+
{
93+
$this->_configMock->expects($this->once())->method('isEnabled')->will($this->returnValue(true));
94+
$this->_configMock->expects(
95+
$this->once()
96+
)->method(
97+
'getType'
98+
)->will(
99+
$this->returnValue(\Magento\PageCache\Model\Config::VARNISH)
100+
);
101+
102+
$this->sendPurgeRequest('.*');
103+
$this->_model->flushAllCache($this->_observerMock);
104+
}
105+
106+
/**
107+
* @param string $tags
108+
*/
109+
protected function sendPurgeRequest($tags)
110+
{
111+
$url = 'http://mangento.index.php';
112+
$httpVersion = '1.1';
113+
$headers = ["X-Magento-Tags-Pattern: {$tags}"];
114+
$this->_helperMock->expects(
115+
$this->any()
116+
)->method(
117+
'getUrl'
118+
)->with(
119+
$this->equalTo('*'),
120+
[]
121+
)->will(
122+
$this->returnValue($url)
123+
);
124+
$this->_curlMock->expects($this->once())->method('setOptions')->with([CURLOPT_CUSTOMREQUEST => 'PURGE']);
125+
$this->_curlMock->expects(
126+
$this->once()
127+
)->method(
128+
'write'
129+
)->with(
130+
$this->equalTo(''),
131+
$this->equalTo($url),
132+
$httpVersion,
133+
$this->equalTo($headers)
134+
);
135+
$this->_curlMock->expects($this->once())->method('read');
136+
$this->_curlMock->expects($this->once())->method('close');
137+
}
138+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"name": "magento/module-cache-invalidate",
3+
"description": "N/A",
4+
"require": {
5+
"php": "~5.5.0|~5.6.0",
6+
"magento/module-page-cache": "0.74.0-beta4",
7+
"magento/framework": "0.74.0-beta4",
8+
"magento/magento-composer-installer": "*"
9+
},
10+
"type": "magento2-module",
11+
"version": "0.74.0-beta4",
12+
"license": [
13+
"OSL-3.0",
14+
"AFL-3.0"
15+
],
16+
"extra": {
17+
"map": [
18+
[
19+
"*",
20+
"Magento/CacheInvalidate"
21+
]
22+
]
23+
}
24+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* Copyright © 2015 Magento. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Event/etc/events.xsd">
9+
<event name="clean_cache_by_tags">
10+
<observer name="invalidate_varnish" instance="Magento\CacheInvalidate\Model\Observer" method="invalidateVarnish" />
11+
</event>
12+
<event name="adminhtml_cache_flush_system">
13+
<observer name="flush_varnish_pagecache" instance="Magento\CacheInvalidate\Model\Observer" method="flushAllCache" />
14+
</event>
15+
<event name="clean_media_cache_after">
16+
<observer name="flush_varnish_pagecache" instance="Magento\CacheInvalidate\Model\Observer" method="flushAllCache" />
17+
</event>
18+
<event name="clean_catalog_images_cache_after">
19+
<observer name="flush_varnish_pagecache" instance="Magento\CacheInvalidate\Model\Observer" method="flushAllCache" />
20+
</event>
21+
<event name="assigned_theme_changed">
22+
<observer name="flush_varnish_pagecache" instance="Magento\CacheInvalidate\Model\Observer" method="invalidateVarnish" />
23+
</event>
24+
<event name="catalogrule_after_apply">
25+
<observer name="flush_varnish_pagecache" instance="Magento\CacheInvalidate\Model\Observer" method="invalidateVarnish" />
26+
</event>
27+
<event name="adminhtml_cache_refresh_type">
28+
<observer name="flush_varnish_pagecache" instance="Magento\CacheInvalidate\Model\Observer" method="flushAllCache" />
29+
</event>
30+
<event name="adminhtml_cache_flush_all">
31+
<observer name="flush_varnish_pagecache" instance="Magento\CacheInvalidate\Model\Observer" method="flushAllCache" />
32+
</event>
33+
<event name="assign_theme_to_stores_after">
34+
<observer name="flush_varnish_pagecache" instance="Magento\CacheInvalidate\Model\Observer" method="flushAllCache" />
35+
</event>
36+
<event name="controller_action_postdispatch_adminhtml_system_currency_saveRates">
37+
<observer name="flush_varnish_pagecache" instance="Magento\CacheInvalidate\Model\Observer" method="invalidateVarnish" />
38+
</event>
39+
<event name="controller_action_postdispatch_adminhtml_system_config_save">
40+
<observer name="flush_varnish_pagecache" instance="Magento\CacheInvalidate\Model\Observer" method="invalidateVarnish" />
41+
</event>
42+
<event name="controller_action_postdispatch_adminhtml_catalog_product_action_attribute_save">
43+
<observer name="flush_varnish_pagecache" instance="Magento\CacheInvalidate\Model\Observer" method="invalidateVarnish" />
44+
</event>
45+
<event name="controller_action_postdispatch_adminhtml_catalog_product_massStatus">
46+
<observer name="flush_varnish_pagecache" instance="Magento\CacheInvalidate\Model\Observer" method="invalidateVarnish" />
47+
</event>
48+
<event name="controller_action_postdispatch_adminhtml_system_currencysymbol_save">
49+
<observer name="flush_varnish_pagecache" instance="Magento\CacheInvalidate\Model\Observer" method="invalidateVarnish" />
50+
</event>
51+
</config>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* Copyright © 2015 Magento. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Module/etc/module.xsd">
9+
<module name="Magento_CacheInvalidate" setup_version="2.0.0">
10+
<sequence>
11+
<module name="Magento_Store"/>
12+
</sequence>
13+
</module>
14+
</config>

app/code/Magento/Catalog/Model/Entity/Attribute.php

100644100755
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,14 +139,14 @@ public function __construct(
139139
* Processing object before save data
140140
*
141141
* @return \Magento\Framework\Model\AbstractModel
142-
* @throws \Magento\Eav\Exception
142+
* @throws \Magento\Framework\Exception\LocalizedException
143143
*/
144144
public function beforeSave()
145145
{
146146
try {
147147
$this->attrLockValidator->validate($this);
148148
} catch (\Magento\Framework\Exception\LocalizedException $exception) {
149-
throw new \Magento\Eav\Exception(__($exception->getMessage()));
149+
throw new \Magento\Framework\Exception\LocalizedException(__($exception->getMessage()));
150150
}
151151

152152
$this->setData('modulePrefix', self::MODULE_NAME);

app/code/Magento/Catalog/Model/Product/Attribute/Backend/Sku.php

100644100755
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,15 @@ public function __construct(\Magento\Framework\Stdlib\String $string)
4444
*
4545
* @param Product $object
4646
* @return bool
47-
* @throws \Magento\Eav\Exception
47+
* @throws \Magento\Framework\Exception\LocalizedException
4848
* @throws \Magento\Framework\Exception\LocalizedException
4949
*/
5050
public function validate($object)
5151
{
5252
$attrCode = $this->getAttribute()->getAttributeCode();
5353
$value = $object->getData($attrCode);
5454
if ($this->getAttribute()->getIsRequired() && strlen($value) === 0) {
55-
throw new \Magento\Eav\Exception(__('The value of attribute "%1" must be set', $attrCode));
55+
throw new \Magento\Framework\Exception\LocalizedException(__('The value of attribute "%1" must be set', $attrCode));
5656
}
5757

5858
if ($this->string->strlen($object->getSku()) > self::SKU_MAX_LENGTH) {

app/code/Magento/Catalog/Model/Product/Option/Type/File.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ protected function _getCurrentConfigFileInfo()
181181
* @param array $values All product option values, i.e. array (option_id => mixed, option_id => mixed...)
182182
* @return $this
183183
* @throws LocalizedException
184+
* @throws \Exception
184185
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
185186
*/
186187
public function validateUserValue($values)
@@ -222,9 +223,6 @@ public function validateUserValue($values)
222223
$value = $this->validatorFile->setProduct($this->getProduct())
223224
->validate($this->_getProcessingParams(), $option);
224225
$this->setUserValue($value);
225-
} catch (\Magento\Framework\Exception\File\LargeSizeException $largeSizeException) {
226-
$this->setIsValid(false);
227-
throw new LocalizedException(__($largeSizeException->getMessage()));
228226
} catch (ProductException $e) {
229227
switch ($this->getProcessMode()) {
230228
case \Magento\Catalog\Model\Product\Type\AbstractType::PROCESS_MODE_FULL:
@@ -236,7 +234,7 @@ public function validateUserValue($values)
236234
}
237235
} catch (\Magento\Framework\Validator\Exception $e) {
238236
$this->setUserValue(null);
239-
} catch (\Magento\Framework\Exception\File\ValidatorException $e) {
237+
} catch (LocalizedException $e) {
240238
$this->setIsValid(false);
241239
throw new LocalizedException(__($e->getMessage()));
242240
} catch (\Exception $e) {

0 commit comments

Comments
 (0)