Skip to content

Commit f80c97c

Browse files
committed
ACP2E-1875: [Magento Cloud] Products incorrectly showed Out of Stock then all products show in stock
- implemented CR
1 parent d92aa8b commit f80c97c

File tree

10 files changed

+50
-142
lines changed

10 files changed

+50
-142
lines changed

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

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,6 @@ class Fulltext implements
101101
*/
102102
private $deploymentConfig;
103103

104-
/**
105-
* @var EnhancedIndexerInterface
106-
*/
107-
private $enhancedIndexerHandler;
108-
109104
/**
110105
* @param FullFactory $fullActionFactory
111106
* @param IndexerHandlerFactory $indexerHandlerFactory
@@ -117,7 +112,6 @@ class Fulltext implements
117112
* @param ProcessManager|null $processManager
118113
* @param int|null $batchSize
119114
* @param DeploymentConfig|null $deploymentConfig
120-
* @param EnhancedIndexerInterface|null $enhancedIndexerHandler
121115
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
122116
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
123117
*/
@@ -131,8 +125,7 @@ public function __construct(
131125
array $data,
132126
ProcessManager $processManager = null,
133127
?int $batchSize = null,
134-
?DeploymentConfig $deploymentConfig = null,
135-
?EnhancedIndexerInterface $enhancedIndexerHandler = null
128+
?DeploymentConfig $deploymentConfig = null
136129
) {
137130
$this->fullAction = $fullActionFactory->create(['data' => $data]);
138131
$this->indexerHandlerFactory = $indexerHandlerFactory;
@@ -144,8 +137,6 @@ public function __construct(
144137
$this->processManager = $processManager ?: ObjectManager::getInstance()->get(ProcessManager::class);
145138
$this->batchSize = $batchSize ?? self::BATCH_SIZE;
146139
$this->deploymentConfig = $deploymentConfig ?: ObjectManager::getInstance()->get(DeploymentConfig::class);
147-
$this->enhancedIndexerHandler = $enhancedIndexerHandler ?:
148-
ObjectManager::getInstance()->create(EnhancedIndexerInterface::class, ['data' => $this->data]);
149140
}
150141

151142
/**
@@ -198,13 +189,13 @@ public function executeByDimensions(array $dimensions, \Traversable $entityIds =
198189
foreach ($entityIds as $entityId) {
199190
$currentBatch[] = $entityId;
200191
if (++$i === $this->batchSize) {
201-
$this->processBatch($this->enhancedIndexerHandler, $dimensions, $currentBatch);
192+
$this->processBatch($saveHandler, $dimensions, $currentBatch);
202193
$i = 0;
203194
$currentBatch = [];
204195
}
205196
}
206197
if (!empty($currentBatch)) {
207-
$this->processBatch($this->enhancedIndexerHandler, $dimensions, $currentBatch);
198+
$this->processBatch($saveHandler, $dimensions, $currentBatch);
208199
}
209200
}
210201
}

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

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
use Magento\CatalogSearch\Model\Indexer\Fulltext;
1111
use Magento\CatalogSearch\Model\Indexer\Fulltext\Action\Full;
1212
use Magento\CatalogSearch\Model\Indexer\Fulltext\Action\FullFactory;
13-
use Magento\Elasticsearch\Model\Indexer\EnhancedIndexerHandler;
1413
use Magento\Framework\Indexer\SaveHandler\IndexerInterface;
1514
use Magento\CatalogSearch\Model\Indexer\IndexerHandlerFactory;
1615
use Magento\CatalogSearch\Model\Indexer\Scope\State;
@@ -42,11 +41,6 @@ class FulltextTest extends TestCase
4241
*/
4342
protected $saveHandler;
4443

45-
/**
46-
* @var IndexerInterface|MockObject
47-
*/
48-
protected $enhancedSaveHandler;
49-
5044
/**
5145
* @var \Magento\CatalogSearch\Model\ResourceModel\Fulltext|MockObject
5246
*/
@@ -71,7 +65,6 @@ protected function setUp(): void
7165
);
7266
$fullActionFactory->expects($this->any())->method('create')->willReturn($this->fullAction);
7367
$this->saveHandler = $this->getClassMock(IndexerInterface::class);
74-
$this->enhancedSaveHandler = $this->getClassMock(EnhancedIndexerHandler::class);
7568
$indexerHandlerFactory = $this->createPartialMock(
7669
IndexerHandlerFactory::class,
7770
['create']
@@ -100,7 +93,6 @@ protected function setUp(): void
10093
'dimensionProvider' => $this->dimensionProviderMock,
10194
'indexScopeState' => $stateMock,
10295
'processManager' => $this->processManager,
103-
'enhancedIndexerHandler' => $this->enhancedSaveHandler
10496
]
10597
);
10698
}
@@ -124,9 +116,9 @@ public function testExecute()
124116
$this->fulltextResource->expects($this->exactly(2))
125117
->method('getRelationsByChild')
126118
->willReturn($ids);
127-
$this->enhancedSaveHandler->expects($this->exactly(count($stores)))->method('deleteIndex');
128-
$this->enhancedSaveHandler->expects($this->exactly(2))->method('saveIndex');
129-
$this->enhancedSaveHandler->expects($this->exactly(2))->method('isAvailable')->willReturn(true);
119+
$this->saveHandler->expects($this->exactly(count($stores)))->method('deleteIndex');
120+
$this->saveHandler->expects($this->exactly(2))->method('saveIndex');
121+
$this->saveHandler->expects($this->exactly(2))->method('isAvailable')->willReturn(true);
130122
$consecutiveStoreRebuildArguments = array_map(
131123
function ($store) use ($ids) {
132124
return [$store, $ids];
@@ -195,9 +187,9 @@ public function testExecuteList()
195187
$this->fulltextResource->expects($this->exactly(2))
196188
->method('getRelationsByChild')
197189
->willReturn($ids);
198-
$this->enhancedSaveHandler->expects($this->exactly(count($stores)))->method('deleteIndex');
199-
$this->enhancedSaveHandler->expects($this->exactly(2))->method('saveIndex');
200-
$this->enhancedSaveHandler->expects($this->exactly(2))->method('isAvailable')->willReturn(true);
190+
$this->saveHandler->expects($this->exactly(count($stores)))->method('deleteIndex');
191+
$this->saveHandler->expects($this->exactly(2))->method('saveIndex');
192+
$this->saveHandler->expects($this->exactly(2))->method('isAvailable')->willReturn(true);
201193
$this->fullAction->expects($this->exactly(2))
202194
->method('rebuildStoreIndex')
203195
->willReturn(new \ArrayObject([$indexData, $indexData]));
@@ -214,9 +206,9 @@ public function testExecuteRow()
214206
$this->fulltextResource->expects($this->exactly(2))
215207
->method('getRelationsByChild')
216208
->willReturn([$id]);
217-
$this->enhancedSaveHandler->expects($this->exactly(count($stores)))->method('deleteIndex');
218-
$this->enhancedSaveHandler->expects($this->exactly(2))->method('saveIndex');
219-
$this->enhancedSaveHandler->expects($this->exactly(2))->method('isAvailable')->willReturn(true);
209+
$this->saveHandler->expects($this->exactly(count($stores)))->method('deleteIndex');
210+
$this->saveHandler->expects($this->exactly(2))->method('saveIndex');
211+
$this->saveHandler->expects($this->exactly(2))->method('isAvailable')->willReturn(true);
220212
$this->fullAction->expects($this->exactly(2))
221213
->method('rebuildStoreIndex')
222214
->willReturn(new \ArrayObject([$indexData, $indexData]));

app/code/Magento/Elasticsearch/Model/Adapter/Elasticsearch.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
use Elasticsearch\Common\Exceptions\Missing404Exception;
1010
use Exception;
11+
use LogicException;
1112
use Magento\AdvancedSearch\Model\Client\ClientInterface;
1213
use Magento\Catalog\Api\ProductAttributeRepositoryInterface;
1314
use Magento\Elasticsearch\Model\Adapter\FieldMapper\Product\FieldProvider\StaticField;
@@ -238,9 +239,9 @@ public function triggerStackedQueries(): self
238239
*
239240
* @param array $queries
240241
* @return void
241-
* @throws LocalizedException
242+
* @throws LogicException
242243
*/
243-
protected function stackQueries(array $queries): void
244+
private function stackQueries(array $queries): void
244245
{
245246
if ($this->isStackQueries) {
246247
if (empty($this->stackedQueries)) {
@@ -249,7 +250,7 @@ protected function stackQueries(array $queries): void
249250
$this->stackedQueries['body'] = array_merge($this->stackedQueries['body'], $queries['body']);
250251
}
251252
} else {
252-
throw new LocalizedException(__('Stacked indexer queries not enabled'));
253+
throw new LogicException('Stacked indexer queries not enabled');
253254
}
254255
}
255256

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

Lines changed: 0 additions & 99 deletions
This file was deleted.

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

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Magento\Framework\App\ScopeResolverInterface;
1616
use Magento\Framework\Indexer\IndexStructureInterface;
1717
use Magento\Framework\Indexer\SaveHandler\Batch;
18+
use Magento\Framework\Indexer\SaveHandler\EnhancedIndexerInterface;
1819
use Magento\Framework\Indexer\SaveHandler\IndexerInterface;
1920
use Magento\Framework\Search\Request\Dimension;
2021
use Magento\Framework\Indexer\CacheContext;
@@ -23,7 +24,7 @@
2324
* Indexer Handler for Elasticsearch engine.
2425
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
2526
*/
26-
class IndexerHandler implements IndexerInterface
27+
class IndexerHandler implements IndexerInterface, EnhancedIndexerInterface
2728
{
2829
/**
2930
* Size of default batch
@@ -125,6 +126,37 @@ public function __construct(
125126
$this->processor = $processor ?: ObjectManager::getInstance()->get(Processor::class);
126127
}
127128

129+
/**
130+
* Disables stacked actions mode
131+
*
132+
* @return void
133+
*/
134+
public function disableStackedActions(): void
135+
{
136+
$this->adapter->disableStackQueriesMode();
137+
}
138+
139+
/**
140+
* Enables stacked actions mode
141+
*
142+
* @return void
143+
*/
144+
public function enableStackedActions(): void
145+
{
146+
$this->adapter->enableStackQueriesMode();
147+
}
148+
149+
/**
150+
* Runs stacked actions
151+
*
152+
* @return void
153+
* @throws \Exception
154+
*/
155+
public function triggerStackedActions(): void
156+
{
157+
$this->adapter->triggerStackedQueries();
158+
}
159+
128160
/**
129161
* @inheritdoc
130162
*/

app/code/Magento/Elasticsearch/etc/di.xml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
<preference for="Magento\Framework\Search\Dynamic\DataProviderInterface" type="Magento\Elasticsearch\SearchAdapter\Dynamic\DataProvider" />
1717
<preference for="Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection\SearchResultApplierInterface" type="Magento\Elasticsearch\Model\ResourceModel\Fulltext\Collection\SearchResultApplier"/>
1818
<preference for="Magento\Elasticsearch\Model\DataProvider\Base\GetSuggestionFrequencyInterface" type="Magento\Elasticsearch\Model\DataProvider\Base\GetSuggestionFrequency"/>
19-
<preference for="Magento\Framework\Indexer\SaveHandler\EnhancedIndexerInterface" type="Magento\Elasticsearch\Model\Indexer\EnhancedIndexerHandler"/>
2019
<type name="Magento\Catalog\Model\Indexer\Category\Product\Action\Rows">
2120
<plugin name="catalogsearchFulltextProductAssignment" type="Magento\Elasticsearch\Model\Indexer\Fulltext\Plugin\Category\Product\Action\Rows"/>
2221
</type>
@@ -561,11 +560,6 @@
561560
<argument name="cacheContext" xsi:type="object">Magento\Framework\Indexer\CacheContext\Proxy</argument>
562561
</arguments>
563562
</type>
564-
<type name="Magento\Elasticsearch\Model\Indexer\EnhancedIndexerHandler">
565-
<arguments>
566-
<argument name="cacheContext" xsi:type="object">Magento\Framework\Indexer\CacheContext\Proxy</argument>
567-
</arguments>
568-
</type>
569563
<type name="Magento\Catalog\Model\Product\ReservedAttributeList">
570564
<arguments>
571565
<argument name="reservedAttributes" xsi:type="array">

app/code/Magento/Elasticsearch/i18n/en_US.csv

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,3 @@
1212
"Test Connection","Test Connection"
1313
"Minimum Terms to Match","Minimum Terms to Match"
1414
"Created indexer handler must be instance of %1.", "Created indexer handler must be instance of %1."
15-
"Stacked indexer queries not enabled", "Stacked indexer queries not enabled"

app/code/Magento/Elasticsearch7/etc/di.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
*/
77
-->
88
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
9-
<preference for="Magento\Framework\Indexer\SaveHandler\EnhancedIndexerInterface" type="Magento\Elasticsearch\Model\Indexer\EnhancedIndexerHandler"/>
109
<type name="Magento\Elasticsearch\Model\Config">
1110
<arguments>
1211
<argument name="engineList" xsi:type="array">

app/code/Magento/OpenSearch/etc/di.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
-->
88
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
99
xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
10-
<preference for="Magento\Framework\Indexer\SaveHandler\EnhancedIndexerInterface" type="Magento\Elasticsearch\Model\Indexer\EnhancedIndexerHandler"/>
1110
<type name="Magento\Elasticsearch\Model\Config">
1211
<arguments>
1312
<argument name="engineList" xsi:type="array">

lib/internal/Magento/Framework/Indexer/SaveHandler/EnhancedIndexerInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
namespace Magento\Framework\Indexer\SaveHandler;
99

10-
interface EnhancedIndexerInterface extends IndexerInterface
10+
interface EnhancedIndexerInterface
1111
{
1212
/**
1313
* Disable stacked queries mode

0 commit comments

Comments
 (0)