Skip to content

Commit b653b2f

Browse files
author
Alexander Akimov
authored
Merge pull request #3795 from magento-tsg/2.1.17-develop-pr64
[TSG] Backporting for 2.1 (pr64) (2.1.17)
2 parents 29e0994 + 9c479f3 commit b653b2f

File tree

169 files changed

+2114
-1390
lines changed

Some content is hidden

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

169 files changed

+2114
-1390
lines changed

app/code/Magento/AdminNotification/Block/Grid/Renderer/Actions.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ public function render(\Magento\Framework\DataObject $row)
5555

5656
$encodedUrl = $this->_urlHelper->getEncodedUrl();
5757
return sprintf(
58-
'%s%s<a class="action-delete" href="%s" onClick="deleteConfirm(\'%s\', this.href); return false;">%s</a>',
58+
'%s%s<a class="action-delete" href="%s" onclick="deleteConfirm(\'%s\', this.href, {data: {}});' .
59+
' return false;">%s</a>',
5960
$readDetailsHtml,
6061
$markAsReadHtml,
6162
$this->getUrl(

app/code/Magento/Backend/Block/System/Design/Edit.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ protected function _prepareLayout()
5050
{
5151
$this->getToolbar()->addChild(
5252
'back_button',
53-
'Magento\Backend\Block\Widget\Button',
53+
\Magento\Backend\Block\Widget\Button::class,
5454
[
5555
'label' => __('Back'),
5656
'onclick' => 'setLocation(\'' . $this->getUrl('adminhtml/*/') . '\')',
@@ -61,20 +61,20 @@ protected function _prepareLayout()
6161
if ($this->getDesignChangeId()) {
6262
$this->getToolbar()->addChild(
6363
'delete_button',
64-
'Magento\Backend\Block\Widget\Button',
64+
\Magento\Backend\Block\Widget\Button::class,
6565
[
6666
'label' => __('Delete'),
6767
'onclick' => 'deleteConfirm(\'' . __(
6868
'Are you sure?'
69-
) . '\', \'' . $this->getDeleteUrl() . '\')',
69+
) . '\', \'' . $this->getDeleteUrl() . '\', {data: {}})',
7070
'class' => 'delete'
7171
]
7272
);
7373
}
7474

7575
$this->getToolbar()->addChild(
7676
'save_button',
77-
'Magento\Backend\Block\Widget\Button',
77+
\Magento\Backend\Block\Widget\Button::class,
7878
[
7979
'label' => __('Save'),
8080
'class' => 'save primary',

app/code/Magento/Backend/Block/Widget/Form/Container.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class Container extends \Magento\Backend\Block\Widget\Container
4545

4646
/**
4747
* @return void
48+
* @SuppressWarnings(PHPMD.RequestAwareBlockMethod)
4849
*/
4950
protected function _construct()
5051
{
@@ -75,7 +76,7 @@ protected function _construct()
7576
'class' => 'delete',
7677
'onclick' => 'deleteConfirm(\'' . __(
7778
'Are you sure you want to do this?'
78-
) . '\', \'' . $this->getDeleteUrl() . '\')'
79+
) . '\', \'' . $this->getDeleteUrl() . '\', {data: {}})'
7980
]
8081
);
8182
}

app/code/Magento/Backend/Controller/Adminhtml/System/Design/Delete.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,25 @@ class Delete extends \Magento\Backend\Controller\Adminhtml\System\Design
1010
{
1111
/**
1212
* @return \Magento\Backend\Model\View\Result\Redirect
13+
* @throws \Magento\Framework\Exception\NotFoundException
1314
*/
1415
public function execute()
1516
{
17+
if (!$this->getRequest()->isPost()) {
18+
throw new \Magento\Framework\Exception\NotFoundException(__('Page not found.'));
19+
}
20+
1621
$id = $this->getRequest()->getParam('id');
1722
if ($id) {
18-
$design = $this->_objectManager->create('Magento\Framework\App\DesignInterface')->load($id);
23+
$design = $this->_objectManager->create(\Magento\Framework\App\DesignInterface::class)->load($id);
1924

2025
try {
2126
$design->delete();
22-
$this->messageManager->addSuccess(__('You deleted the design change.'));
27+
$this->messageManager->addSuccessMessage(__('You deleted the design change.'));
2328
} catch (\Magento\Framework\Exception\LocalizedException $e) {
24-
$this->messageManager->addError($e->getMessage());
29+
$this->messageManager->addErrorMessage($e->getMessage());
2530
} catch (\Exception $e) {
26-
$this->messageManager->addException($e, __("You can't delete the design change."));
31+
$this->messageManager->addExceptionMessage($e, __("You can't delete the design change."));
2732
}
2833
}
2934
/** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */

app/code/Magento/Backup/Controller/Adminhtml/Index/Disabled.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
* See COPYING.txt for license details.
55
*/
66

7-
declare(strict_types=1);
8-
97
namespace Magento\Backup\Controller\Adminhtml\Index;
108

119
use Magento\Backend\App\Action;

app/code/Magento/Captcha/Controller/Refresh/Index.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,15 @@ public function __construct(Context $context, \Magento\Captcha\Helper\Data $capt
2828
}
2929

3030
/**
31-
* {@inheritdoc}
31+
* @inheritdoc
32+
* @throws \Magento\Framework\Exception\NotFoundException
3233
*/
3334
public function execute()
3435
{
36+
if (!$this->getRequest()->isPost()) {
37+
throw new \Magento\Framework\Exception\NotFoundException(__('Page not found.'));
38+
}
39+
3540
$formId = $this->_request->getPost('formId');
3641
if (null === $formId) {
3742
try {

app/code/Magento/Captcha/Test/Unit/Controller/Refresh/IndexTest.php

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -52,22 +52,25 @@ class IndexTest extends \PHPUnit_Framework_TestCase
5252
*/
5353
protected $model;
5454

55+
/**
56+
* @inheritdoc
57+
*/
5558
protected function setUp()
5659
{
57-
$this->captchaHelperMock = $this->getMock('Magento\Captcha\Helper\Data', [], [], '', false);
58-
$this->captchaMock = $this->getMock('Magento\Captcha\Model\DefaultModel', [], [], '', false);
59-
$this->requestMock = $this->getMock('Magento\Framework\App\Request\Http', [], [], '', false);
60-
$this->responseMock = $this->getMock('Magento\Framework\App\Response\Http', [], [], '', false);
61-
$this->contextMock = $this->getMock('Magento\Framework\App\Action\Context', [], [], '', false);
62-
$this->viewMock = $this->getMock('Magento\Framework\App\ViewInterface');
63-
$this->layoutMock = $this->getMock('Magento\Framework\View\LayoutInterface');
64-
$this->flagMock = $this->getMock('Magento\Framework\App\ActionFlag', [], [], '', false);
65-
66-
$this->contextMock->expects($this->any())->method('getRequest')->will($this->returnValue($this->requestMock));
67-
$this->contextMock->expects($this->any())->method('getView')->will($this->returnValue($this->viewMock));
68-
$this->contextMock->expects($this->any())->method('getResponse')->will($this->returnValue($this->responseMock));
69-
$this->contextMock->expects($this->any())->method('getActionFlag')->will($this->returnValue($this->flagMock));
70-
$this->viewMock->expects($this->any())->method('getLayout')->will($this->returnValue($this->layoutMock));
60+
$this->captchaHelperMock = $this->getMock(\Magento\Captcha\Helper\Data::class, [], [], '', false);
61+
$this->captchaMock = $this->getMock(\Magento\Captcha\Model\DefaultModel::class, [], [], '', false);
62+
$this->requestMock = $this->getMock(\Magento\Framework\App\Request\Http::class, [], [], '', false);
63+
$this->responseMock = $this->getMock(\Magento\Framework\App\Response\Http::class, [], [], '', false);
64+
$this->contextMock = $this->getMock(\Magento\Framework\App\Action\Context::class, [], [], '', false);
65+
$this->viewMock = $this->getMock(\Magento\Framework\App\ViewInterface::class);
66+
$this->layoutMock = $this->getMock(\Magento\Framework\View\LayoutInterface::class);
67+
$this->flagMock = $this->getMock(\Magento\Framework\App\ActionFlag::class, [], [], '', false);
68+
69+
$this->contextMock->expects($this->any())->method('getRequest')->willReturn($this->requestMock);
70+
$this->contextMock->expects($this->any())->method('getView')->willReturn($this->viewMock);
71+
$this->contextMock->expects($this->any())->method('getResponse')->willReturn($this->responseMock);
72+
$this->contextMock->expects($this->any())->method('getActionFlag')->willReturn($this->flagMock);
73+
$this->viewMock->expects($this->any())->method('getLayout')->willReturn($this->layoutMock);
7174

7275
$this->model = new \Magento\Captcha\Controller\Refresh\Index($this->contextMock, $this->captchaHelperMock);
7376
}
@@ -82,18 +85,19 @@ public function testExecute($formId, $callsNumber)
8285
$content = ['formId' => $formId];
8386

8487
$blockMethods = ['setFormId', 'setIsAjax', 'toHtml'];
85-
$blockMock = $this->getMock('Magento\Captcha\Block\Captcha', $blockMethods, [], '', false);
88+
$blockMock = $this->getMock(\Magento\Captcha\Block\Captcha::class, $blockMethods, [], '', false);
8689

87-
$this->requestMock->expects($this->any())->method('getPost')->with('formId')->will($this->returnValue($formId));
90+
$this->requestMock->expects($this->once())->method('isPost')->willReturn(true);
91+
$this->requestMock->expects($this->any())->method('getPost')->with('formId')->willReturn($formId);
8892
$this->requestMock->expects($this->exactly($callsNumber))->method('getContent')
89-
->will($this->returnValue(json_encode($content)));
93+
->willReturn(json_encode($content));
9094
$this->captchaHelperMock->expects($this->any())->method('getCaptcha')->with($formId)
91-
->will($this->returnValue($this->captchaMock));
95+
->willReturn($this->captchaMock);
9296
$this->captchaMock->expects($this->once())->method('generate');
93-
$this->captchaMock->expects($this->once())->method('getBlockName')->will($this->returnValue('block'));
94-
$this->captchaMock->expects($this->once())->method('getImgSrc')->will($this->returnValue('source'));
97+
$this->captchaMock->expects($this->once())->method('getBlockName')->willReturn('block');
98+
$this->captchaMock->expects($this->once())->method('getImgSrc')->willReturn('source');
9599
$this->layoutMock->expects($this->once())->method('createBlock')->with('block')
96-
->will($this->returnValue($blockMock));
100+
->willReturn($blockMock);
97101
$blockMock->expects($this->any())->method('setFormId')->with($formId)->will($this->returnValue($blockMock));
98102
$blockMock->expects($this->any())->method('setIsAjax')->with(true)->will($this->returnValue($blockMock));
99103
$blockMock->expects($this->once())->method('toHtml');

app/code/Magento/Catalog/Block/Adminhtml/Category/Edit/DeleteButton.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ public function getButtonData()
2727
return [
2828
'id' => 'delete',
2929
'label' => __('Delete'),
30-
'on_click' => "categoryDelete('" . $this->getDeleteUrl() . "')",
30+
'on_click' => "deleteConfirm('" .__('Are you sure you want to delete this category?') ."', '"
31+
. $this->getDeleteUrl() . "', {data: {}})",
3132
'class' => 'delete',
3233
'sort_order' => 10
3334
];

app/code/Magento/Catalog/Block/Adminhtml/Product/Attribute/Set/Main.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ protected function _prepareLayout()
136136
) . '\', \'' . $this->getUrl(
137137
'catalog/*/delete',
138138
['id' => $setId]
139-
) . '\')',
139+
) . '\', {data: {}})',
140140
'class' => 'delete'
141141
]
142142
);

app/code/Magento/Catalog/Controller/Adminhtml/Category/CategoriesJson.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,18 @@ public function __construct(
3737
* Get tree node (Ajax version)
3838
*
3939
* @return \Magento\Framework\Controller\ResultInterface
40+
* @throws \Magento\Framework\Exception\NotFoundException
4041
*/
4142
public function execute()
4243
{
44+
if (!$this->getRequest()->isPost()) {
45+
throw new \Magento\Framework\Exception\NotFoundException(__('Page not found.'));
46+
}
47+
4348
if ($this->getRequest()->getParam('expand_all')) {
44-
$this->_objectManager->get('Magento\Backend\Model\Auth\Session')->setIsTreeWasExpanded(true);
49+
$this->_objectManager->get(\Magento\Backend\Model\Auth\Session::class)->setIsTreeWasExpanded(true);
4550
} else {
46-
$this->_objectManager->get('Magento\Backend\Model\Auth\Session')->setIsTreeWasExpanded(false);
51+
$this->_objectManager->get(\Magento\Backend\Model\Auth\Session::class)->setIsTreeWasExpanded(false);
4752
}
4853
$categoryId = (int)$this->getRequest()->getPost('id');
4954
if ($categoryId) {
@@ -58,7 +63,7 @@ public function execute()
5863
/** @var \Magento\Framework\Controller\Result\Json $resultJson */
5964
$resultJson = $this->resultJsonFactory->create();
6065
return $resultJson->setJsonData(
61-
$this->layoutFactory->create()->createBlock('Magento\Catalog\Block\Adminhtml\Category\Tree')
66+
$this->layoutFactory->create()->createBlock(\Magento\Catalog\Block\Adminhtml\Category\Tree::class)
6267
->getTreeJson($category)
6368
);
6469
}

app/code/Magento/Catalog/Controller/Adminhtml/Category/Delete.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,14 @@ public function __construct(
2727
* Delete category action
2828
*
2929
* @return \Magento\Backend\Model\View\Result\Redirect
30+
* @throws \Magento\Framework\Exception\NotFoundException
3031
*/
3132
public function execute()
3233
{
34+
if (!$this->getRequest()->isPost()) {
35+
throw new \Magento\Framework\Exception\NotFoundException(__('Page not found.'));
36+
}
37+
3338
/** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
3439
$resultRedirect = $this->resultRedirectFactory->create();
3540

@@ -42,12 +47,12 @@ public function execute()
4247
$this->_eventManager->dispatch('catalog_controller_category_delete', ['category' => $category]);
4348
$this->_auth->getAuthStorage()->setDeletedPath($category->getPath());
4449
$this->categoryRepository->delete($category);
45-
$this->messageManager->addSuccess(__('You deleted the category.'));
50+
$this->messageManager->addSuccessMessage(__('You deleted the category.'));
4651
} catch (\Magento\Framework\Exception\LocalizedException $e) {
47-
$this->messageManager->addError($e->getMessage());
52+
$this->messageManager->addErrorMessage($e->getMessage());
4853
return $resultRedirect->setPath('catalog/*/edit', ['_current' => true]);
4954
} catch (\Exception $e) {
50-
$this->messageManager->addError(__('Something went wrong while trying to delete the category.'));
55+
$this->messageManager->addErrorMessage(__('Something went wrong while trying to delete the category.'));
5156
return $resultRedirect->setPath('catalog/*/edit', ['_current' => true]);
5257
}
5358
}

app/code/Magento/Catalog/Controller/Adminhtml/Category/Move.php

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ class Move extends \Magento\Catalog\Controller\Adminhtml\Category
2626
/**
2727
* @param \Magento\Backend\App\Action\Context $context
2828
* @param \Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory
29-
* @param \Magento\Framework\View\LayoutFactory $layoutFactory,
30-
* @param \Psr\Log\LoggerInterface $logger,
29+
* @param \Magento\Framework\View\LayoutFactory $layoutFactory
30+
* @param \Psr\Log\LoggerInterface $logger
3131
*/
3232
public function __construct(
3333
\Magento\Backend\App\Action\Context $context,
@@ -45,16 +45,17 @@ public function __construct(
4545
* Move category action
4646
*
4747
* @return \Magento\Framework\Controller\Result\Raw
48+
* @throws \Magento\Framework\Exception\NotFoundException
4849
*/
4950
public function execute()
5051
{
51-
/**
52-
* New parent category identifier
53-
*/
52+
if (!$this->getRequest()->isPost()) {
53+
throw new \Magento\Framework\Exception\NotFoundException(__('Page not found.'));
54+
}
55+
56+
/** New parent category identifier */
5457
$parentNodeId = $this->getRequest()->getPost('pid', false);
55-
/**
56-
* Category id after which we have put our category
57-
*/
58+
/** Category id after which we have put our category */
5859
$prevNodeId = $this->getRequest()->getPost('aid', false);
5960

6061
/** @var $block \Magento\Framework\View\Element\Messages */
@@ -69,18 +70,18 @@ public function execute()
6970
$category->move($parentNodeId, $prevNodeId);
7071
} catch (\Magento\Framework\Exception\AlreadyExistsException $e) {
7172
$error = true;
72-
$this->messageManager->addError(__('There was a category move error. %1', $e->getMessage()));
73+
$this->messageManager->addErrorMessage(__('There was a category move error. %1', $e->getMessage()));
7374
} catch (\Magento\Framework\Exception\LocalizedException $e) {
7475
$error = true;
75-
$this->messageManager->addError($e->getMessage());
76+
$this->messageManager->addErrorMessage($e);
7677
} catch (\Exception $e) {
7778
$error = true;
78-
$this->messageManager->addError(__('There was a category move error.'));
79+
$this->messageManager->addErrorMessage(__('There was a category move error.'));
7980
$this->logger->critical($e);
8081
}
8182

8283
if (!$error) {
83-
$this->messageManager->addSuccess(__('You moved the category'));
84+
$this->messageManager->addSuccessMessage(__('You moved the category.'));
8485
}
8586

8687
$block->setMessages($this->messageManager->getMessages(true));

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
namespace Magento\Catalog\Controller\Adminhtml\Product\Action\Attribute;
88

99
use Magento\Backend\App\Action;
10+
use Magento\Framework\Exception\NotFoundException;
1011

1112
/**
1213
* Class Save
@@ -81,12 +82,17 @@ public function __construct(
8182
* Update product attributes
8283
*
8384
* @return \Magento\Backend\Model\View\Result\Redirect
85+
* @throws NotFoundException
8486
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
8587
* @SuppressWarnings(PHPMD.NPathComplexity)
8688
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
8789
*/
8890
public function execute()
8991
{
92+
if (!$this->getRequest()->isPost()) {
93+
throw new NotFoundException(__('Page not found'));
94+
}
95+
9096
if (!$this->_validateProducts()) {
9197
return $this->resultRedirectFactory->create()->setPath('catalog/product/', ['_current' => true]);
9298
}

app/code/Magento/Catalog/Controller/Adminhtml/Product/MassStatus.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Magento\Backend\App\Action;
1010
use Magento\Catalog\Controller\Adminhtml\Product;
1111
use Magento\Framework\Controller\ResultFactory;
12+
use Magento\Framework\Exception\NotFoundException;
1213
use Magento\Ui\Component\MassAction\Filter;
1314
use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory;
1415

@@ -74,9 +75,14 @@ public function _validateMassStatus(array $productIds, $status)
7475
* Update product(s) status action
7576
*
7677
* @return \Magento\Backend\Model\View\Result\Redirect
78+
* @throws NotFoundException
7779
*/
7880
public function execute()
7981
{
82+
if (!$this->getRequest()->isPost()) {
83+
throw new NotFoundException(__('Page not found'));
84+
}
85+
8086
$collection = $this->filter->getCollection($this->collectionFactory->create());
8187
$productIds = $collection->getAllIds();
8288
$storeId = (int) $this->getRequest()->getParam('store', 0);
@@ -89,12 +95,14 @@ public function execute()
8995

9096
try {
9197
$this->_validateMassStatus($productIds, $status);
92-
$this->_objectManager->get('Magento\Catalog\Model\Product\Action')
98+
$this->_objectManager->get(\Magento\Catalog\Model\Product\Action::class)
9399
->updateAttributes($productIds, ['status' => $status], $storeId);
94-
$this->messageManager->addSuccess(__('A total of %1 record(s) have been updated.', count($productIds)));
100+
$this->messageManager->addSuccessMessage(
101+
__('A total of %1 record(s) have been updated.', count($productIds))
102+
);
95103
$this->_productPriceIndexerProcessor->reindexList($productIds);
96104
} catch (\Magento\Framework\Exception\LocalizedException $e) {
97-
$this->messageManager->addError($e->getMessage());
105+
$this->messageManager->addErrorMessage($e->getMessage());
98106
} catch (\Exception $e) {
99107
$this->_getSession()->addException($e, __('Something went wrong while updating the product(s) status.'));
100108
}

0 commit comments

Comments
 (0)