Skip to content

Commit 3d806a6

Browse files
committed
ACP2E-1875: [Magento Cloud] Products incorrectly showed Out of Stock then all products show in stock
- stacked indexer actions
1 parent e05e97d commit 3d806a6

File tree

4 files changed

+16
-40
lines changed

4 files changed

+16
-40
lines changed

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
use Magento\Elasticsearch\Model\Indexer\EnhancedIndexerHandler;
1414
use Magento\Framework\App\ObjectManager;
1515
use Magento\Framework\Indexer\DimensionProviderInterface;
16-
use Magento\Framework\Indexer\SaveHandler\IndexerInterface;
1716
use Magento\Store\Model\StoreDimensionProvider;
1817
use Magento\Indexer\Model\ProcessManager;
1918
use Magento\Framework\App\DeploymentConfig;
@@ -102,6 +101,11 @@ class Fulltext implements
102101
*/
103102
private $deploymentConfig;
104103

104+
/**
105+
* @var EnhancedIndexerHandler
106+
*/
107+
private $enhancedIndexerHandler;
108+
105109
/**
106110
* @param FullFactory $fullActionFactory
107111
* @param IndexerHandlerFactory $indexerHandlerFactory
@@ -140,6 +144,8 @@ public function __construct(
140144
$this->processManager = $processManager ?: ObjectManager::getInstance()->get(ProcessManager::class);
141145
$this->batchSize = $batchSize ?? self::BATCH_SIZE;
142146
$this->deploymentConfig = $deploymentConfig ?: ObjectManager::getInstance()->get(DeploymentConfig::class);
147+
$this->enhancedIndexerHandler = $enhancedIndexerHandler ?:
148+
ObjectManager::getInstance()->create(EnhancedIndexerHandler::class, ['data' => $this->data]);
143149
}
144150

145151
/**
@@ -173,12 +179,6 @@ public function executeByDimensions(array $dimensions, \Traversable $entityIds =
173179
'data' => $this->data,
174180
]
175181
);
176-
$enhancedIndexerHandler = $this->indexerHandlerFactory->createSpecificHandler(
177-
[
178-
'data' => $this->data,
179-
],
180-
EnhancedIndexerHandler::class
181-
);
182182

183183
if (null === $entityIds) {
184184
$saveHandler->cleanIndex($dimensions);
@@ -198,13 +198,13 @@ public function executeByDimensions(array $dimensions, \Traversable $entityIds =
198198
foreach ($entityIds as $entityId) {
199199
$currentBatch[] = $entityId;
200200
if (++$i === $this->batchSize) {
201-
$this->processBatch($enhancedIndexerHandler, $dimensions, $currentBatch);
201+
$this->processBatch($this->enhancedIndexerHandler, $dimensions, $currentBatch);
202202
$i = 0;
203203
$currentBatch = [];
204204
}
205205
}
206206
if (!empty($currentBatch)) {
207-
$this->processBatch($enhancedIndexerHandler, $dimensions, $currentBatch);
207+
$this->processBatch($this->enhancedIndexerHandler, $dimensions, $currentBatch);
208208
}
209209
}
210210
}

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

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -53,35 +53,6 @@ public function __construct(
5353
$this->engineResolver = $engineResolver;
5454
}
5555

56-
/**
57-
* Creates specific indexer handler
58-
*
59-
* @param array $data
60-
* @param string|null $handler
61-
* @return IndexerInterface
62-
*/
63-
public function createSpecificHandler(array $data = [], ?string $handler = null): IndexerInterface
64-
{
65-
if (!$handler) {
66-
return $this->create($data);
67-
}
68-
$indexer = $this->_objectManager->create($handler, $data);
69-
70-
$currentHandler = $this->engineResolver->getCurrentSearchEngine();
71-
if (!$indexer instanceof IndexerInterface) {
72-
throw new \InvalidArgumentException(
73-
$currentHandler . ' indexer handler doesn\'t implement ' . IndexerInterface::class
74-
);
75-
}
76-
77-
if ($indexer && !$indexer->isAvailable()) {
78-
throw new \LogicException(
79-
'Indexer handler is not available: ' . $currentHandler
80-
);
81-
}
82-
return $indexer;
83-
}
84-
8556
/**
8657
* Create indexer handler
8758
*

app/code/Magento/CatalogSearch/Test/Unit/Model/Indexer/FulltextTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,9 @@ protected function setUp(): void
7474
$this->enhancedSaveHandler = $this->getClassMock(EnhancedIndexerHandler::class);
7575
$indexerHandlerFactory = $this->createPartialMock(
7676
IndexerHandlerFactory::class,
77-
['create', 'createSpecificHandler']
77+
['create']
7878
);
7979
$indexerHandlerFactory->expects($this->any())->method('create')->willReturn($this->saveHandler);
80-
$indexerHandlerFactory->expects($this->any())->method('createSpecificHandler')->willReturn($this->enhancedSaveHandler);
8180

8281
$this->fulltextResource = $this->getClassMock(\Magento\CatalogSearch\Model\ResourceModel\Fulltext::class);
8382

@@ -101,6 +100,7 @@ protected function setUp(): void
101100
'dimensionProvider' => $this->dimensionProviderMock,
102101
'indexScopeState' => $stateMock,
103102
'processManager' => $this->processManager,
103+
'enhancedIndexerHandler' => $this->enhancedSaveHandler
104104
]
105105
);
106106
}

app/code/Magento/Elasticsearch/Model/Indexer/EnhancedIndexerHandler.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ class EnhancedIndexerHandler extends IndexerHandler
2323
*/
2424
private ElasticsearchAdapter $adapter;
2525

26+
/**
27+
* @var array
28+
*/
29+
private array $data = [];
30+
2631
/**
2732
* IndexerHandler constructor.
2833
* @param IndexStructureInterface $indexStructure

0 commit comments

Comments
 (0)