Skip to content

Commit 85c1d4a

Browse files
committed
Merge remote-tracking branch 'origin/2.2-develop' into 2.2-develop-pr40
2 parents 7559c68 + 33d39af commit 85c1d4a

File tree

48 files changed

+561
-203
lines changed

Some content is hidden

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

48 files changed

+561
-203
lines changed

app/bootstrap.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,16 @@
5454
&& isset($_SERVER['HTTP_ACCEPT'])
5555
&& strpos($_SERVER['HTTP_ACCEPT'], 'text/html') !== false
5656
) {
57-
$profilerFlag = isset($_SERVER['MAGE_PROFILER']) && strlen($_SERVER['MAGE_PROFILER'])
57+
$profilerConfig = isset($_SERVER['MAGE_PROFILER']) && strlen($_SERVER['MAGE_PROFILER'])
5858
? $_SERVER['MAGE_PROFILER']
5959
: trim(file_get_contents(BP . '/var/profiler.flag'));
6060

61-
\Magento\Framework\Profiler::applyConfig(
62-
$profilerFlag,
61+
if ($profilerConfig) {
62+
$profilerConfig = json_decode($profilerConfig, true) ?: $profilerConfig;
63+
}
64+
65+
Magento\Framework\Profiler::applyConfig(
66+
$profilerConfig,
6367
BP,
6468
!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest'
6569
);

app/code/Magento/Catalog/Model/Indexer/Product/Eav/AbstractAction.php

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,20 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
7+
68
namespace Magento\Catalog\Model\Indexer\Product\Eav;
79

810
/**
911
* Abstract action reindex class
1012
*/
1113
abstract class AbstractAction
1214
{
15+
/**
16+
* Config path for enable EAV indexer
17+
*/
18+
const ENABLE_EAV_INDEXER = 'catalog/search/enable_eav_indexer';
19+
1320
/**
1421
* EAV Indexers by type
1522
*
@@ -27,17 +34,27 @@ abstract class AbstractAction
2734
*/
2835
protected $_eavDecimalFactory;
2936

37+
/**
38+
* @var \Magento\Framework\App\Config\ScopeConfigInterface
39+
*/
40+
private $scopeConfig;
41+
3042
/**
3143
* AbstractAction constructor.
3244
* @param \Magento\Catalog\Model\ResourceModel\Product\Indexer\Eav\DecimalFactory $eavDecimalFactory
3345
* @param \Magento\Catalog\Model\ResourceModel\Product\Indexer\Eav\SourceFactory $eavSourceFactory
46+
* @param \Magento\Framework\App\Config\ScopeConfigInterface|null $scopeConfig
3447
*/
3548
public function __construct(
3649
\Magento\Catalog\Model\ResourceModel\Product\Indexer\Eav\DecimalFactory $eavDecimalFactory,
37-
\Magento\Catalog\Model\ResourceModel\Product\Indexer\Eav\SourceFactory $eavSourceFactory
50+
\Magento\Catalog\Model\ResourceModel\Product\Indexer\Eav\SourceFactory $eavSourceFactory,
51+
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig = null
3852
) {
3953
$this->_eavDecimalFactory = $eavDecimalFactory;
4054
$this->_eavSourceFactory = $eavSourceFactory;
55+
$this->scopeConfig = $scopeConfig ?: \Magento\Framework\App\ObjectManager::getInstance()->get(
56+
\Magento\Framework\App\Config\ScopeConfigInterface::class
57+
);
4158
}
4259

4360
/**
@@ -90,6 +107,9 @@ public function getIndexer($type)
90107
*/
91108
public function reindex($ids = null)
92109
{
110+
if (!$this->isEavIndexerEnabled()) {
111+
return;
112+
}
93113
foreach ($this->getIndexers() as $indexer) {
94114
if ($ids === null) {
95115
$indexer->reindexAll();
@@ -147,4 +167,19 @@ protected function processRelations($indexer, $ids, $onlyParents = false)
147167
$childIds = $onlyParents ? [] : $indexer->getRelationsByParent($parentIds);
148168
return array_unique(array_merge($ids, $childIds, $parentIds));
149169
}
170+
171+
/**
172+
* Get EAV indexer status
173+
*
174+
* @return bool
175+
*/
176+
private function isEavIndexerEnabled(): bool
177+
{
178+
$eavIndexerStatus = $this->scopeConfig->getValue(
179+
self::ENABLE_EAV_INDEXER,
180+
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
181+
);
182+
183+
return (bool)$eavIndexerStatus;
184+
}
150185
}

app/code/Magento/Catalog/Model/Indexer/Product/Eav/Action/Full.php

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,15 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
7+
68
namespace Magento\Catalog\Model\Indexer\Product\Eav\Action;
79

810
use Magento\Catalog\Model\ResourceModel\Indexer\ActiveTableSwitcher;
911

1012
/**
1113
* Class Full reindex action
14+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1215
*/
1316
class Full extends \Magento\Catalog\Model\Indexer\Product\Eav\AbstractAction
1417
{
@@ -32,23 +35,33 @@ class Full extends \Magento\Catalog\Model\Indexer\Product\Eav\AbstractAction
3235
*/
3336
private $activeTableSwitcher;
3437

38+
/**
39+
* @var \Magento\Framework\App\Config\ScopeConfigInterface
40+
*/
41+
private $scopeConfig;
42+
3543
/**
3644
* @param \Magento\Catalog\Model\ResourceModel\Product\Indexer\Eav\DecimalFactory $eavDecimalFactory
3745
* @param \Magento\Catalog\Model\ResourceModel\Product\Indexer\Eav\SourceFactory $eavSourceFactory
3846
* @param \Magento\Framework\EntityManager\MetadataPool|null $metadataPool
3947
* @param \Magento\Framework\Indexer\BatchProviderInterface|null $batchProvider
4048
* @param \Magento\Catalog\Model\ResourceModel\Product\Indexer\Eav\BatchSizeCalculator $batchSizeCalculator
4149
* @param ActiveTableSwitcher|null $activeTableSwitcher
50+
* @param \Magento\Framework\App\Config\ScopeConfigInterface|null $scopeConfig
4251
*/
4352
public function __construct(
4453
\Magento\Catalog\Model\ResourceModel\Product\Indexer\Eav\DecimalFactory $eavDecimalFactory,
4554
\Magento\Catalog\Model\ResourceModel\Product\Indexer\Eav\SourceFactory $eavSourceFactory,
4655
\Magento\Framework\EntityManager\MetadataPool $metadataPool = null,
4756
\Magento\Framework\Indexer\BatchProviderInterface $batchProvider = null,
4857
\Magento\Catalog\Model\ResourceModel\Product\Indexer\Eav\BatchSizeCalculator $batchSizeCalculator = null,
49-
ActiveTableSwitcher $activeTableSwitcher = null
58+
ActiveTableSwitcher $activeTableSwitcher = null,
59+
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig = null
5060
) {
51-
parent::__construct($eavDecimalFactory, $eavSourceFactory);
61+
$this->scopeConfig = $scopeConfig ?: \Magento\Framework\App\ObjectManager::getInstance()->get(
62+
\Magento\Framework\App\Config\ScopeConfigInterface::class
63+
);
64+
parent::__construct($eavDecimalFactory, $eavSourceFactory, $scopeConfig);
5265
$this->metadataPool = $metadataPool ?: \Magento\Framework\App\ObjectManager::getInstance()->get(
5366
\Magento\Framework\EntityManager\MetadataPool::class
5467
);
@@ -73,6 +86,9 @@ public function __construct(
7386
*/
7487
public function execute($ids = null)
7588
{
89+
if (!$this->isEavIndexerEnabled()) {
90+
return;
91+
}
7692
try {
7793
foreach ($this->getIndexers() as $indexerName => $indexer) {
7894
$connection = $indexer->getConnection();
@@ -129,4 +145,19 @@ protected function syncData($indexer, $destinationTable, $ids = null)
129145
throw $e;
130146
}
131147
}
148+
149+
/**
150+
* Get EAV indexer status
151+
*
152+
* @return bool
153+
*/
154+
private function isEavIndexerEnabled(): bool
155+
{
156+
$eavIndexerStatus = $this->scopeConfig->getValue(
157+
self::ENABLE_EAV_INDEXER,
158+
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
159+
);
160+
161+
return (bool)$eavIndexerStatus;
162+
}
132163
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Catalog\Test\Unit\Cron;
9+
10+
use Magento\Catalog\Cron\DeleteAbandonedStoreFlatTables;
11+
use Magento\Catalog\Helper\Product\Flat\Indexer;
12+
13+
/**
14+
* @covers \Magento\Catalog\Cron\DeleteAbandonedStoreFlatTables
15+
*/
16+
class DeleteAbandonedStoreFlatTablesTest extends \PHPUnit\Framework\TestCase
17+
{
18+
/**
19+
* Testable Object
20+
*
21+
* @var DeleteAbandonedStoreFlatTables
22+
*/
23+
private $deleteAbandonedStoreFlatTables;
24+
25+
/**
26+
* @var Indexer|\PHPUnit_Framework_MockObject_MockObject
27+
*/
28+
private $indexerMock;
29+
30+
/**
31+
* Set Up
32+
*
33+
* @return void
34+
*/
35+
protected function setUp()
36+
{
37+
$this->indexerMock = $this->createMock(Indexer::class);
38+
$this->deleteAbandonedStoreFlatTables = new DeleteAbandonedStoreFlatTables($this->indexerMock);
39+
}
40+
41+
/**
42+
* Test execute method
43+
*
44+
* @return void
45+
*/
46+
public function testExecute()
47+
{
48+
$this->indexerMock->expects($this->once())->method('deleteAbandonedStoreFlatTables');
49+
$this->deleteAbandonedStoreFlatTables->execute();
50+
}
51+
}
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Catalog\Test\Unit\Cron;
9+
10+
use Magento\Catalog\Api\Data\ProductAttributeInterface;
11+
use Magento\Catalog\Cron\DeleteOutdatedPriceValues;
12+
use Magento\Eav\Api\AttributeRepositoryInterface as AttributeRepository;
13+
use Magento\Eav\Model\Entity\Attribute;
14+
use Magento\Eav\Model\Entity\Attribute\Backend\BackendInterface;
15+
use Magento\Framework\App\Config\MutableScopeConfigInterface as ScopeConfig;
16+
use Magento\Framework\App\ResourceConnection;
17+
use Magento\Framework\DB\Adapter\AdapterInterface;
18+
use Magento\Store\Model\Store;
19+
20+
/**
21+
* @covers \Magento\Catalog\Cron\DeleteOutdatedPriceValues
22+
*/
23+
class DeleteOutdatedPriceValuesTest extends \PHPUnit\Framework\TestCase
24+
{
25+
/**
26+
* Testable Object
27+
*
28+
* @var DeleteOutdatedPriceValues
29+
*/
30+
private $deleteOutdatedPriceValues;
31+
32+
/**
33+
* @var AttributeRepository|\PHPUnit_Framework_MockObject_MockObject
34+
*/
35+
private $attributeRepositoryMock;
36+
37+
/**
38+
* @var ResourceConnection|\PHPUnit_Framework_MockObject_MockObject
39+
*/
40+
private $resourceConnectionMock;
41+
42+
/**
43+
* @var ScopeConfig|\PHPUnit_Framework_MockObject_MockObject
44+
*/
45+
private $scopeConfigMock;
46+
47+
/**
48+
* @var Attribute|\PHPUnit_Framework_MockObject_MockObject
49+
*/
50+
private $attributeMock;
51+
52+
/**
53+
* @var AdapterInterface|\PHPUnit_Framework_MockObject_MockObject
54+
*/
55+
private $dbAdapterMock;
56+
57+
/**
58+
* @var BackendInterface|\PHPUnit_Framework_MockObject_MockObject
59+
*/
60+
private $attributeBackendMock;
61+
62+
/**
63+
* Set Up
64+
*
65+
* @return void
66+
*/
67+
protected function setUp()
68+
{
69+
$this->resourceConnectionMock = $this->createMock(ResourceConnection::class);
70+
$this->attributeRepositoryMock = $this->createMock(AttributeRepository::class);
71+
$this->attributeMock = $this->createMock(Attribute::class);
72+
$this->scopeConfigMock = $this->createMock(ScopeConfig::class);
73+
$this->dbAdapterMock = $this->createMock(AdapterInterface::class);
74+
$this->attributeBackendMock = $this->createMock(BackendInterface::class);
75+
$this->deleteOutdatedPriceValues = new DeleteOutdatedPriceValues(
76+
$this->resourceConnectionMock,
77+
$this->attributeRepositoryMock,
78+
$this->scopeConfigMock
79+
);
80+
}
81+
82+
/**
83+
* Test execute method
84+
*
85+
* @return void
86+
*/
87+
public function testExecute()
88+
{
89+
$table = 'catalog_product_entity_decimal';
90+
$attributeId = 15;
91+
$conditions = ['first', 'second'];
92+
93+
$this->scopeConfigMock->expects($this->once())->method('getValue')->with(Store::XML_PATH_PRICE_SCOPE)
94+
->willReturn(Store::XML_PATH_PRICE_SCOPE);
95+
$this->attributeRepositoryMock->expects($this->once())->method('get')
96+
->with(ProductAttributeInterface::ENTITY_TYPE_CODE, ProductAttributeInterface::CODE_PRICE)
97+
->willReturn($this->attributeMock);
98+
$this->attributeMock->expects($this->once())->method('getId')->willReturn($attributeId);
99+
$this->attributeMock->expects($this->once())->method('getBackend')->willReturn($this->attributeBackendMock);
100+
$this->attributeBackendMock->expects($this->once())->method('getTable')->willReturn($table);
101+
$this->resourceConnectionMock->expects($this->once())
102+
->method('getConnection')
103+
->willReturn($this->dbAdapterMock);
104+
$this->dbAdapterMock->expects($this->exactly(2))->method('quoteInto')->willReturnMap([
105+
['attribute_id = ?', $attributeId, null, null, $conditions[0]],
106+
['store_id != ?', Store::DEFAULT_STORE_ID, null, null, $conditions[1]],
107+
]);
108+
$this->dbAdapterMock->expects($this->once())->method('delete')->with($table, $conditions);
109+
$this->deleteOutdatedPriceValues->execute();
110+
}
111+
112+
/**
113+
* Test execute method
114+
* The price scope config option is not equal to global value
115+
*
116+
* @return void
117+
*/
118+
public function testExecutePriceConfigIsNotSetToGlobal()
119+
{
120+
$this->scopeConfigMock->expects($this->once())->method('getValue')->with(Store::XML_PATH_PRICE_SCOPE)
121+
->willReturn(null);
122+
$this->attributeRepositoryMock->expects($this->never())->method('get');
123+
$this->dbAdapterMock->expects($this->never())->method('delete');
124+
125+
$this->deleteOutdatedPriceValues->execute();
126+
}
127+
}

0 commit comments

Comments
 (0)