Skip to content
This repository was archived by the owner on Apr 29, 2019. It is now read-only.

Commit 467ee16

Browse files
author
Joan He
committed
Merge remote-tracking branch 'upstream/2.3.0-release' into MAGETWO-90280
2 parents 942196b + 32219a9 commit 467ee16

File tree

121 files changed

+3064
-5374
lines changed

Some content is hidden

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

121 files changed

+3064
-5374
lines changed

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
<?php
22
/**
3-
*
43
* Copyright © Magento, Inc. All rights reserved.
54
* See COPYING.txt for license details.
65
*/
76
namespace Magento\Backend\Controller\Adminhtml\System\Store;
87

8+
use Magento\Framework\App\Action\HttpPostActionInterface;
99
use Magento\Framework\Controller\ResultFactory;
1010

11-
class DeleteGroupPost extends \Magento\Backend\Controller\Adminhtml\System\Store
11+
/**
12+
* Delete store.
13+
*/
14+
class DeleteGroupPost extends \Magento\Backend\Controller\Adminhtml\System\Store implements HttpPostActionInterface
1215
{
1316
/**
17+
* @inheritDoc
1418
* @return \Magento\Backend\Model\View\Result\Redirect
1519
*/
1620
public function execute()

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
<?php
22
/**
3-
*
43
* Copyright © Magento, Inc. All rights reserved.
54
* See COPYING.txt for license details.
65
*/
76
namespace Magento\Backend\Controller\Adminhtml\System\Store;
87

8+
use Magento\Framework\App\Action\HttpPostActionInterface;
99
use Magento\Framework\Controller\ResultFactory;
1010

11-
class DeleteStorePost extends \Magento\Backend\Controller\Adminhtml\System\Store
11+
/**
12+
* Delete store view.
13+
*/
14+
class DeleteStorePost extends \Magento\Backend\Controller\Adminhtml\System\Store implements HttpPostActionInterface
1215
{
1316
/**
1417
* Delete store view post action

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,13 @@
99
use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface;
1010
use Magento\Framework\Controller\ResultFactory;
1111

12+
/**
13+
* Delete website.
14+
*/
1215
class DeleteWebsitePost extends \Magento\Backend\Controller\Adminhtml\System\Store implements HttpPostActionInterface
1316
{
1417
/**
18+
* @inheritDoc
1519
* @return \Magento\Backend\Model\View\Result\Redirect
1620
*/
1721
public function execute()

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

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

app/code/Magento/Catalog/Controller/Adminhtml/Category/Image/Upload.php

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@
55
*/
66
namespace Magento\Catalog\Controller\Adminhtml\Category\Image;
77

8+
use Magento\Framework\App\Action\HttpPostActionInterface;
89
use Magento\Framework\Controller\ResultFactory;
910

1011
/**
1112
* Class Upload
1213
*/
13-
class Upload extends \Magento\Backend\App\Action
14+
class Upload extends \Magento\Backend\App\Action implements HttpPostActionInterface
1415
{
1516
/**
1617
* Image uploader
@@ -54,14 +55,6 @@ public function execute()
5455

5556
try {
5657
$result = $this->imageUploader->saveFileToTmpDir($imageId);
57-
58-
$result['cookie'] = [
59-
'name' => $this->_getSession()->getName(),
60-
'value' => $this->_getSession()->getSessionId(),
61-
'lifetime' => $this->_getSession()->getCookieLifetime(),
62-
'path' => $this->_getSession()->getCookiePath(),
63-
'domain' => $this->_getSession()->getCookieDomain(),
64-
];
6558
} catch (\Exception $e) {
6659
$result = ['error' => $e->getMessage(), 'errorcode' => $e->getCode()];
6760
}

app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Save.php

Lines changed: 35 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Magento\Catalog\Controller\Adminhtml\Product\Attribute;
1515
use Magento\Catalog\Helper\Product;
1616
use Magento\Catalog\Model\Product\Attribute\Frontend\Inputtype\Presentation;
17+
use Magento\Framework\Serialize\Serializer\FormData;
1718
use Magento\Catalog\Model\Product\AttributeSet\BuildFactory;
1819
use Magento\Catalog\Model\ResourceModel\Eav\AttributeFactory;
1920
use Magento\Eav\Model\Adminhtml\System\Config\Source\Inputtype\Validator;
@@ -32,6 +33,8 @@
3233
use Magento\Framework\View\Result\PageFactory;
3334

3435
/**
36+
* Product attribute save controller.
37+
*
3538
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
3639
*/
3740
class Save extends Attribute implements HttpPostActionInterface
@@ -76,6 +79,11 @@ class Save extends Attribute implements HttpPostActionInterface
7679
*/
7780
private $presentation;
7881

82+
/**
83+
* @var FormData|null
84+
*/
85+
private $formDataSerializer;
86+
7987
/**
8088
* @param Context $context
8189
* @param FrontendInterface $attributeLabelCache
@@ -89,6 +97,7 @@ class Save extends Attribute implements HttpPostActionInterface
8997
* @param Product $productHelper
9098
* @param LayoutFactory $layoutFactory
9199
* @param Presentation|null $presentation
100+
* @param FormData|null $formDataSerializer
92101
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
93102
*/
94103
public function __construct(
@@ -103,7 +112,8 @@ public function __construct(
103112
FilterManager $filterManager,
104113
Product $productHelper,
105114
LayoutFactory $layoutFactory,
106-
Presentation $presentation = null
115+
Presentation $presentation = null,
116+
FormData $formDataSerializer = null
107117
) {
108118
parent::__construct($context, $attributeLabelCache, $coreRegistry, $resultPageFactory);
109119
$this->buildFactory = $buildFactory;
@@ -114,19 +124,38 @@ public function __construct(
114124
$this->groupCollectionFactory = $groupCollectionFactory;
115125
$this->layoutFactory = $layoutFactory;
116126
$this->presentation = $presentation ?: ObjectManager::getInstance()->get(Presentation::class);
127+
$this->formDataSerializer = $formDataSerializer
128+
?: ObjectManager::getInstance()->get(FormData::class);
117129
}
118130

119131
/**
132+
* @inheritdoc
133+
*
120134
* @return Redirect
121135
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
122136
* @SuppressWarnings(PHPMD.NPathComplexity)
123137
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
138+
* @throws \Zend_Validate_Exception
124139
*/
125140
public function execute()
126141
{
142+
try {
143+
$optionData = $this->formDataSerializer
144+
->unserialize($this->getRequest()->getParam('serialized_options', '[]'));
145+
} catch (\InvalidArgumentException $e) {
146+
$message = __("The attribute couldn't be saved due to an error. Verify your information and try again. "
147+
. "If the error persists, please try again later.");
148+
$this->messageManager->addErrorMessage($message);
149+
return $this->returnResult('catalog/*/edit', ['_current' => true], ['error' => true]);
150+
}
151+
127152
$data = $this->getRequest()->getPostValue();
153+
$data = array_replace_recursive(
154+
$data,
155+
$optionData
156+
);
157+
128158
if ($data) {
129-
$this->preprocessOptionsData($data);
130159
$setId = $this->getRequest()->getParam('set');
131160

132161
$attributeSet = null;
@@ -135,7 +164,7 @@ public function execute()
135164
$name = trim($name);
136165

137166
try {
138-
/** @var $attributeSet Set */
167+
/** @var Set $attributeSet */
139168
$attributeSet = $this->buildFactory->create()
140169
->setEntityTypeId($this->_entityTypeId)
141170
->setSkeletonId($setId)
@@ -157,7 +186,7 @@ public function execute()
157186

158187
$attributeId = $this->getRequest()->getParam('attribute_id');
159188

160-
/** @var $model ProductAttributeInterface */
189+
/** @var ProductAttributeInterface $model */
161190
$model = $this->attributeFactory->create();
162191
if ($attributeId) {
163192
$model->load($attributeId);
@@ -189,7 +218,7 @@ public function execute()
189218

190219
//validate frontend_input
191220
if (isset($data['frontend_input'])) {
192-
/** @var $inputType Validator */
221+
/** @var Validator $inputType */
193222
$inputType = $this->validatorFactory->create();
194223
if (!$inputType->isValid($data['frontend_input'])) {
195224
foreach ($inputType->getMessages() as $message) {
@@ -317,28 +346,8 @@ public function execute()
317346
}
318347

319348
/**
320-
* Extract options data from serialized options field and append to data array.
349+
* Provides an initialized Result object.
321350
*
322-
* This logic is required to overcome max_input_vars php limit
323-
* that may vary and/or be inaccessible to change on different instances.
324-
*
325-
* @param array $data
326-
* @return void
327-
*/
328-
private function preprocessOptionsData(&$data)
329-
{
330-
if (isset($data['serialized_options'])) {
331-
$serializedOptions = json_decode($data['serialized_options'], JSON_OBJECT_AS_ARRAY);
332-
foreach ($serializedOptions as $serializedOption) {
333-
$option = [];
334-
parse_str($serializedOption, $option);
335-
$data = array_replace_recursive($data, $option);
336-
}
337-
}
338-
unset($data['serialized_options']);
339-
}
340-
341-
/**
342351
* @param string $path
343352
* @param array $params
344353
* @param array $response

app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Validate.php

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,18 @@
77

88
namespace Magento\Catalog\Controller\Adminhtml\Product\Attribute;
99

10+
use Magento\Framework\Serialize\Serializer\FormData;
1011
use Magento\Framework\App\Action\HttpGetActionInterface;
1112
use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface;
13+
use Magento\Framework\App\ObjectManager;
1214
use Magento\Framework\DataObject;
1315
use Magento\Catalog\Controller\Adminhtml\Product\Attribute as AttributeAction;
1416

17+
/**
18+
* Product attribute validate controller.
19+
*
20+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
21+
*/
1522
class Validate extends AttributeAction implements HttpGetActionInterface, HttpPostActionInterface
1623
{
1724
const DEFAULT_MESSAGE_KEY = 'message';
@@ -31,6 +38,11 @@ class Validate extends AttributeAction implements HttpGetActionInterface, HttpPo
3138
*/
3239
private $multipleAttributeList;
3340

41+
/**
42+
* @var FormData|null
43+
*/
44+
private $formDataSerializer;
45+
3446
/**
3547
* Constructor
3648
*
@@ -41,6 +53,7 @@ class Validate extends AttributeAction implements HttpGetActionInterface, HttpPo
4153
* @param \Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory
4254
* @param \Magento\Framework\View\LayoutFactory $layoutFactory
4355
* @param array $multipleAttributeList
56+
* @param FormData|null $formDataSerializer
4457
*/
4558
public function __construct(
4659
\Magento\Backend\App\Action\Context $context,
@@ -49,15 +62,20 @@ public function __construct(
4962
\Magento\Framework\View\Result\PageFactory $resultPageFactory,
5063
\Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory,
5164
\Magento\Framework\View\LayoutFactory $layoutFactory,
52-
array $multipleAttributeList = []
65+
array $multipleAttributeList = [],
66+
FormData $formDataSerializer = null
5367
) {
5468
parent::__construct($context, $attributeLabelCache, $coreRegistry, $resultPageFactory);
5569
$this->resultJsonFactory = $resultJsonFactory;
5670
$this->layoutFactory = $layoutFactory;
5771
$this->multipleAttributeList = $multipleAttributeList;
72+
$this->formDataSerializer = $formDataSerializer ?: ObjectManager::getInstance()
73+
->get(FormData::class);
5874
}
5975

6076
/**
77+
* @inheritdoc
78+
*
6179
* @return \Magento\Framework\Controller\ResultInterface
6280
* @SuppressWarnings(PHPMD.NPathComplexity)
6381
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
@@ -66,6 +84,15 @@ public function execute()
6684
{
6785
$response = new DataObject();
6886
$response->setError(false);
87+
try {
88+
$optionsData = $this->formDataSerializer
89+
->unserialize($this->getRequest()->getParam('serialized_options', '[]'));
90+
} catch (\InvalidArgumentException $e) {
91+
$message = __("The attribute couldn't be validated due to an error. Verify your information and try again. "
92+
. "If the error persists, please try again later.");
93+
$this->setMessageToResponse($response, [$message]);
94+
$response->setError(true);
95+
}
6996

7097
$attributeCode = $this->getRequest()->getParam('attribute_code');
7198
$frontendLabel = $this->getRequest()->getParam('frontend_label');
@@ -105,10 +132,10 @@ public function execute()
105132
}
106133

107134
$multipleOption = $this->getRequest()->getParam("frontend_input");
108-
$multipleOption = null == $multipleOption ? 'select' : $multipleOption;
135+
$multipleOption = (null === $multipleOption) ? 'select' : $multipleOption;
109136

110-
if (isset($this->multipleAttributeList[$multipleOption]) && !(null == ($multipleOption))) {
111-
$options = $this->getRequest()->getParam($this->multipleAttributeList[$multipleOption]);
137+
if (isset($this->multipleAttributeList[$multipleOption])) {
138+
$options = $optionsData[$this->multipleAttributeList[$multipleOption]] ?? null;
112139
$this->checkUniqueOption(
113140
$response,
114141
$options
@@ -126,7 +153,8 @@ public function execute()
126153
}
127154

128155
/**
129-
* Throws Exception if not unique values into options
156+
* Throws Exception if not unique values into options.
157+
*
130158
* @param array $optionsValues
131159
* @param array $deletedOptions
132160
* @return bool
@@ -160,6 +188,8 @@ private function setMessageToResponse($response, $messages)
160188
}
161189

162190
/**
191+
* Performs checking the uniqueness of the attribute options.
192+
*
163193
* @param DataObject $response
164194
* @param array|null $options
165195
* @return $this

0 commit comments

Comments
 (0)