Skip to content

Commit 952eb86

Browse files
Merge pull request #2753 from magento-qwerty/2.2.6-bugfixes-210618
Fixed issues: - MAGETWO-88592: [Backport for 2.2.x] Deleting Stores - MAGETWO-81470: [Backport for 2.2.x] Cached Config is Different From DB - MAGETWO-92200: Some Underscore templates are broken - MAGETWO-88655: [Backport for 2.2.x] Sales Rule Widget Label
2 parents 914ffbe + ab70ac8 commit 952eb86

File tree

9 files changed

+139
-66
lines changed

9 files changed

+139
-66
lines changed

app/code/Magento/Backend/Controller/Adminhtml/System/Store/DeleteGroupPost.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,28 @@
77
namespace Magento\Backend\Controller\Adminhtml\System\Store;
88

99
use Magento\Framework\Controller\ResultFactory;
10+
use Magento\Framework\App\Request\Http as HttpRequest;
11+
use Magento\Framework\Exception\NotFoundException;
1012

1113
class DeleteGroupPost extends \Magento\Backend\Controller\Adminhtml\System\Store
1214
{
1315
/**
1416
* @return \Magento\Backend\Model\View\Result\Redirect
17+
* @throws NotFoundException
1518
*/
1619
public function execute()
1720
{
18-
$itemId = $this->getRequest()->getParam('item_id');
19-
21+
/** @var HttpRequest $request */
22+
$request = $this->getRequest();
2023
/** @var \Magento\Backend\Model\View\Result\Redirect $redirectResult */
21-
$redirectResult = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
24+
$redirectResult = $this->resultFactory->create(
25+
ResultFactory::TYPE_REDIRECT
26+
);
27+
if (!$request->isPost()) {
28+
throw new NotFoundException(__('Page not found.'));
29+
}
2230

31+
$itemId = $request->getParam('item_id');
2332
if (!($model = $this->_objectManager->create(\Magento\Store\Model\Group::class)->load($itemId))) {
2433
$this->messageManager->addError(__('Something went wrong. Please try again.'));
2534
return $redirectResult->setPath('adminhtml/*/');

app/code/Magento/Backend/Controller/Adminhtml/System/Store/DeleteStorePost.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,31 @@
66
*/
77
namespace Magento\Backend\Controller\Adminhtml\System\Store;
88

9+
use Magento\Framework\App\Request\Http as HttpRequest;
910
use Magento\Framework\Controller\ResultFactory;
11+
use Magento\Framework\Exception\NotFoundException;
1012

1113
class DeleteStorePost extends \Magento\Backend\Controller\Adminhtml\System\Store
1214
{
1315
/**
1416
* Delete store view post action
1517
*
1618
* @return \Magento\Backend\Model\View\Result\Redirect
19+
* @throws NotFoundException
1720
*/
1821
public function execute()
1922
{
20-
$itemId = $this->getRequest()->getParam('item_id');
21-
23+
/** @var HttpRequest $request */
24+
$request = $this->getRequest();
2225
/** @var \Magento\Backend\Model\View\Result\Redirect $redirectResult */
23-
$redirectResult = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
26+
$redirectResult = $this->resultFactory->create(
27+
ResultFactory::TYPE_REDIRECT
28+
);
29+
if (!$request->isPost()) {
30+
throw new NotFoundException(__('Page not found.'));
31+
}
32+
33+
$itemId = $request->getParam('item_id');
2434
if (!($model = $this->_objectManager->create(\Magento\Store\Model\Store::class)->load($itemId))) {
2535
$this->messageManager->addError(__('Something went wrong. Please try again.'));
2636
return $redirectResult->setPath('adminhtml/*/');

app/code/Magento/Backend/Controller/Adminhtml/System/Store/DeleteWebsitePost.php

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,30 @@
77
namespace Magento\Backend\Controller\Adminhtml\System\Store;
88

99
use Magento\Framework\Controller\ResultFactory;
10+
use Magento\Framework\App\Request\Http as HttpRequest;
11+
use Magento\Framework\Exception\NotFoundException;
1012

1113
class DeleteWebsitePost extends \Magento\Backend\Controller\Adminhtml\System\Store
1214
{
1315
/**
1416
* @return \Magento\Backend\Model\View\Result\Redirect
17+
* @throws NotFoundException
1518
*/
1619
public function execute()
1720
{
18-
$itemId = $this->getRequest()->getParam('item_id');
19-
$model = $this->_objectManager->create(\Magento\Store\Model\Website::class);
20-
$model->load($itemId);
21-
21+
/** @var HttpRequest $request */
22+
$request = $this->getRequest();
2223
/** @var \Magento\Backend\Model\View\Result\Redirect $redirectResult */
23-
$redirectResult = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
24+
$redirectResult = $this->resultFactory->create(
25+
ResultFactory::TYPE_REDIRECT
26+
);
27+
if (!$request->isPost()) {
28+
throw new NotFoundException(__('Page not found.'));
29+
}
2430

31+
$itemId = $request->getParam('item_id');
32+
$model = $this->_objectManager->create(\Magento\Store\Model\Website::class);
33+
$model->load($itemId);
2534
if (!$model) {
2635
$this->messageManager->addError(__('Something went wrong. Please try again.'));
2736
return $redirectResult->setPath('adminhtml/*/');

app/code/Magento/Backend/view/adminhtml/templates/system/search.phtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
<% if (data.items.length) { %>
4040
<% _.each(data.items, function(value){ %>
4141
<li class="item"
42-
<%- data.optionData(value) %>
42+
<%= data.optionData(value) %>
4343
>
4444
<a href="<%- value.url %>" class="title"><%- value.name %></a>
4545
<span class="type"><%- value.type %></span>

app/code/Magento/Catalog/view/adminhtml/templates/catalog/product/edit/attribute_set.phtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<% } %>
1515
<ul data-mage-init='{"menu":[]}'>
1616
<% _.each(data.items, function(value) { %>
17-
<li <%- data.optionData(value) %>><a href="#"><%- value.label %></a></li>
17+
<li <%= data.optionData(value) %>><a href="#"><%- value.label %></a></li>
1818
<% }); %>
1919
</ul>
2020
<% if (!data.term && data.items.length && !data.allShown()) { %>

app/code/Magento/Config/App/Config/Type/System.php

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
use Magento\Framework\App\Config\ConfigTypeInterface;
99
use Magento\Framework\App\ObjectManager;
1010
use Magento\Config\App\Config\Type\System\Reader;
11+
use Magento\Framework\Serialize\Serializer\Sensitive as SensitiveSerializer;
12+
use Magento\Framework\Serialize\Serializer\SensitiveFactory as SensitiveSerializerFactory;
1113

1214
/**
1315
* System configuration type
@@ -56,7 +58,7 @@ class System implements ConfigTypeInterface
5658
private $fallback;
5759

5860
/**
59-
* @var \Magento\Framework\Serialize\SerializerInterface
61+
* @var SensitiveSerializer
6062
*/
6163
private $serializer;
6264

@@ -91,6 +93,9 @@ class System implements ConfigTypeInterface
9193
* @param int $cachingNestedLevel
9294
* @param string $configType
9395
* @param Reader $reader
96+
* @param SensitiveSerializerFactory|null $sensitiveFactory
97+
*
98+
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
9499
*/
95100
public function __construct(
96101
\Magento\Framework\App\Config\ConfigSourceInterface $source,
@@ -101,17 +106,25 @@ public function __construct(
101106
\Magento\Framework\App\Config\Spi\PreProcessorInterface $preProcessor,
102107
$cachingNestedLevel = 1,
103108
$configType = self::CONFIG_TYPE,
104-
Reader $reader = null
109+
Reader $reader = null,
110+
SensitiveSerializerFactory $sensitiveFactory = null
105111
) {
106112
$this->source = $source;
107113
$this->postProcessor = $postProcessor;
108114
$this->preProcessor = $preProcessor;
109115
$this->cache = $cache;
110116
$this->cachingNestedLevel = $cachingNestedLevel;
111117
$this->fallback = $fallback;
112-
$this->serializer = $serializer;
113118
$this->configType = $configType;
114-
$this->reader = $reader ?: ObjectManager::getInstance()->get(Reader::class);
119+
$this->reader = $reader ?: ObjectManager::getInstance()
120+
->get(Reader::class);
121+
$sensitiveFactory = $sensitiveFactory ?? ObjectManager::getInstance()
122+
->get(SensitiveSerializerFactory::class);
123+
//Using sensitive serializer because any kind of information may
124+
//be stored in configs.
125+
$this->serializer = $sensitiveFactory->create(
126+
['serializer' => $serializer]
127+
);
115128
}
116129

117130
/**

app/code/Magento/Config/Test/Unit/App/Config/Type/SystemTest.php

Lines changed: 17 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
use Magento\Framework\App\Config\Spi\PostProcessorInterface;
1212
use Magento\Framework\App\Config\Spi\PreProcessorInterface;
1313
use Magento\Framework\Cache\FrontendInterface;
14+
use Magento\Framework\Serialize\Serializer\Sensitive;
15+
use Magento\Framework\Serialize\Serializer\SensitiveFactory;
1416
use Magento\Framework\Serialize\SerializerInterface;
1517
use Magento\Store\Model\Config\Processor\Fallback;
1618
use Magento\Config\App\Config\Type\System\Reader;
@@ -74,22 +76,34 @@ public function setUp()
7476
->getMockForAbstractClass();
7577
$this->preProcessor = $this->getMockBuilder(PreProcessorInterface::class)
7678
->getMockForAbstractClass();
77-
$this->serializer = $this->getMockBuilder(SerializerInterface::class)
79+
$this->serializer = $this->getMockBuilder(Sensitive::class)
80+
->disableOriginalConstructor()
7881
->getMock();
7982
$this->reader = $this->getMockBuilder(Reader::class)
8083
->disableOriginalConstructor()
8184
->getMock();
85+
$sensitiveFactory = $this->getMockBuilder(SensitiveFactory::class)
86+
->disableOriginalConstructor()
87+
->getMock();
88+
$sensitiveFactory->expects($this->any())
89+
->method('create')
90+
->willReturn($this->serializer);
91+
/** @var SerializerInterface|\PHPUnit_Framework_MockObject_MockObject $serializerMock */
92+
$serializerMock = $this->getMockBuilder(SerializerInterface::class)
93+
->disableOriginalConstructor()
94+
->getMock();
8295

8396
$this->configType = new System(
8497
$this->source,
8598
$this->postProcessor,
8699
$this->fallback,
87100
$this->cache,
88-
$this->serializer,
101+
$serializerMock,
89102
$this->preProcessor,
90103
1,
91104
'system',
92-
$this->reader
105+
$this->reader,
106+
$sensitiveFactory
93107
);
94108
}
95109

@@ -133,49 +147,4 @@ public function testGetCachedWithLoadAllData()
133147
->willReturn($data);
134148
$this->assertEquals($data, $this->configType->get(''));
135149
}
136-
137-
public function testGetNotCached()
138-
{
139-
$path = 'stores/default/dev/unsecure/url';
140-
$url = 'http://magento.test/';
141-
142-
$dataToCache = [
143-
'unsecure' => [
144-
'url' => $url
145-
]
146-
];
147-
$data = [
148-
'default' => [],
149-
'websites' => [],
150-
'stores' => [
151-
'default' => [
152-
'dev' => [
153-
'unsecure' => [
154-
'url' => $url
155-
]
156-
]
157-
]
158-
]
159-
];
160-
$this->cache->expects($this->any())
161-
->method('load')
162-
->willReturnOnConsecutiveCalls(false, false);
163-
164-
$this->serializer->expects($this->atLeastOnce())
165-
->method('serialize')
166-
->willReturn(serialize($dataToCache));
167-
$this->cache->expects($this->atLeastOnce())
168-
->method('save')
169-
->willReturnSelf();
170-
$this->reader->expects($this->once())
171-
->method('read')
172-
->willReturn($data);
173-
$this->postProcessor->expects($this->once())
174-
->method('process')
175-
->with($data)
176-
->willReturn($data);
177-
178-
$this->assertEquals($url, $this->configType->get($path));
179-
$this->assertEquals($url, $this->configType->get($path));
180-
}
181150
}

app/code/Magento/SalesRule/Block/Adminhtml/Promo/Widget/Chooser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public function prepareElementHtml(\Magento\Framework\Data\Form\Element\Abstract
8787
if ($element->getValue()) {
8888
$rule = $this->ruleFactory->create()->load((int)$element->getValue());
8989
if ($rule->getId()) {
90-
$chooser->setLabel($rule->getName());
90+
$chooser->setLabel($this->escapeHtml($rule->getName()));
9191
}
9292
}
9393

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace Magento\Framework\Serialize\Serializer;
10+
11+
use Magento\Framework\Encryption\EncryptorInterface;
12+
use Magento\Framework\Serialize\SerializerInterface;
13+
14+
/**
15+
* Used to serialize sensitive data.
16+
*/
17+
class Sensitive implements SerializerInterface
18+
{
19+
/**
20+
* @var EncryptorInterface
21+
*/
22+
private $encryptor;
23+
24+
/**
25+
* @var SerializerInterface
26+
*/
27+
private $serializer;
28+
29+
/**
30+
* @param EncryptorInterface $encryptor
31+
* @param SerializerInterface $serializer
32+
*/
33+
public function __construct(
34+
EncryptorInterface $encryptor,
35+
SerializerInterface $serializer
36+
) {
37+
$this->encryptor = $encryptor;
38+
$this->serializer = $serializer;
39+
}
40+
41+
/**
42+
* @inheritDoc
43+
*/
44+
public function serialize($data)
45+
{
46+
$serialized = $this->serializer->serialize($data);
47+
if (is_string($serialized)) {
48+
$serialized = $this->encryptor->encrypt($serialized);
49+
}
50+
51+
return $serialized;
52+
}
53+
54+
/**
55+
* @inheritDoc
56+
*/
57+
public function unserialize($string)
58+
{
59+
$string = $this->encryptor->decrypt($string);
60+
61+
return $this->serializer->unserialize($string);
62+
}
63+
}

0 commit comments

Comments
 (0)