Skip to content

Commit 31aebbf

Browse files
committed
MC-21717: [ElasticSearch] Product is not displayed in storefront
1 parent 1ebd7cc commit 31aebbf

File tree

6 files changed

+96
-17
lines changed

6 files changed

+96
-17
lines changed

app/code/Magento/Catalog/Model/Category.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1135,8 +1135,6 @@ public function reindex()
11351135
|| $this->dataHasChangedFor('is_active')) {
11361136
if (!$productIndexer->isScheduled()) {
11371137
$productIndexer->reindexList($this->getPathIds());
1138-
} else {
1139-
$productIndexer->invalidate();
11401138
}
11411139
}
11421140
}
@@ -1294,6 +1292,7 @@ public function getChildrenData()
12941292

12951293
//@codeCoverageIgnoreEnd
12961294

1295+
// phpcs:disable PHPCompatibility.FunctionNameRestrictions.ReservedFunctionNames
12971296
/**
12981297
* Return Data Object data in array format.
12991298
*
@@ -1302,6 +1301,7 @@ public function getChildrenData()
13021301
*/
13031302
public function __toArray()
13041303
{
1304+
// phpcs:enable PHPCompatibility.FunctionNameRestrictions.ReservedFunctionNames
13051305
$data = $this->_data;
13061306
$hasToArray = function ($model) {
13071307
return is_object($model) && method_exists($model, '__toArray') && is_callable([$model, '__toArray']);

app/code/Magento/Catalog/Model/Indexer/Category/Product/Action/Rows.php

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55
*/
66
namespace Magento\Catalog\Model\Indexer\Category\Product\Action;
77

8+
/**
9+
* Reindex multiple rows action.
10+
*
11+
* @package Magento\Catalog\Model\Indexer\Category\Product\Action
12+
*/
813
class Rows extends \Magento\Catalog\Model\Indexer\Category\Product\AbstractAction
914
{
1015
/**
@@ -23,11 +28,19 @@ class Rows extends \Magento\Catalog\Model\Indexer\Category\Product\AbstractActio
2328
*/
2429
public function execute(array $entityIds = [], $useTempTable = false)
2530
{
26-
$this->limitationByCategories = $entityIds;
31+
foreach ($entityIds as $entityId) {
32+
$this->limitationByCategories[] = (int)$entityId;
33+
$path = $this->getPathFromCategoryId($entityId);
34+
if (!empty($path)) {
35+
$pathIds = explode('/', $path);
36+
foreach ($pathIds as $pathId) {
37+
$this->limitationByCategories[] = (int)$pathId;
38+
}
39+
}
40+
}
41+
$this->limitationByCategories = array_unique($this->limitationByCategories);
2742
$this->useTempTable = $useTempTable;
28-
2943
$this->removeEntries();
30-
3144
$this->reindex();
3245

3346
return $this;

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,13 @@ public function __construct(
5555
*/
5656
public function __call(string $method, array $args)
5757
{
58+
//phpcs:ignore Magento2.Functions.DiscouragedFunction
5859
return call_user_func_array([$this->indexer, $method], $args);
5960
}
6061

6162
/**
63+
* Sleep magic.
64+
*
6265
* @return array
6366
*/
6467
public function __sleep()
@@ -218,9 +221,16 @@ public function isWorking(): bool
218221
public function invalidate()
219222
{
220223
$this->indexer->invalidate();
221-
$dependentIndexerIds = $this->dependencyInfoProvider->getIndexerIdsToRunAfter($this->indexer->getId());
222-
foreach ($dependentIndexerIds as $indexerId) {
223-
$this->indexerRegistry->get($indexerId)->invalidate();
224+
$currentIndexerId = $this->indexer->getId();
225+
$idsToRunBefore = $this->dependencyInfoProvider->getIndexerIdsToRunBefore($currentIndexerId);
226+
$idsToRunAfter = $this->dependencyInfoProvider->getIndexerIdsToRunAfter($currentIndexerId);
227+
228+
$indexersToInvalidate = array_unique(array_merge($idsToRunBefore, $idsToRunAfter));
229+
foreach ($indexersToInvalidate as $indexerId) {
230+
$indexer = $this->indexerRegistry->get($indexerId);
231+
if (!$indexer->isInvalid()) {
232+
$indexer->invalidate();
233+
}
224234
}
225235
}
226236

dev/tests/integration/testsuite/Magento/Catalog/Model/Product/UrlTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@ public function getUrlsWithSecondStoreProvider()
8787
];
8888
}
8989

90+
/**
91+
* @magentoDbIsolation disabled
92+
*/
9093
public function testGetProductUrl()
9194
{
9295
$repository = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
@@ -121,6 +124,7 @@ public function testGetUrlPath()
121124
}
122125

123126
/**
127+
* @magentoDbIsolation disabled
124128
* @magentoAppArea frontend
125129
*/
126130
public function testGetUrl()
@@ -142,6 +146,7 @@ public function testGetUrl()
142146
* Check that rearranging product url rewrites do not influence on whether to use category in product links
143147
*
144148
* @magentoConfigFixture current_store catalog/seo/product_use_categories 0
149+
* @magentoDbIsolation disabled
145150
*/
146151
public function testGetProductUrlWithRearrangedUrlRewrites()
147152
{

lib/internal/Magento/Framework/Mview/Test/Unit/View/ChangelogTest.php

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ class ChangelogTest extends \PHPUnit\Framework\TestCase
3333
protected function setUp()
3434
{
3535
$this->connectionMock = $this->createMock(\Magento\Framework\DB\Adapter\Pdo\Mysql::class);
36-
3736
$this->resourceMock = $this->createMock(\Magento\Framework\App\ResourceConnection::class);
3837
$this->mockGetConnection($this->connectionMock);
3938

@@ -98,14 +97,50 @@ public function testGetVersion()
9897
$this->mockIsTableExists($changelogTableName, true);
9998
$this->mockGetTableName();
10099

100+
$selectMock = $this->getMockBuilder(\Magento\Framework\DB\Select::class)
101+
->disableOriginalConstructor()
102+
->disableOriginalClone()
103+
->setMethods(['from', 'order', 'limit'])
104+
->getMock();
105+
$selectMock->expects($this->any())->method('from')->willReturn($selectMock);
106+
$selectMock->expects($this->any())->method('order')->willReturn($selectMock);
107+
$selectMock->expects($this->any())->method('limit')->willReturn($selectMock);
108+
109+
$this->connectionMock->expects($this->any())->method('select')->willReturn($selectMock);
110+
101111
$this->connectionMock->expects($this->once())
102112
->method('fetchRow')
103-
->will($this->returnValue(['Auto_increment' => 11]));
113+
->will($this->returnValue(['version_id' => 10]));
104114

105115
$this->model->setViewId('viewIdtest');
106116
$this->assertEquals(10, $this->model->getVersion());
107117
}
108118

119+
public function testGetVersionEmptyChangelog()
120+
{
121+
$changelogTableName = 'viewIdtest_cl';
122+
$this->mockIsTableExists($changelogTableName, true);
123+
$this->mockGetTableName();
124+
125+
$selectMock = $this->getMockBuilder(\Magento\Framework\DB\Select::class)
126+
->disableOriginalConstructor()
127+
->disableOriginalClone()
128+
->setMethods(['from', 'order', 'limit'])
129+
->getMock();
130+
$selectMock->expects($this->any())->method('from')->willReturn($selectMock);
131+
$selectMock->expects($this->any())->method('order')->willReturn($selectMock);
132+
$selectMock->expects($this->any())->method('limit')->willReturn($selectMock);
133+
134+
$this->connectionMock->expects($this->any())->method('select')->willReturn($selectMock);
135+
136+
$this->connectionMock->expects($this->once())
137+
->method('fetchRow')
138+
->will($this->returnValue(false));
139+
140+
$this->model->setViewId('viewIdtest');
141+
$this->assertEquals(0, $this->model->getVersion());
142+
}
143+
109144
/**
110145
* @expectedException \Magento\Framework\Exception\RuntimeException
111146
* @expectedExceptionMessage Table status for viewIdtest_cl is incorrect. Can`t fetch version id.
@@ -116,9 +151,20 @@ public function testGetVersionWithExceptionNoAutoincrement()
116151
$this->mockIsTableExists($changelogTableName, true);
117152
$this->mockGetTableName();
118153

154+
$selectMock = $this->getMockBuilder(\Magento\Framework\DB\Select::class)
155+
->disableOriginalConstructor()
156+
->disableOriginalClone()
157+
->setMethods(['from', 'order', 'limit'])
158+
->getMock();
159+
$selectMock->expects($this->any())->method('from')->willReturn($selectMock);
160+
$selectMock->expects($this->any())->method('order')->willReturn($selectMock);
161+
$selectMock->expects($this->any())->method('limit')->willReturn($selectMock);
162+
163+
$this->connectionMock->expects($this->any())->method('select')->willReturn($selectMock);
164+
119165
$this->connectionMock->expects($this->once())
120166
->method('fetchRow')
121-
->will($this->returnValue([]));
167+
->will($this->returnValue(['no_version_column' => 'blabla']));
122168

123169
$this->model->setViewId('viewIdtest');
124170
$this->model->getVersion();

lib/internal/Magento/Framework/Mview/View/Changelog.php

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -178,13 +178,18 @@ public function getVersion()
178178
if (!$this->connection->isTableExists($changelogTableName)) {
179179
throw new ChangelogTableNotExistsException(new Phrase("Table %1 does not exist", [$changelogTableName]));
180180
}
181-
$row = $this->connection->fetchRow('SHOW TABLE STATUS LIKE ?', [$changelogTableName]);
182-
if (isset($row['Auto_increment'])) {
183-
return (int)$row['Auto_increment'] - 1;
181+
$select = $this->connection->select()->from($changelogTableName)->order('version_id DESC')->limit(1);
182+
$row = $this->connection->fetchRow($select);
183+
if ($row === false) {
184+
return 0;
184185
} else {
185-
throw new RuntimeException(
186-
new Phrase("Table status for %1 is incorrect. Can`t fetch version id.", [$changelogTableName])
187-
);
186+
if (is_array($row) && array_key_exists('version_id', $row)) {
187+
return (int)$row['version_id'];
188+
} else {
189+
throw new RuntimeException(
190+
new Phrase("Table status for %1 is incorrect. Can`t fetch version id.", [$changelogTableName])
191+
);
192+
}
188193
}
189194
}
190195

0 commit comments

Comments
 (0)