Skip to content

Commit e4f85c9

Browse files
[EngCom] Public Pull Requests - 2.2-develop
- merged latest code from mainline branch
2 parents efda409 + f378f1f commit e4f85c9

File tree

6 files changed

+97
-2
lines changed

6 files changed

+97
-2
lines changed
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
namespace Magento\Catalog\Model\Indexer\Category\Product\Plugin;
8+
9+
use Magento\Framework\App\ResourceConnection;
10+
use Magento\Store\Model\StoreManagerInterface;
11+
use Magento\Framework\Indexer\ScopeResolver\IndexScopeResolver;
12+
use Magento\Catalog\Model\Indexer\Category\Product\AbstractAction;
13+
use Magento\Framework\Search\Request\Dimension;
14+
15+
/**
16+
* Class that replace catalog_category_product_index table name on the table name segmented per store
17+
*/
18+
class TableResolver
19+
{
20+
/**
21+
* @var StoreManagerInterface
22+
*/
23+
private $storeManager;
24+
25+
/**
26+
* @var IndexScopeResolver
27+
*/
28+
private $tableResolver;
29+
30+
/**
31+
* @param StoreManagerInterface $storeManager
32+
* @param IndexScopeResolver $tableResolver
33+
*/
34+
public function __construct(
35+
StoreManagerInterface $storeManager,
36+
IndexScopeResolver $tableResolver
37+
) {
38+
$this->storeManager = $storeManager;
39+
$this->tableResolver = $tableResolver;
40+
}
41+
42+
/**
43+
* replacing catalog_category_product_index table name on the table name segmented per store
44+
*
45+
* @param ResourceConnection $subject
46+
* @param string $result
47+
* @param string|string[] $modelEntity
48+
*
49+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
50+
*
51+
* @return string
52+
*/
53+
public function afterGetTableName(
54+
\Magento\Framework\App\ResourceConnection $subject,
55+
string $result,
56+
$modelEntity
57+
) {
58+
if (!is_array($modelEntity) && $modelEntity === AbstractAction::MAIN_INDEX_TABLE) {
59+
$catalogCategoryProductDimension = new Dimension(
60+
\Magento\Store\Model\Store::ENTITY,
61+
$this->storeManager->getStore()->getId()
62+
);
63+
64+
$tableName = $this->tableResolver->resolve(
65+
AbstractAction::MAIN_INDEX_TABLE,
66+
[
67+
$catalogCategoryProductDimension
68+
]
69+
);
70+
return $tableName;
71+
}
72+
return $result;
73+
}
74+
}

app/code/Magento/Catalog/Model/Indexer/Category/Product/TableMaintainer.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,19 @@ public function getMainTable(int $storeId)
136136
public function createTablesForStore(int $storeId)
137137
{
138138
$mainTableName = $this->getMainTable($storeId);
139-
$this->createTable($this->getTable(AbstractAction::MAIN_INDEX_TABLE), $mainTableName);
139+
//Create index table for store based on on main replica table
140+
//Using main replica table is necessary for backward capability and TableResolver plugin work
141+
$this->createTable(
142+
$this->getTable(AbstractAction::MAIN_INDEX_TABLE . $this->additionalTableSuffix),
143+
$mainTableName
144+
);
140145

141146
$mainReplicaTableName = $this->getMainTable($storeId) . $this->additionalTableSuffix;
142-
$this->createTable($this->getTable(AbstractAction::MAIN_INDEX_TABLE), $mainReplicaTableName);
147+
//Create replica table for store based on main replica table
148+
$this->createTable(
149+
$this->getTable(AbstractAction::MAIN_INDEX_TABLE . $this->additionalTableSuffix),
150+
$mainReplicaTableName
151+
);
143152
}
144153

145154
/**

app/code/Magento/Catalog/etc/adminhtml/di.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,4 +193,7 @@
193193
<type name="Magento\Eav\Api\AttributeSetRepositoryInterface">
194194
<plugin name="remove_products" type="Magento\Catalog\Plugin\Model\AttributeSetRepository\RemoveProducts"/>
195195
</type>
196+
<type name="Magento\Framework\App\ResourceConnection">
197+
<plugin name="get_catalog_category_product_index_table_name" type="Magento\Catalog\Model\Indexer\Category\Product\Plugin\TableResolver"/>
198+
</type>
196199
</config>

app/code/Magento/Catalog/etc/frontend/di.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,7 @@
7979
<argument name="typeId" xsi:type="string">recently_compared_product</argument>
8080
</arguments>
8181
</virtualType>
82+
<type name="Magento\Framework\App\ResourceConnection">
83+
<plugin name="get_catalog_category_product_index_table_name" type="Magento\Catalog\Model\Indexer\Category\Product\Plugin\TableResolver"/>
84+
</type>
8285
</config>

app/code/Magento/Catalog/etc/webapi_rest/di.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,7 @@
1616
</argument>
1717
</arguments>
1818
</type>
19+
<type name="Magento\Framework\App\ResourceConnection">
20+
<plugin name="get_catalog_category_product_index_table_name" type="Magento\Catalog\Model\Indexer\Category\Product\Plugin\TableResolver"/>
21+
</type>
1922
</config>

app/code/Magento/Catalog/etc/webapi_soap/di.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,7 @@
1515
</argument>
1616
</arguments>
1717
</type>
18+
<type name="Magento\Framework\App\ResourceConnection">
19+
<plugin name="get_catalog_category_product_index_table_name" type="Magento\Catalog\Model\Indexer\Category\Product\Plugin\TableResolver"/>
20+
</type>
1821
</config>

0 commit comments

Comments
 (0)