Skip to content

Commit 7898946

Browse files
Merge forwardport of #11183 to 2.3-develop branch
Applied pull request patch https://github.com/magento/magento2/pull/11183.patch (created by @larsroettig) based on commit(s): 1. fb2ec44 2. 214fc33 Fixed GitHub Issues in 2.3-develop branch: - #11166: ReindexAll -> getState() is not correct if the Indexer broke with PHP fatal error (reported by @larsroettig)
2 parents 3e32140 + e7d90de commit 7898946

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,11 @@ public function reindexAll()
418418
$state->save();
419419
$this->getView()->resume();
420420
throw $exception;
421+
} catch (\Error $error) {
422+
$state->setStatus(StateInterface::STATUS_INVALID);
423+
$state->save();
424+
$this->getView()->resume();
425+
throw $error;
421426
}
422427
}
423428
}

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

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,56 @@ function () {
273273
$this->model->reindexAll();
274274
}
275275

276+
/**
277+
* @expectedException \Error
278+
* @expectedExceptionMessage Test Engine Error
279+
*/
280+
public function testReindexAllWithError()
281+
{
282+
283+
$indexId = 'indexer_internal_name';
284+
$this->loadIndexer($indexId);
285+
286+
$stateMock = $this->createPartialMock(
287+
\Magento\Indexer\Model\Indexer\State::class,
288+
['load', 'getId', 'setIndexerId', '__wakeup', 'getStatus', 'setStatus', 'save']
289+
);
290+
$stateMock->expects($this->once())->method('load')->with($indexId, 'indexer_id')->will($this->returnSelf());
291+
$stateMock->expects($this->never())->method('setIndexerId');
292+
$stateMock->expects($this->once())->method('getId')->will($this->returnValue(1));
293+
$stateMock->expects($this->exactly(2))->method('setStatus')->will($this->returnSelf());
294+
$stateMock->expects($this->once())->method('getStatus')->will($this->returnValue('idle'));
295+
$stateMock->expects($this->exactly(2))->method('save')->will($this->returnSelf());
296+
$this->stateFactoryMock->expects($this->once())->method('create')->will($this->returnValue($stateMock));
297+
298+
$this->viewMock->expects($this->once())->method('isEnabled')->will($this->returnValue(false));
299+
$this->viewMock->expects($this->never())->method('suspend');
300+
$this->viewMock->expects($this->once())->method('resume');
301+
302+
$actionMock = $this->createPartialMock(
303+
\Magento\Framework\Indexer\ActionInterface::class,
304+
['executeFull', 'executeList', 'executeRow']
305+
);
306+
$actionMock->expects($this->once())->method('executeFull')->will(
307+
$this->returnCallback(
308+
function () {
309+
throw new \Error('Test Engine Error');
310+
}
311+
)
312+
);
313+
$this->actionFactoryMock->expects(
314+
$this->once()
315+
)->method(
316+
'create'
317+
)->with(
318+
'Some\Class\Name'
319+
)->will(
320+
$this->returnValue($actionMock)
321+
);
322+
323+
$this->model->reindexAll();
324+
}
325+
276326
protected function getIndexerData()
277327
{
278328
return [

0 commit comments

Comments
 (0)