Skip to content

Commit

Permalink
Merge pull request #54 from magento-epam/2.3-develop
Browse files Browse the repository at this point in the history
Merge 2.3-develop to EPAM-PR-2
  • Loading branch information
nikshostko authored Aug 16, 2018
2 parents 80abb23 + 03ab0fd commit 81d518f
Show file tree
Hide file tree
Showing 79 changed files with 1,440 additions and 460 deletions.
12 changes: 10 additions & 2 deletions app/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,16 @@
&& isset($_SERVER['HTTP_ACCEPT'])
&& strpos($_SERVER['HTTP_ACCEPT'], 'text/html') !== false
) {
\Magento\Framework\Profiler::applyConfig(
(isset($_SERVER['MAGE_PROFILER']) && strlen($_SERVER['MAGE_PROFILER'])) ? $_SERVER['MAGE_PROFILER'] : trim(file_get_contents(BP . '/var/profiler.flag')),
$profilerConfig = isset($_SERVER['MAGE_PROFILER']) && strlen($_SERVER['MAGE_PROFILER'])
? $_SERVER['MAGE_PROFILER']
: trim(file_get_contents(BP . '/var/profiler.flag'));

if ($profilerConfig) {
$profilerConfig = json_decode($profilerConfig, true) ?: $profilerConfig;
}

Magento\Framework\Profiler::applyConfig(
$profilerConfig,
BP,
!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest'
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function __construct(
}

/**
* Predispath admin action controller
* Predispatch admin action controller
*
* @param \Magento\Framework\Event\Observer $observer
* @return void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Catalog\Model\Indexer\Product\Eav;

use Magento\Catalog\Model\ResourceModel\Product\Indexer\Eav\AbstractEav;
Expand All @@ -12,6 +14,11 @@
*/
abstract class AbstractAction
{
/**
* Config path for enable EAV indexer
*/
const ENABLE_EAV_INDEXER = 'catalog/search/enable_eav_indexer';

/**
* EAV Indexers by type
*
Expand All @@ -29,17 +36,27 @@ abstract class AbstractAction
*/
protected $_eavDecimalFactory;

/**
* @var \Magento\Framework\App\Config\ScopeConfigInterface
*/
private $scopeConfig;

/**
* AbstractAction constructor.
* @param \Magento\Catalog\Model\ResourceModel\Product\Indexer\Eav\DecimalFactory $eavDecimalFactory
* @param \Magento\Catalog\Model\ResourceModel\Product\Indexer\Eav\SourceFactory $eavSourceFactory
* @param \Magento\Framework\App\Config\ScopeConfigInterface|null $scopeConfig
*/
public function __construct(
\Magento\Catalog\Model\ResourceModel\Product\Indexer\Eav\DecimalFactory $eavDecimalFactory,
\Magento\Catalog\Model\ResourceModel\Product\Indexer\Eav\SourceFactory $eavSourceFactory
\Magento\Catalog\Model\ResourceModel\Product\Indexer\Eav\SourceFactory $eavSourceFactory,
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig = null
) {
$this->_eavDecimalFactory = $eavDecimalFactory;
$this->_eavSourceFactory = $eavSourceFactory;
$this->scopeConfig = $scopeConfig ?: \Magento\Framework\App\ObjectManager::getInstance()->get(
\Magento\Framework\App\Config\ScopeConfigInterface::class
);
}

/**
Expand Down Expand Up @@ -92,6 +109,9 @@ public function getIndexer($type)
*/
public function reindex($ids = null)
{
if (!$this->isEavIndexerEnabled()) {
return;
}
foreach ($this->getIndexers() as $indexer) {
if ($ids === null) {
$indexer->reindexAll();
Expand Down Expand Up @@ -149,4 +169,19 @@ protected function processRelations(AbstractEav $indexer, array $ids, bool $only

return array_unique(array_merge($ids, $childIds, $parentIds));
}

/**
* Get EAV indexer status
*
* @return bool
*/
private function isEavIndexerEnabled(): bool
{
$eavIndexerStatus = $this->scopeConfig->getValue(
self::ENABLE_EAV_INDEXER,
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
);

return (bool)$eavIndexerStatus;
}
}
35 changes: 33 additions & 2 deletions app/code/Magento/Catalog/Model/Indexer/Product/Eav/Action/Full.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Catalog\Model\Indexer\Product\Eav\Action;

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

/**
* Class Full reindex action
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class Full extends \Magento\Catalog\Model\Indexer\Product\Eav\AbstractAction
{
Expand All @@ -32,23 +35,33 @@ class Full extends \Magento\Catalog\Model\Indexer\Product\Eav\AbstractAction
*/
private $activeTableSwitcher;

/**
* @var \Magento\Framework\App\Config\ScopeConfigInterface
*/
private $scopeConfig;

/**
* @param \Magento\Catalog\Model\ResourceModel\Product\Indexer\Eav\DecimalFactory $eavDecimalFactory
* @param \Magento\Catalog\Model\ResourceModel\Product\Indexer\Eav\SourceFactory $eavSourceFactory
* @param \Magento\Framework\EntityManager\MetadataPool|null $metadataPool
* @param \Magento\Framework\Indexer\BatchProviderInterface|null $batchProvider
* @param \Magento\Catalog\Model\ResourceModel\Product\Indexer\Eav\BatchSizeCalculator $batchSizeCalculator
* @param ActiveTableSwitcher|null $activeTableSwitcher
* @param \Magento\Framework\App\Config\ScopeConfigInterface|null $scopeConfig
*/
public function __construct(
\Magento\Catalog\Model\ResourceModel\Product\Indexer\Eav\DecimalFactory $eavDecimalFactory,
\Magento\Catalog\Model\ResourceModel\Product\Indexer\Eav\SourceFactory $eavSourceFactory,
\Magento\Framework\EntityManager\MetadataPool $metadataPool = null,
\Magento\Framework\Indexer\BatchProviderInterface $batchProvider = null,
\Magento\Catalog\Model\ResourceModel\Product\Indexer\Eav\BatchSizeCalculator $batchSizeCalculator = null,
ActiveTableSwitcher $activeTableSwitcher = null
ActiveTableSwitcher $activeTableSwitcher = null,
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig = null
) {
parent::__construct($eavDecimalFactory, $eavSourceFactory);
$this->scopeConfig = $scopeConfig ?: \Magento\Framework\App\ObjectManager::getInstance()->get(
\Magento\Framework\App\Config\ScopeConfigInterface::class
);
parent::__construct($eavDecimalFactory, $eavSourceFactory, $scopeConfig);
$this->metadataPool = $metadataPool ?: \Magento\Framework\App\ObjectManager::getInstance()->get(
\Magento\Framework\EntityManager\MetadataPool::class
);
Expand All @@ -73,6 +86,9 @@ public function __construct(
*/
public function execute($ids = null)
{
if (!$this->isEavIndexerEnabled()) {
return;
}
try {
foreach ($this->getIndexers() as $indexerName => $indexer) {
$connection = $indexer->getConnection();
Expand Down Expand Up @@ -129,4 +145,19 @@ protected function syncData($indexer, $destinationTable, $ids = null)
throw $e;
}
}

/**
* Get EAV indexer status
*
* @return bool
*/
private function isEavIndexerEnabled(): bool
{
$eavIndexerStatus = $this->scopeConfig->getValue(
self::ENABLE_EAV_INDEXER,
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
);

return (bool)$eavIndexerStatus;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ class AbstractActionTest extends \PHPUnit\Framework\TestCase
*/
protected $_eavSourceFactoryMock;

/**
* @var \Magento\Framework\App\Config\ScopeConfigInterface|\PHPUnit_Framework_MockObject_MockObject
*/
private $scopeConfig;

/**
* @return void
*/
protected function setUp()
{
$this->_eavDecimalFactoryMock = $this->createPartialMock(
Expand All @@ -32,12 +40,22 @@ protected function setUp()
\Magento\Catalog\Model\ResourceModel\Product\Indexer\Eav\SourceFactory::class,
['create']
);
$this->scopeConfig = $this->getMockBuilder(\Magento\Framework\App\Config\ScopeConfigInterface::class)
->disableOriginalConstructor()
->getMockForAbstractClass();
$this->_model = $this->getMockForAbstractClass(
\Magento\Catalog\Model\Indexer\Product\Eav\AbstractAction::class,
[$this->_eavDecimalFactoryMock, $this->_eavSourceFactoryMock, []]
[
$this->_eavDecimalFactoryMock,
$this->_eavSourceFactoryMock,
$this->scopeConfig
]
);
}

/**
* @return void
*/
public function testGetIndexers()
{
$expectedIndexers = [
Expand Down Expand Up @@ -73,6 +91,10 @@ public function testGetIndexerWithUnknownTypeThrowsException()
$this->_model->getIndexer('unknown_type');
}

/**
* @return void
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function testGetIndexer()
{
$this->_eavSourceFactoryMock->expects($this->once())
Expand All @@ -86,6 +108,10 @@ public function testGetIndexer()
$this->assertEquals('source_return_value', $this->_model->getIndexer('source'));
}

/**
* @return void
* @throws \Exception
*/
public function testReindexWithoutArgumentsExecutesReindexAll()
{
$eavSource = $this->getMockBuilder(\Magento\Catalog\Model\ResourceModel\Product\Indexer\Eav\Source::class)
Expand All @@ -110,6 +136,10 @@ public function testReindexWithoutArgumentsExecutesReindexAll()
->method('create')
->will($this->returnValue($eavDecimal));

$this->scopeConfig->expects($this->once())
->method('getValue')
->willReturn(1);

$this->_model->reindex();
}

Expand Down Expand Up @@ -174,9 +204,25 @@ public function testReindexWithNotNullArgumentExecutesReindexEntities(
->method('create')
->will($this->returnValue($eavDecimal));

$this->scopeConfig->expects($this->once())
->method('getValue')
->willReturn(1);

$this->_model->reindex($ids);
}

/**
* @return void
* @throws \Exception
*/
public function testReindexWithDisabledEavIndexer()
{
$this->scopeConfig->expects($this->once())->method('getValue')->willReturn(0);
$this->_eavSourceFactoryMock->expects($this->never())->method('create');
$this->_eavDecimalFactoryMock->expects($this->never())->method('create');
$this->_model->reindex();
}

/**
* @return array
*/
Expand Down
Loading

0 comments on commit 81d518f

Please sign in to comment.