Skip to content

Commit 270db19

Browse files
author
Oleksii Korshenko
committed
MAGETWO-87058: [EngCom Team] Batch 6. Forwardports to 2.3-develop #1287
- Merge Pull Request magento-engcom/magento2ce#1287 from magento-engcom-team/magento2:batch-6-forwardport-2.3-develop - Merged commits: 1. 7734bd1 2. d96327d 3. 8c735e5 4. 1a11319 5. 3011b5e 6. 850e38c 7. 24dcb91 8. c574e46 9. 8161593 10. f06e173 11. 66f9593 12. d59be58 13. 11f6dc4 14. 4fe19c1 15. 3d085f5 16. d28ddba 17. dcfa68c 18. ff33a1b 19. df7ef2b 20. 2c7a113 21. 596e260
2 parents 8e77e2f + 596e260 commit 270db19

File tree

23 files changed

+356
-55
lines changed

23 files changed

+356
-55
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
@@ -1298,20 +1297,15 @@ protected function _saveLinks()
12981297
*/
12991298
protected function _saveProductAttributes(array $attributesData)
13001299
{
1300+
$linkField = $this->getProductEntityLinkField();
13011301
foreach ($attributesData as $tableName => $skuData) {
13021302
$tableData = [];
13031303
foreach ($skuData as $sku => $attributes) {
1304-
$linkId = $this->_connection->fetchOne(
1305-
$this->_connection->select()
1306-
->from($this->getResource()->getTable('catalog_product_entity'))
1307-
->where('sku = ?', (string)$sku)
1308-
->columns($this->getProductEntityLinkField())
1309-
);
1310-
1304+
$linkId = $this->_oldSku[strtolower($sku)][$linkField];
13111305
foreach ($attributes as $attributeId => $storeValues) {
13121306
foreach ($storeValues as $storeId => $storeValue) {
13131307
$tableData[] = [
1314-
$this->getProductEntityLinkField() => $linkId,
1308+
$linkField => $linkId,
13151309
'attribute_id' => $attributeId,
13161310
'store_id' => $storeId,
13171311
'value' => $storeValue,
@@ -1321,6 +1315,7 @@ protected function _saveProductAttributes(array $attributesData)
13211315
}
13221316
$this->_connection->insertOnDuplicate($tableName, $tableData, ['value']);
13231317
}
1318+
13241319
return $this;
13251320
}
13261321

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/ConfigurableProduct/Model/Product/Type/Configurable.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1296,7 +1296,7 @@ private function loadUsedProducts(\Magento\Catalog\Model\Product $product, $cach
12961296
if ($salableOnly) {
12971297
$collection = $this->salableProcessor->process($collection);
12981298
}
1299-
$usedProducts = $collection->getItems();
1299+
$usedProducts = array_values($collection->getItems());
13001300
$this->saveUsedProductsCacheData($product, $usedProducts, $cacheKey);
13011301
}
13021302
$product->setData($dataFieldName, $usedProducts);

app/code/Magento/CustomerImportExport/Model/Import/Customer.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,13 +270,29 @@ protected function _saveCustomerEntities(array $entitiesToCreate, array $entitie
270270
$this->_connection->insertOnDuplicate(
271271
$this->_entityTable,
272272
$entitiesToUpdate,
273-
$this->customerFields
273+
$this->getCustomerEntityFieldsToUpdate($entitiesToUpdate)
274274
);
275275
}
276276

277277
return $this;
278278
}
279279

280+
/**
281+
* Filter the entity that are being updated so we only change fields found in the importer file
282+
*
283+
* @param array $entitiesToUpdate
284+
* @return array
285+
*/
286+
private function getCustomerEntityFieldsToUpdate(array $entitiesToUpdate): array
287+
{
288+
$firstCustomer = reset($entitiesToUpdate);
289+
$columnsToUpdate = array_keys($firstCustomer);
290+
$customerFieldsToUpdate = array_filter($this->customerFields, function ($field) use ($columnsToUpdate) {
291+
return in_array($field, $columnsToUpdate);
292+
});
293+
return $customerFieldsToUpdate;
294+
}
295+
280296
/**
281297
* Save customer attributes.
282298
*

app/code/Magento/NewRelicReporting/Model/NewRelicWrapper.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,19 @@ public function addCustomParameter($param, $value)
2828
return false;
2929
}
3030

31+
/**
32+
* Wrapper for 'newrelic_notice_error' function
33+
*
34+
* @param Exception $exception
35+
* @return void
36+
*/
37+
public function reportError($exception)
38+
{
39+
if (extension_loaded('newrelic')) {
40+
newrelic_notice_error($exception->getMessage(), $exception);
41+
}
42+
}
43+
3144
/**
3245
* Checks whether newrelic-php5 agent is installed
3346
*
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\NewRelicReporting\Model\Observer;
7+
8+
use Magento\Framework\Event\Observer;
9+
use Magento\Framework\Event\ObserverInterface;
10+
use Magento\NewRelicReporting\Model\Config;
11+
use Magento\NewRelicReporting\Model\NewRelicWrapper;
12+
13+
/**
14+
* Class ReportApplicationHandledExceptionToNewRelic
15+
*/
16+
class ReportApplicationHandledExceptionToNewRelic implements ObserverInterface
17+
{
18+
/**
19+
* @var Config
20+
*/
21+
private $config;
22+
23+
/**
24+
* @var NewRelicWrapper
25+
*/
26+
private $newRelicWrapper;
27+
28+
/**
29+
* @param Config $config
30+
* @param NewRelicWrapper $newRelicWrapper
31+
*/
32+
public function __construct(
33+
Config $config,
34+
NewRelicWrapper $newRelicWrapper
35+
) {
36+
$this->config = $config;
37+
$this->newRelicWrapper = $newRelicWrapper;
38+
}
39+
40+
public function execute(Observer $observer)
41+
{
42+
if ($this->config->isNewRelicEnabled()) {
43+
$exception = $observer->getEvent()->getException();
44+
$this->newRelicWrapper->reportError($exception);
45+
}
46+
}
47+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\NewRelicReporting\Plugin;
7+
8+
use Magento\Framework\App\Bootstrap;
9+
use Magento\Framework\App\Http;
10+
use Magento\NewRelicReporting\Model\Config;
11+
use Magento\NewRelicReporting\Model\NewRelicWrapper;
12+
13+
class HttpPlugin
14+
{
15+
/**
16+
* @var Config
17+
*/
18+
private $config;
19+
20+
/**
21+
* @var NewRelicWrapper
22+
*/
23+
private $newRelicWrapper;
24+
25+
/**
26+
* @param Config $config
27+
* @param NewRelicWrapper $newRelicWrapper
28+
*/
29+
public function __construct(
30+
Config $config,
31+
NewRelicWrapper $newRelicWrapper
32+
) {
33+
$this->config = $config;
34+
$this->newRelicWrapper = $newRelicWrapper;
35+
}
36+
37+
/**
38+
* Report exception to New Relic
39+
*
40+
* @param Http $subject
41+
* @param Bootstrap $bootstrap
42+
* @param \Exception $exception
43+
* @return void
44+
*
45+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
46+
*/
47+
public function beforeCatchException(Http $subject, Bootstrap $bootstrap, \Exception $exception)
48+
{
49+
if ($this->config->isNewRelicEnabled()) {
50+
$this->newRelicWrapper->reportError($exception);
51+
}
52+
}
53+
}

app/code/Magento/NewRelicReporting/etc/di.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,7 @@
2727
</argument>
2828
</arguments>
2929
</type>
30+
<type name="Magento\Framework\App\Http">
31+
<plugin name="framework-http-newrelic" type="Magento\NewRelicReporting\Plugin\HttpPlugin"/>
32+
</type>
3033
</config>

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/Quote/Item/Collection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ protected function getProductData(array $productIds)
192192
. ' AND product_name.attribute_id = ' . $productAttrNameId
193193
. ' AND product_name.store_id = ' . \Magento\Store\Model\Store::DEFAULT_STORE_ID,
194194
['name' => 'product_name.value']
195-
)->joinInner(
195+
)->joinLeft(
196196
['product_price' => $productAttrPrice->getBackend()->getTable()],
197197
"product_price.{$linkField} = main_table.{$linkField}"
198198
." AND product_price.attribute_id = {$productAttrPriceId}",
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Reports\Test\Unit\Block\Adminhtml\Grid;
8+
9+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
10+
11+
/**
12+
* Test for class \Magento\Reports\Block\Adminhtml\Grid\AbstractGrid.
13+
*/
14+
class AbstractGridTest extends \PHPUnit\Framework\TestCase
15+
{
16+
/**
17+
* @var \Magento\Reports\Block\Adminhtml\Grid\AbstractGrid|\PHPUnit_Framework_MockObject_MockObject
18+
*/
19+
private $model;
20+
21+
/**
22+
* @var \Magento\Store\Model\StoreManagerInterface|\PHPUnit_Framework_MockObject_MockObject
23+
*/
24+
private $storeManagerMock;
25+
26+
protected function setUp()
27+
{
28+
$objectManager = new ObjectManager($this);
29+
30+
$this->storeManagerMock = $this->getMockForAbstractClass(
31+
\Magento\Store\Model\StoreManagerInterface::class,
32+
[],
33+
'',
34+
true,
35+
true,
36+
true,
37+
['getStore']
38+
);
39+
40+
$this->model = $objectManager->getObject(
41+
\Magento\Reports\Block\Adminhtml\Grid\AbstractGrid::class,
42+
['_storeManager' => $this->storeManagerMock]
43+
);
44+
}
45+
46+
/**
47+
* @param $storeIds
48+
*
49+
* @dataProvider getCurrentCurrencyCodeDataProvider
50+
*/
51+
public function testGetCurrentCurrencyCode($storeIds)
52+
{
53+
$storeMock = $this->getMockForAbstractClass(
54+
\Magento\Store\Api\Data\StoreInterface::class,
55+
[],
56+
'',
57+
true,
58+
true,
59+
true,
60+
['getBaseCurrencyCode', 'getCurrentCurrencyCode']
61+
);
62+
63+
$this->storeManagerMock->expects($this->once())->method('getStore')->willReturn($storeMock);
64+
65+
$this->model->setStoreIds($storeIds);
66+
67+
if ($storeIds) {
68+
$storeMock->expects($this->once())->method('getCurrentCurrencyCode')->willReturn('EUR');
69+
$expectedCurrencyCode = 'EUR';
70+
} else {
71+
$storeMock->expects($this->once())->method('getBaseCurrencyCode')->willReturn('USD');
72+
$expectedCurrencyCode = 'USD';
73+
}
74+
75+
$currencyCode = $this->model->getCurrentCurrencyCode();
76+
$this->assertEquals($expectedCurrencyCode, $currencyCode);
77+
}
78+
79+
/**
80+
* DataProvider for testGetCurrentCurrencyCode.
81+
*
82+
* @return array
83+
*/
84+
public function getCurrentCurrencyCodeDataProvider()
85+
{
86+
return [
87+
[[]],
88+
[[2]],
89+
];
90+
}
91+
}

0 commit comments

Comments
 (0)