Skip to content

Commit 07a89b1

Browse files
committed
Merge branch 'ACP2E-1834' of https://github.com/magento-l3/magento2ce into PR-05242023
2 parents 32804b3 + d09224a commit 07a89b1

File tree

4 files changed

+30
-20
lines changed

4 files changed

+30
-20
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -441,8 +441,10 @@ public function reindexAll()
441441
}
442442
try {
443443
$this->getActionInstance()->executeFull();
444-
$state->setStatus(StateInterface::STATUS_VALID);
445-
$state->save();
444+
if ($this->workingStateProvider->isWorking($this->getId())) {
445+
$state->setStatus(StateInterface::STATUS_VALID);
446+
$state->save();
447+
}
446448
if (!empty($sharedIndexers)) {
447449
$this->resumeSharedViews($sharedIndexers);
448450
}

app/code/Magento/Indexer/Model/Processor.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public function __construct(
5959
IndexerInterfaceFactory $indexerFactory,
6060
Indexer\CollectionFactory $indexersFactory,
6161
ProcessorInterface $mviewProcessor,
62-
MakeSharedIndexValid $makeSharedValid = null
62+
?MakeSharedIndexValid $makeSharedValid = null
6363
) {
6464
$this->config = $config;
6565
$this->indexerFactory = $indexerFactory;
@@ -86,9 +86,11 @@ public function reindexAllInvalid()
8686
$sharedIndex = $indexerConfig['shared_index'] ?? null;
8787
if (!in_array($sharedIndex, $this->sharedIndexesComplete)) {
8888
$indexer->reindexAll();
89-
90-
if (!empty($sharedIndex) && $this->makeSharedValid->execute($sharedIndex)) {
91-
$this->sharedIndexesComplete[] = $sharedIndex;
89+
$indexer->load($indexer->getId());
90+
if ($indexer->isValid()) {
91+
if (!empty($sharedIndex) && $this->makeSharedValid->execute($sharedIndex)) {
92+
$this->sharedIndexesComplete[] = $sharedIndex;
93+
}
9294
}
9395
}
9496
}

app/code/Magento/Indexer/Test/Unit/Model/IndexerTest.php

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,8 @@ public function testLoadWithException()
144144
public function testGetView()
145145
{
146146
$indexId = 'indexer_internal_name';
147-
$this->viewMock->expects($this->once())->method('load')->with('view_test')->willReturnSelf();
147+
$this->viewMock->expects($this->once())
148+
->method('load')->with('view_test')->willReturnSelf();
148149
$this->loadIndexer($indexId);
149150

150151
$this->assertEquals($this->viewMock, $this->model->getView());
@@ -224,11 +225,14 @@ public function testReindexAll()
224225
$indexId = 'indexer_internal_name';
225226
$this->loadIndexer($indexId);
226227

228+
$this->workingStateProvider->method('isWorking')->willReturnOnConsecutiveCalls(false, true);
229+
227230
$stateMock = $this->createPartialMock(
228231
State::class,
229232
['load', 'getId', 'setIndexerId', '__wakeup', 'getStatus', 'setStatus', 'save']
230233
);
231-
$stateMock->expects($this->once())->method('load')->with($indexId, 'indexer_id')->willReturnSelf();
234+
$stateMock->expects($this->once())
235+
->method('load')->with($indexId, 'indexer_id')->willReturnSelf();
232236
$stateMock->expects($this->never())->method('setIndexerId');
233237
$stateMock->expects($this->once())->method('getId')->willReturn(1);
234238
$stateMock->expects($this->exactly(2))->method('setStatus')->willReturnSelf();
@@ -268,7 +272,8 @@ public function testReindexAllWithException()
268272
State::class,
269273
['load', 'getId', 'setIndexerId', '__wakeup', 'getStatus', 'setStatus', 'save']
270274
);
271-
$stateMock->expects($this->once())->method('load')->with($indexId, 'indexer_id')->willReturnSelf();
275+
$stateMock->expects($this->once())
276+
->method('load')->with($indexId, 'indexer_id')->willReturnSelf();
272277
$stateMock->expects($this->never())->method('setIndexerId');
273278
$stateMock->expects($this->once())->method('getId')->willReturn(1);
274279
$stateMock->expects($this->exactly(2))->method('setStatus')->willReturnSelf();
@@ -313,7 +318,8 @@ public function testReindexAllWithError()
313318
State::class,
314319
['load', 'getId', 'setIndexerId', '__wakeup', 'getStatus', 'setStatus', 'save']
315320
);
316-
$stateMock->expects($this->once())->method('load')->with($indexId, 'indexer_id')->willReturnSelf();
321+
$stateMock->expects($this->once())
322+
->method('load')->with($indexId, 'indexer_id')->willReturnSelf();
317323
$stateMock->expects($this->never())->method('setIndexerId');
318324
$stateMock->expects($this->once())->method('getId')->willReturn(1);
319325
$stateMock->expects($this->exactly(2))->method('setStatus')->willReturnSelf();
@@ -483,7 +489,8 @@ public function testInvalidate()
483489
);
484490

485491
$this->stateFactoryMock->expects($this->once())->method('create')->willReturn($stateMock);
486-
$stateMock->expects($this->once())->method('setStatus')->with(StateInterface::STATUS_INVALID)->willReturnSelf();
492+
$stateMock->expects($this->once())
493+
->method('setStatus')->with(StateInterface::STATUS_INVALID)->willReturnSelf();
487494
$stateMock->expects($this->once())->method('save')->willReturnSelf();
488495
$this->model->invalidate();
489496
}

app/code/Magento/Indexer/Test/Unit/Model/ProcessorTest.php

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -102,18 +102,14 @@ public function testReindexAllInvalid(): void
102102
$this->configMock->expects($this->once())->method('getIndexers')->willReturn($indexers);
103103

104104
$state1Mock = $this->createPartialMock(State::class, ['getStatus', '__wakeup']);
105-
$state1Mock->expects(
106-
$this->once()
107-
)->method(
108-
'getStatus'
109-
)->willReturn(
110-
StateInterface::STATUS_INVALID
111-
);
105+
$state1Mock->expects($this->exactly(2))
106+
->method('getStatus')
107+
->willReturnOnConsecutiveCalls(StateInterface::STATUS_INVALID, StateInterface::STATUS_VALID);
112108
$indexer1Mock = $this->createPartialMock(
113109
Indexer::class,
114110
['load', 'getState', 'reindexAll']
115111
);
116-
$indexer1Mock->expects($this->once())->method('getState')->willReturn($state1Mock);
112+
$indexer1Mock->expects($this->exactly(2))->method('getState')->willReturn($state1Mock);
117113
$indexer1Mock->expects($this->once())->method('reindexAll');
118114

119115
$state2Mock = $this->createPartialMock(State::class, ['getStatus', '__wakeup']);
@@ -169,7 +165,10 @@ function ($elem) {
169165
$stateMock = $this->createPartialMock(State::class, ['getStatus', '__wakeup']);
170166
$stateMock->expects($this->any())
171167
->method('getStatus')
172-
->willReturn($indexerStates[$indexerData['indexer_id']]);
168+
->willReturnOnConsecutiveCalls(
169+
$indexerStates[$indexerData['indexer_id']],
170+
StateInterface::STATUS_VALID
171+
);
173172
$indexerMock = $this->createPartialMock(Indexer::class, ['load', 'getState', 'reindexAll']);
174173
$indexerMock->expects($this->any())->method('getState')->willReturn($stateMock);
175174
$indexerMock->expects($expectedReindexAllCalls[$indexerData['indexer_id']])->method('reindexAll');

0 commit comments

Comments
 (0)