Skip to content

Commit 81d518f

Browse files
authored
Merge pull request #54 from magento-epam/2.3-develop
Merge 2.3-develop to EPAM-PR-2
2 parents 80abb23 + 03ab0fd commit 81d518f

File tree

79 files changed

+1440
-460
lines changed

Some content is hidden

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

79 files changed

+1440
-460
lines changed

app/bootstrap.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,16 @@
5454
&& isset($_SERVER['HTTP_ACCEPT'])
5555
&& strpos($_SERVER['HTTP_ACCEPT'], 'text/html') !== false
5656
) {
57-
\Magento\Framework\Profiler::applyConfig(
58-
(isset($_SERVER['MAGE_PROFILER']) && strlen($_SERVER['MAGE_PROFILER'])) ? $_SERVER['MAGE_PROFILER'] : trim(file_get_contents(BP . '/var/profiler.flag')),
57+
$profilerConfig = isset($_SERVER['MAGE_PROFILER']) && strlen($_SERVER['MAGE_PROFILER'])
58+
? $_SERVER['MAGE_PROFILER']
59+
: trim(file_get_contents(BP . '/var/profiler.flag'));
60+
61+
if ($profilerConfig) {
62+
$profilerConfig = json_decode($profilerConfig, true) ?: $profilerConfig;
63+
}
64+
65+
Magento\Framework\Profiler::applyConfig(
66+
$profilerConfig,
5967
BP,
6068
!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest'
6169
);

app/code/Magento/AdminNotification/Observer/PredispatchAdminActionControllerObserver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function __construct(
3737
}
3838

3939
/**
40-
* Predispath admin action controller
40+
* Predispatch admin action controller
4141
*
4242
* @param \Magento\Framework\Event\Observer $observer
4343
* @return void

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,6 +3,8 @@
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
use Magento\Catalog\Model\ResourceModel\Product\Indexer\Eav\AbstractEav;
@@ -12,6 +14,11 @@
1214
*/
1315
abstract class AbstractAction
1416
{
17+
/**
18+
* Config path for enable EAV indexer
19+
*/
20+
const ENABLE_EAV_INDEXER = 'catalog/search/enable_eav_indexer';
21+
1522
/**
1623
* EAV Indexers by type
1724
*
@@ -29,17 +36,27 @@ abstract class AbstractAction
2936
*/
3037
protected $_eavDecimalFactory;
3138

39+
/**
40+
* @var \Magento\Framework\App\Config\ScopeConfigInterface
41+
*/
42+
private $scopeConfig;
43+
3244
/**
3345
* AbstractAction constructor.
3446
* @param \Magento\Catalog\Model\ResourceModel\Product\Indexer\Eav\DecimalFactory $eavDecimalFactory
3547
* @param \Magento\Catalog\Model\ResourceModel\Product\Indexer\Eav\SourceFactory $eavSourceFactory
48+
* @param \Magento\Framework\App\Config\ScopeConfigInterface|null $scopeConfig
3649
*/
3750
public function __construct(
3851
\Magento\Catalog\Model\ResourceModel\Product\Indexer\Eav\DecimalFactory $eavDecimalFactory,
39-
\Magento\Catalog\Model\ResourceModel\Product\Indexer\Eav\SourceFactory $eavSourceFactory
52+
\Magento\Catalog\Model\ResourceModel\Product\Indexer\Eav\SourceFactory $eavSourceFactory,
53+
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig = null
4054
) {
4155
$this->_eavDecimalFactory = $eavDecimalFactory;
4256
$this->_eavSourceFactory = $eavSourceFactory;
57+
$this->scopeConfig = $scopeConfig ?: \Magento\Framework\App\ObjectManager::getInstance()->get(
58+
\Magento\Framework\App\Config\ScopeConfigInterface::class
59+
);
4360
}
4461

4562
/**
@@ -92,6 +109,9 @@ public function getIndexer($type)
92109
*/
93110
public function reindex($ids = null)
94111
{
112+
if (!$this->isEavIndexerEnabled()) {
113+
return;
114+
}
95115
foreach ($this->getIndexers() as $indexer) {
96116
if ($ids === null) {
97117
$indexer->reindexAll();
@@ -149,4 +169,19 @@ protected function processRelations(AbstractEav $indexer, array $ids, bool $only
149169

150170
return array_unique(array_merge($ids, $childIds, $parentIds));
151171
}
172+
173+
/**
174+
* Get EAV indexer status
175+
*
176+
* @return bool
177+
*/
178+
private function isEavIndexerEnabled(): bool
179+
{
180+
$eavIndexerStatus = $this->scopeConfig->getValue(
181+
self::ENABLE_EAV_INDEXER,
182+
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
183+
);
184+
185+
return (bool)$eavIndexerStatus;
186+
}
152187
}

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
}

app/code/Magento/Catalog/Test/Unit/Model/Indexer/Product/Eav/AbstractActionTest.php

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@ class AbstractActionTest extends \PHPUnit\Framework\TestCase
2222
*/
2323
protected $_eavSourceFactoryMock;
2424

25+
/**
26+
* @var \Magento\Framework\App\Config\ScopeConfigInterface|\PHPUnit_Framework_MockObject_MockObject
27+
*/
28+
private $scopeConfig;
29+
30+
/**
31+
* @return void
32+
*/
2533
protected function setUp()
2634
{
2735
$this->_eavDecimalFactoryMock = $this->createPartialMock(
@@ -32,12 +40,22 @@ protected function setUp()
3240
\Magento\Catalog\Model\ResourceModel\Product\Indexer\Eav\SourceFactory::class,
3341
['create']
3442
);
43+
$this->scopeConfig = $this->getMockBuilder(\Magento\Framework\App\Config\ScopeConfigInterface::class)
44+
->disableOriginalConstructor()
45+
->getMockForAbstractClass();
3546
$this->_model = $this->getMockForAbstractClass(
3647
\Magento\Catalog\Model\Indexer\Product\Eav\AbstractAction::class,
37-
[$this->_eavDecimalFactoryMock, $this->_eavSourceFactoryMock, []]
48+
[
49+
$this->_eavDecimalFactoryMock,
50+
$this->_eavSourceFactoryMock,
51+
$this->scopeConfig
52+
]
3853
);
3954
}
4055

56+
/**
57+
* @return void
58+
*/
4159
public function testGetIndexers()
4260
{
4361
$expectedIndexers = [
@@ -73,6 +91,10 @@ public function testGetIndexerWithUnknownTypeThrowsException()
7391
$this->_model->getIndexer('unknown_type');
7492
}
7593

94+
/**
95+
* @return void
96+
* @throws \Magento\Framework\Exception\LocalizedException
97+
*/
7698
public function testGetIndexer()
7799
{
78100
$this->_eavSourceFactoryMock->expects($this->once())
@@ -86,6 +108,10 @@ public function testGetIndexer()
86108
$this->assertEquals('source_return_value', $this->_model->getIndexer('source'));
87109
}
88110

111+
/**
112+
* @return void
113+
* @throws \Exception
114+
*/
89115
public function testReindexWithoutArgumentsExecutesReindexAll()
90116
{
91117
$eavSource = $this->getMockBuilder(\Magento\Catalog\Model\ResourceModel\Product\Indexer\Eav\Source::class)
@@ -110,6 +136,10 @@ public function testReindexWithoutArgumentsExecutesReindexAll()
110136
->method('create')
111137
->will($this->returnValue($eavDecimal));
112138

139+
$this->scopeConfig->expects($this->once())
140+
->method('getValue')
141+
->willReturn(1);
142+
113143
$this->_model->reindex();
114144
}
115145

@@ -174,9 +204,25 @@ public function testReindexWithNotNullArgumentExecutesReindexEntities(
174204
->method('create')
175205
->will($this->returnValue($eavDecimal));
176206

207+
$this->scopeConfig->expects($this->once())
208+
->method('getValue')
209+
->willReturn(1);
210+
177211
$this->_model->reindex($ids);
178212
}
179213

214+
/**
215+
* @return void
216+
* @throws \Exception
217+
*/
218+
public function testReindexWithDisabledEavIndexer()
219+
{
220+
$this->scopeConfig->expects($this->once())->method('getValue')->willReturn(0);
221+
$this->_eavSourceFactoryMock->expects($this->never())->method('create');
222+
$this->_eavDecimalFactoryMock->expects($this->never())->method('create');
223+
$this->_model->reindex();
224+
}
225+
180226
/**
181227
* @return array
182228
*/

0 commit comments

Comments
 (0)