Skip to content

Commit 0928000

Browse files
author
Andrii Kasian
committed
Merge remote-tracking branch 'origin/MAGETWO-38814' into S70pr
2 parents 11452b8 + a609685 commit 0928000

File tree

13 files changed

+108
-245
lines changed

13 files changed

+108
-245
lines changed

app/code/Magento/CatalogSearch/Model/Indexer/Fulltext.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class Fulltext implements \Magento\Indexer\Model\ActionInterface, \Magento\Frame
4747
private $searchRequestConfig;
4848

4949
/**
50-
* @param Full $fullAction
50+
* @param FullFactory $fullActionFactory
5151
* @param IndexerHandlerFactory $indexerHandlerFactory
5252
* @param StoreManagerInterface $storeManager
5353
* @param DimensionFactory $dimensionFactory

app/code/Magento/CatalogSearch/Model/Indexer/Fulltext/Action/Full.php

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
*/
66
namespace Magento\CatalogSearch\Model\Indexer\Fulltext\Action;
77

8+
use Magento\CatalogSearch\Model\Indexer\Fulltext;
9+
810
/**
911
* @SuppressWarnings(PHPMD.TooManyFields)
1012
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
@@ -99,9 +101,14 @@ class Full
99101
protected $storeManager;
100102

101103
/**
102-
* @var \Magento\CatalogSearch\Model\Resource\EngineProvider
104+
* @var \Magento\CatalogSearch\Model\Resource\Engine
103105
*/
104-
protected $engineProvider;
106+
protected $engine;
107+
108+
/**
109+
* @var \Magento\Framework\IndexerInterface
110+
*/
111+
protected $indexHandler;
105112

106113
/**
107114
* @var \Magento\Framework\Stdlib\DateTime
@@ -146,6 +153,7 @@ class Full
146153
* @param \Magento\Catalog\Model\Product\Attribute\Source\Status $catalogProductStatus
147154
* @param \Magento\Catalog\Model\Resource\Product\Attribute\CollectionFactory $productAttributeCollectionFactory
148155
* @param \Magento\CatalogSearch\Model\Resource\EngineProvider $engineProvider
156+
* @param \Magento\CatalogSearch\Model\Indexer\IndexerHandlerFactory $indexHandlerFactory
149157
* @param \Magento\Framework\Event\ManagerInterface $eventManager
150158
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
151159
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
@@ -154,6 +162,7 @@ class Full
154162
* @param \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate
155163
* @param \Magento\CatalogSearch\Model\Resource\Fulltext $fulltextResource
156164
* @param \Magento\Framework\Search\Request\DimensionFactory $dimensionFactory
165+
* @param \Magento\Indexer\Model\ConfigInterface $indexerConfig
157166
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
158167
*/
159168
public function __construct(
@@ -164,14 +173,16 @@ public function __construct(
164173
\Magento\Catalog\Model\Product\Attribute\Source\Status $catalogProductStatus,
165174
\Magento\Catalog\Model\Resource\Product\Attribute\CollectionFactory $productAttributeCollectionFactory,
166175
\Magento\CatalogSearch\Model\Resource\EngineProvider $engineProvider,
176+
\Magento\CatalogSearch\Model\Indexer\IndexerHandlerFactory $indexHandlerFactory,
167177
\Magento\Framework\Event\ManagerInterface $eventManager,
168178
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
169179
\Magento\Store\Model\StoreManagerInterface $storeManager,
170180
\Magento\Framework\Stdlib\DateTime $dateTime,
171181
\Magento\Framework\Locale\ResolverInterface $localeResolver,
172182
\Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate,
173183
\Magento\CatalogSearch\Model\Resource\Fulltext $fulltextResource,
174-
\Magento\Framework\Search\Request\DimensionFactory $dimensionFactory
184+
\Magento\Framework\Search\Request\DimensionFactory $dimensionFactory,
185+
\Magento\Indexer\Model\ConfigInterface $indexerConfig
175186
) {
176187
$this->resource = $resource;
177188
$this->catalogProductType = $catalogProductType;
@@ -182,7 +193,9 @@ public function __construct(
182193
$this->eventManager = $eventManager;
183194
$this->scopeConfig = $scopeConfig;
184195
$this->storeManager = $storeManager;
185-
$this->engineProvider = $engineProvider;
196+
$this->engine = $engineProvider->get();
197+
$configData = $indexerConfig->getIndexer(Fulltext::INDEXER_ID);
198+
$this->indexHandler = $indexHandlerFactory->create(['data' => $configData]);
186199
$this->dateTime = $dateTime;
187200
$this->localeResolver = $localeResolver;
188201
$this->localeDate = $localeDate;
@@ -245,11 +258,10 @@ protected function getWriteAdapter()
245258
protected function rebuildIndex($productIds = null)
246259
{
247260
$storeIds = array_keys($this->storeManager->getStores());
248-
$engine = $this->getEngineProvider();
249261
foreach ($storeIds as $storeId) {
250262
$dimension = $this->dimensionFactory->create(['name' => self::SCOPE_FIELD_NAME, 'value' => $storeId]);
251-
$engine->deleteIndex([$dimension], $this->getIterator($productIds));
252-
$engine->saveIndex(
263+
$this->indexHandler->deleteIndex([$dimension], $this->getIterator($productIds));
264+
$this->indexHandler->saveIndex(
253265
[$dimension],
254266
$this->rebuildStoreIndex($storeId, $productIds)
255267
);
@@ -308,7 +320,7 @@ public function rebuildStoreIndex($storeId, $productIds = null)
308320
$visibility = $this->getSearchableAttribute('visibility');
309321
$status = $this->getSearchableAttribute('status');
310322
$statusIds = $this->catalogProductStatus->getVisibleStatusIds();
311-
$allowedVisibility = $this->getEngineProvider()->getAllowedVisibility();
323+
$allowedVisibility = $this->engine->getAllowedVisibility();
312324

313325
$lastProductId = 0;
314326
while (true) {
@@ -431,7 +443,7 @@ protected function getSearchableProducts(
431443
protected function cleanIndex($storeId)
432444
{
433445
$dimension = $this->dimensionFactory->create(['name' => self::SCOPE_FIELD_NAME, 'value' => $storeId]);
434-
$this->getEngineProvider()->cleanIndex([$dimension]);
446+
$this->indexHandler->cleanIndex([$dimension]);
435447
}
436448

437449
/**
@@ -444,7 +456,7 @@ protected function cleanIndex($storeId)
444456
protected function deleteIndex($storeId = null, $productIds = null)
445457
{
446458
$dimension = $this->dimensionFactory->create(['name' => self::SCOPE_FIELD_NAME, 'value' => $storeId]);
447-
$this->getEngineProvider()->deleteIndex([$dimension], $this->getIterator($productIds));
459+
$this->indexHandler->deleteIndex([$dimension], $this->getIterator($productIds));
448460
}
449461

450462
/**
@@ -476,7 +488,7 @@ protected function getSearchableAttributes($backendType = null)
476488

477489
$this->eventManager->dispatch(
478490
'catelogsearch_searchable_attributes_load_after',
479-
['engine' => $this->getEngineProvider(), 'attributes' => $attributes]
491+
['engine' => $this->engine, 'attributes' => $attributes]
480492
);
481493

482494
$entity = $this->getEavConfig()->getEntityType(\Magento\Catalog\Model\Product::ENTITY)->getEntity();
@@ -722,7 +734,7 @@ protected function prepareProductIndex($indexData, $productData, $storeId)
722734
$index['options'] = $data;
723735
}
724736

725-
return $this->getEngineProvider()->prepareEntityIndex($index, $this->separator);
737+
return $this->engine->prepareEntityIndex($index, $this->separator);
726738
}
727739

728740
/**
@@ -736,11 +748,11 @@ protected function prepareProductIndex($indexData, $productData, $storeId)
736748
protected function getAttributeValue($attributeId, $valueId, $storeId)
737749
{
738750
$attribute = $this->getSearchableAttribute($attributeId);
739-
$value = $this->getEngineProvider()->processAttributeValue($attribute, $valueId);
751+
$value = $this->engine->processAttributeValue($attribute, $valueId);
740752

741753
if ($attribute->getIsSearchable()
742754
&& $attribute->usesSource()
743-
&& $this->getEngineProvider()->allowAdvancedIndex()
755+
&& $this->engine->allowAdvancedIndex()
744756
) {
745757
$attribute->setStoreId($storeId);
746758
$valueText = $attribute->getSource()->getIndexOptionText($valueId);
@@ -803,12 +815,4 @@ protected function getIterator(array $data)
803815
yield $key => $value;
804816
}
805817
}
806-
807-
/**
808-
* @return \Magento\CatalogSearch\Model\Resource\EngineInterface
809-
*/
810-
private function getEngineProvider()
811-
{
812-
return $this->engineProvider->get();
813-
}
814818
}

app/code/Magento/CatalogSearch/Model/Indexer/IndexerHandler.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
*/
66
namespace Magento\CatalogSearch\Model\Indexer;
77

8-
use Magento\Catalog\Model\Product;
98
use Magento\Eav\Model\Config;
109
use Magento\Framework\App\Resource;
1110
use Magento\Framework\DB\Adapter\AdapterInterface;
@@ -157,6 +156,9 @@ private function getAdapter()
157156
private function insertDocuments(array $documents, array $dimensions)
158157
{
159158
$documents = $this->prepareSearchableFields($documents);
159+
if (empty($documents)) {
160+
return;
161+
}
160162
$this->getAdapter()->insertOnDuplicate(
161163
$this->getTableName($dimensions),
162164
$documents,

app/code/Magento/CatalogSearch/Model/Indexer/IndexerHandlerFactory.php

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55
*/
66
namespace Magento\CatalogSearch\Model\Indexer;
77

8-
use Magento\CatalogSearch\Model\Resource\EngineProvider;
98
use Magento\Framework\App\Config\ScopeConfigInterface;
10-
use Magento\Framework\App\Resource;
119
use Magento\Framework\IndexerInterface;
1210
use Magento\Framework\ObjectManagerInterface;
1311
use Magento\Store\Model\ScopeInterface;
@@ -33,38 +31,58 @@ class IndexerHandlerFactory
3331
*/
3432
private $scopeConfig;
3533

34+
/**
35+
* Configuration path by which current indexer handler stored
36+
*
37+
* @var string
38+
*/
39+
private $configPath;
40+
3641
/**
3742
* Factory constructor
3843
*
3944
* @param ObjectManagerInterface $objectManager
4045
* @param ScopeConfigInterface $scopeConfig
46+
* @param string $configPath
4147
* @param string[] $handlers
4248
*/
4349
public function __construct(
4450
ObjectManagerInterface $objectManager,
4551
ScopeConfigInterface $scopeConfig,
52+
$configPath,
4653
array $handlers = []
4754
) {
4855
$this->_objectManager = $objectManager;
49-
$this->handlers = $handlers;
5056
$this->scopeConfig = $scopeConfig;
57+
$this->configPath = $configPath;
58+
$this->handlers = $handlers;
5159
}
5260

5361
/**
54-
* Create class instance with specified parameters
62+
* Create indexer handler
5563
*
5664
* @param array $data
5765
* @return IndexerInterface
5866
*/
5967
public function create(array $data = [])
6068
{
61-
$currentEngine = $this->scopeConfig->getValue(EngineProvider::CONFIG_ENGINE_PATH, ScopeInterface::SCOPE_STORE);
62-
$object = $this->_objectManager->create($this->handlers[$currentEngine], $data);
69+
$currentHandler = $this->scopeConfig->getValue($this->configPath, ScopeInterface::SCOPE_STORE);
70+
if (!isset($this->handlers[$currentHandler])) {
71+
throw new \LogicException(
72+
'There is no such indexer handler: ' . $currentHandler
73+
);
74+
}
75+
$indexer = $this->_objectManager->create($this->handlers[$currentHandler], $data);
6376

64-
if (!$object instanceof IndexerInterface) {
65-
throw new \InvalidArgumentException($object . ' doesn\'t implement ' . IndexerInterface::class);
77+
if (!$indexer instanceof IndexerInterface) {
78+
throw new \InvalidArgumentException($indexer . ' doesn\'t implement \Magento\Framework\IndexerInterface');
6679
}
6780

68-
return $object;
81+
if ($indexer && !$indexer->isAvailable()) {
82+
throw new \LogicException(
83+
'Indexer handler is not available: ' . $indexer
84+
);
85+
}
86+
return $indexer;
6987
}
7088
}

0 commit comments

Comments
 (0)