Skip to content

Commit 5de0f07

Browse files
author
Oleksii Korshenko
authored
Merge pull request magento#1689 from magento-engcom/2.2-develop-prs
Public Pull Requests magento#12139 9768: Admin dashboard Most Viewed Products Tab only gives default attribute set's products(backport for 2.2) by @RomaKis magento#12131 [Backport 2.2] Close PayPal popup window in case of rejected request magento#10820 by @vovayatsyuk magento#12082 Products in cart report error when we have grouped or bundle product by @mihaifaget magento#11719 10920: Sku => Entity_id relations are fetched inefficiently when inserting attributes values during product import. by @nmalevanec magento#12031 Improve urn in xhtml by @enriquei4 magento#11988 10195: Order relation child is not set during edit operation(backport from 2.3 to 2.2) by @RomaKis magento#11962 11793: Magento2.1.5 admin shipping report shows wrong currency code by @RomaKis magento#11947 Fix json encoded attribute backend type when attribute value is null by @tkotosz magento#11902 magento#9151: [Github] Sitemap.xml: lastmod timestamp can contain invalid dates by @serhii-balko magento#11857 CMS Page - CMS Page - Force validate layout update xml in production mode when saving CMS Page - Handle layout update xml validation exceptions by @adrian-martinez-interactiv4 magento#11722 6802: Magento\Search\Helper\getSuggestUrl() not used in search template. by @nmalevanec magento#11461 [ISSUE-10811][BUGFIX] Update .htaccess.sample to replace FollowSymLin… by @diglin Fixed Public Issues magento#9768 Admin dashboard Most Viewed Products Tab only gives default attribute set's products magento#12079 Products in cart report error when we have grouped or bundle product magento#10920 Sku => Entity_id relations are fetched inefficiently when inserting attributes values during product import magento#6661 XHTML templates Don't Use Schema URNs magento#10195 Order relation child is not set during edit operation. magento#11793 Magento2.1.5 admin shipping report shows wrong currency code magento#9151 Sitemap.xml: lastmod timestamp can contain invalid dates magento#6802 Magento\Search\Helper\getSuggestUrl() not used in search template magento#10811 Replace FollowSymLinks with SymLinksIfOwnerMatch
2 parents 94b1db0 + 8eecb61 commit 5de0f07

File tree

30 files changed

+620
-80
lines changed

30 files changed

+620
-80
lines changed

.htaccess.sample

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,8 @@
111111
############################################
112112
## enable rewrites
113113

114-
Options +FollowSymLinks
114+
# The following line has better security but add some performance overhead - see https://httpd.apache.org/docs/2.4/en/misc/perf-tuning.html
115+
Options -FollowSymLinks +SymLinksIfOwnerMatch
115116
RewriteEngine on
116117

117118
############################################

app/code/Magento/CatalogImportExport/Model/Import/Product.php

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,18 @@
55
*/
66
namespace Magento\CatalogImportExport\Model\Import;
77

8+
use Magento\Catalog\Model\Config as CatalogConfig;
89
use Magento\Catalog\Model\Product\Visibility;
910
use Magento\CatalogImportExport\Model\Import\Product\RowValidatorInterface as ValidatorInterface;
1011
use Magento\Framework\App\Filesystem\DirectoryList;
11-
use Magento\Framework\App\ObjectManager;
12+
use Magento\Framework\Filesystem;
1213
use Magento\Framework\Model\ResourceModel\Db\ObjectRelationProcessor;
1314
use Magento\Framework\Model\ResourceModel\Db\TransactionManagerInterface;
1415
use Magento\Framework\Stdlib\DateTime;
15-
use Magento\Framework\Filesystem;
1616
use Magento\ImportExport\Model\Import;
1717
use Magento\ImportExport\Model\Import\Entity\AbstractEntity;
1818
use Magento\ImportExport\Model\Import\ErrorProcessing\ProcessingError;
1919
use Magento\ImportExport\Model\Import\ErrorProcessing\ProcessingErrorAggregatorInterface;
20-
use Magento\Catalog\Model\Config as CatalogConfig;
2120

2221
/**
2322
* Import entity product model
@@ -1293,20 +1292,15 @@ protected function _saveLinks()
12931292
*/
12941293
protected function _saveProductAttributes(array $attributesData)
12951294
{
1295+
$linkField = $this->getProductEntityLinkField();
12961296
foreach ($attributesData as $tableName => $skuData) {
12971297
$tableData = [];
12981298
foreach ($skuData as $sku => $attributes) {
1299-
$linkId = $this->_connection->fetchOne(
1300-
$this->_connection->select()
1301-
->from($this->getResource()->getTable('catalog_product_entity'))
1302-
->where('sku = ?', (string)$sku)
1303-
->columns($this->getProductEntityLinkField())
1304-
);
1305-
1299+
$linkId = $this->_oldSku[strtolower($sku)][$linkField];
13061300
foreach ($attributes as $attributeId => $storeValues) {
13071301
foreach ($storeValues as $storeId => $storeValue) {
13081302
$tableData[] = [
1309-
$this->getProductEntityLinkField() => $linkId,
1303+
$linkField => $linkId,
13101304
'attribute_id' => $attributeId,
13111305
'store_id' => $storeId,
13121306
'value' => $storeValue,
@@ -1316,6 +1310,7 @@ protected function _saveProductAttributes(array $attributesData)
13161310
}
13171311
$this->_connection->insertOnDuplicate($tableName, $tableData, ['value']);
13181312
}
1313+
13191314
return $this;
13201315
}
13211316

app/code/Magento/CatalogImportExport/Test/Unit/Model/Import/ProductTest.php

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
namespace Magento\CatalogImportExport\Test\Unit\Model\Import;
77

88
use Magento\Framework\App\Filesystem\DirectoryList;
9-
use Magento\Framework\Stdlib\DateTime;
109
use Magento\ImportExport\Model\Import;
1110

1211
/**
@@ -513,25 +512,6 @@ public function testSaveProductAttributes()
513512
]
514513
]
515514
];
516-
$entityTable = 'catalog_product_entity';
517-
$resource = $this->getMockBuilder(\Magento\CatalogImportExport\Model\Import\Proxy\Product\ResourceModel::class)
518-
->disableOriginalConstructor()
519-
->setMethods(['getTable'])
520-
->getMock();
521-
$resource->expects($this->once())->method('getTable')->with($entityTable)->willReturnArgument(0);
522-
$this->_resourceFactory->expects($this->once())->method('create')->willReturn($resource);
523-
$selectMock = $this->getMockBuilder(\Magento\Framework\DB\Select::class)
524-
->disableOriginalConstructor()
525-
->getMock();
526-
$selectMock->expects($this->once())->method('from')->with($entityTable, '*', null)->willReturnSelf();
527-
$selectMock->expects($this->once())->method('where')->with('sku = ?', $testSku)->willReturnSelf();
528-
$selectMock->expects($this->once())->method('columns')->with('entity_id')->willReturnSelf();
529-
$this->_connection->expects($this->any())->method('fetchOne')->willReturn(self::ENTITY_ID);
530-
$this->_connection->expects($this->any())->method('select')->willReturn($selectMock);
531-
$this->_connection->expects($this->any())
532-
->method('quoteInto')
533-
->willReturnCallback([$this, 'returnQuoteCallback']);
534-
535515
$tableData[] = [
536516
'entity_id' => self::ENTITY_ID,
537517
'attribute_id' => $attributeId,
@@ -541,6 +521,7 @@ public function testSaveProductAttributes()
541521
$this->_connection->expects($this->once())
542522
->method('insertOnDuplicate')
543523
->with($testTable, $tableData, ['value']);
524+
$this->setPropertyValue($this->importProduct, '_oldSku', [$testSku => ['entity_id' => self::ENTITY_ID]]);
544525
$object = $this->invokeMethod($this->importProduct, '_saveProductAttributes', [$attributesData]);
545526
$this->assertEquals($this->importProduct, $object);
546527
}

app/code/Magento/Cms/Controller/Adminhtml/Page/PostDataProcessor.php

Lines changed: 64 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,15 @@
66
*/
77
namespace Magento\Cms\Controller\Adminhtml\Page;
88

9+
use Magento\Cms\Model\Page\DomValidationState;
10+
use Magento\Framework\App\ObjectManager;
11+
use Magento\Framework\Config\Dom\ValidationException;
12+
use Magento\Framework\Config\Dom\ValidationSchemaException;
13+
14+
/**
15+
* Class PostDataProcessor
16+
* @package Magento\Cms\Controller\Adminhtml\Page
17+
*/
918
class PostDataProcessor
1019
{
1120
/**
@@ -23,19 +32,28 @@ class PostDataProcessor
2332
*/
2433
protected $messageManager;
2534

35+
/**
36+
* @var DomValidationState
37+
*/
38+
private $validationState;
39+
2640
/**
2741
* @param \Magento\Framework\Stdlib\DateTime\Filter\Date $dateFilter
2842
* @param \Magento\Framework\Message\ManagerInterface $messageManager
2943
* @param \Magento\Framework\View\Model\Layout\Update\ValidatorFactory $validatorFactory
44+
* @param DomValidationState $validationState
3045
*/
3146
public function __construct(
3247
\Magento\Framework\Stdlib\DateTime\Filter\Date $dateFilter,
3348
\Magento\Framework\Message\ManagerInterface $messageManager,
34-
\Magento\Framework\View\Model\Layout\Update\ValidatorFactory $validatorFactory
49+
\Magento\Framework\View\Model\Layout\Update\ValidatorFactory $validatorFactory,
50+
DomValidationState $validationState = null
3551
) {
3652
$this->dateFilter = $dateFilter;
3753
$this->messageManager = $messageManager;
3854
$this->validatorFactory = $validatorFactory;
55+
$this->validationState = $validationState
56+
?: ObjectManager::getInstance()->get(DomValidationState::class);
3957
}
4058

4159
/**
@@ -61,27 +79,27 @@ public function filter($data)
6179
* Validate post data
6280
*
6381
* @param array $data
64-
* @return bool Return FALSE if someone item is invalid
82+
* @return bool Return FALSE if some item is invalid
6583
*/
6684
public function validate($data)
6785
{
68-
$errorNo = true;
6986
if (!empty($data['layout_update_xml']) || !empty($data['custom_layout_update_xml'])) {
70-
/** @var $validatorCustomLayout \Magento\Framework\View\Model\Layout\Update\Validator */
71-
$validatorCustomLayout = $this->validatorFactory->create();
72-
if (!empty($data['layout_update_xml']) && !$validatorCustomLayout->isValid($data['layout_update_xml'])) {
73-
$errorNo = false;
74-
}
75-
if (!empty($data['custom_layout_update_xml'])
76-
&& !$validatorCustomLayout->isValid($data['custom_layout_update_xml'])
77-
) {
78-
$errorNo = false;
79-
}
80-
foreach ($validatorCustomLayout->getMessages() as $message) {
81-
$this->messageManager->addError($message);
87+
/** @var $layoutXmlValidator \Magento\Framework\View\Model\Layout\Update\Validator */
88+
$layoutXmlValidator = $this->validatorFactory->create(
89+
[
90+
'validationState' => $this->validationState,
91+
]
92+
);
93+
94+
if (!$this->validateData($data, $layoutXmlValidator)) {
95+
$validatorMessages = $layoutXmlValidator->getMessages();
96+
foreach ($validatorMessages as $message) {
97+
$this->messageManager->addErrorMessage($message);
98+
}
99+
return false;
82100
}
83101
}
84-
return $errorNo;
102+
return true;
85103
}
86104

87105
/**
@@ -108,4 +126,34 @@ public function validateRequireEntry(array $data)
108126
}
109127
return $errorNo;
110128
}
129+
130+
/**
131+
* Validate data, avoid cyclomatic complexity
132+
*
133+
* @param array $data
134+
* @param \Magento\Framework\View\Model\Layout\Update\Validator $layoutXmlValidator
135+
* @return bool
136+
*/
137+
private function validateData($data, $layoutXmlValidator)
138+
{
139+
try {
140+
if (!empty($data['layout_update_xml']) && !$layoutXmlValidator->isValid($data['layout_update_xml'])) {
141+
return false;
142+
}
143+
if (!empty($data['custom_layout_update_xml']) &&
144+
!$layoutXmlValidator->isValid($data['custom_layout_update_xml'])
145+
) {
146+
return false;
147+
}
148+
} catch (ValidationException $e) {
149+
return false;
150+
} catch (ValidationSchemaException $e) {
151+
return false;
152+
} catch (\Exception $e) {
153+
$this->messageManager->addExceptionMessage($e);
154+
return false;
155+
}
156+
157+
return true;
158+
}
111159
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
/**
3+
* Application config file resolver
4+
*
5+
* Copyright © Magento, Inc. All rights reserved.
6+
* See COPYING.txt for license details.
7+
*/
8+
namespace Magento\Cms\Model\Page;
9+
10+
/**
11+
* Class DomValidationState
12+
* @package Magento\Cms\Model\Page
13+
*/
14+
class DomValidationState implements \Magento\Framework\Config\ValidationStateInterface
15+
{
16+
/**
17+
* Retrieve validation state
18+
* Used in cms page post processor to force validate layout update xml
19+
*
20+
* @return boolean
21+
*/
22+
public function isValidationRequired()
23+
{
24+
return true;
25+
}
26+
}

app/code/Magento/Eav/Model/Entity/Attribute/Backend/JsonEncoded.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public function afterLoad($object)
5858
{
5959
parent::afterLoad($object);
6060
$attrCode = $this->getAttribute()->getAttributeCode();
61-
$object->setData($attrCode, $this->jsonSerializer->unserialize($object->getData($attrCode)));
61+
$object->setData($attrCode, $this->jsonSerializer->unserialize($object->getData($attrCode) ?: '{}'));
6262
return $this;
6363
}
6464
}

app/code/Magento/Eav/Test/Unit/Model/Entity/Attribute/Backend/JsonEncodedTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,4 +95,18 @@ public function testAfterLoad()
9595
$this->model->afterLoad($product);
9696
$this->assertEquals([1, 2, 3], $product->getData('json_encoded'));
9797
}
98+
99+
/**
100+
* Test after load handler with null attribute value
101+
*/
102+
public function testAfterLoadWithNullAttributeValue()
103+
{
104+
$product = new \Magento\Framework\DataObject(
105+
[
106+
'json_encoded' => null
107+
]
108+
);
109+
$this->model->afterLoad($product);
110+
$this->assertEquals([], $product->getData('json_encoded'));
111+
}
98112
}

app/code/Magento/Paypal/view/frontend/web/js/view/payment/method-renderer/in-context/checkout-express.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,9 @@ define(
7878
$('body').trigger('processStop');
7979
customerData.invalidate(['cart']);
8080
});
81-
}.bind(this));
81+
}.bind(this)).fail(function () {
82+
paypalExpressCheckout.checkout.closeFlow();
83+
});
8284
}
8385
}
8486
}

app/code/Magento/Reports/Block/Adminhtml/Grid/AbstractGrid.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -363,12 +363,11 @@ public function setStoreIds($storeIds)
363363
public function getCurrentCurrencyCode()
364364
{
365365
if ($this->_currentCurrencyCode === null) {
366-
$this->_currentCurrencyCode = count(
367-
$this->_storeIds
368-
) > 0 ? $this->_storeManager->getStore(
369-
array_shift($this->_storeIds)
370-
)->getBaseCurrencyCode() : $this->_storeManager->getStore()->getBaseCurrencyCode();
366+
$this->_currentCurrencyCode = count($this->_storeIds) > 0
367+
? $this->_storeManager->getStore(array_shift($this->_storeIds))->getCurrentCurrencyCode()
368+
: $this->_storeManager->getStore()->getBaseCurrencyCode();
371369
}
370+
372371
return $this->_currentCurrencyCode;
373372
}
374373

app/code/Magento/Reports/Model/ResourceModel/Product/Collection.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ public function setOrder($attribute, $dir = self::SORT_ORDER_DESC)
298298
}
299299

300300
/**
301-
* Add views count
301+
* Add views count.
302302
*
303303
* @param string $from
304304
* @param string $to
@@ -322,10 +322,7 @@ public function addViewsCount($from = '', $to = '')
322322
['views' => 'COUNT(report_table_views.event_id)']
323323
)->join(
324324
['e' => $this->getProductEntityTableName()],
325-
$this->getConnection()->quoteInto(
326-
'e.entity_id = report_table_views.object_id AND e.attribute_set_id = ?',
327-
$this->getProductAttributeSetId()
328-
)
325+
'e.entity_id = report_table_views.object_id'
329326
)->where(
330327
'report_table_views.event_type_id = ?',
331328
$productViewEvent
@@ -341,6 +338,7 @@ public function addViewsCount($from = '', $to = '')
341338
if ($from != '' && $to != '') {
342339
$this->getSelect()->where('logged_at >= ?', $from)->where('logged_at <= ?', $to);
343340
}
341+
344342
return $this;
345343
}
346344

0 commit comments

Comments
 (0)