12
12
use Magento \Framework \App \ObjectManager ;
13
13
use Magento \Framework \Pricing \PriceCurrencyInterface ;
14
14
use Magento \CatalogRule \Model \Indexer \IndexBuilder \ProductLoader ;
15
+ use Magento \CatalogRule \Model \Indexer \IndexerTableSwapperInterface as TableSwapper ;
15
16
16
17
/**
17
18
* @api
@@ -132,9 +133,9 @@ class IndexBuilder
132
133
private $ pricesPersistor ;
133
134
134
135
/**
135
- * @var \Magento\Catalog\Model\ResourceModel\Indexer\ActiveTableSwitcher
136
+ * @var TableSwapper
136
137
*/
137
- private $ activeTableSwitcher ;
138
+ private $ tableSwapper ;
138
139
139
140
/**
140
141
* @var ProductLoader
@@ -160,7 +161,9 @@ class IndexBuilder
160
161
* @param RuleProductPricesPersistor|null $pricesPersistor
161
162
* @param \Magento\Catalog\Model\ResourceModel\Indexer\ActiveTableSwitcher|null $activeTableSwitcher
162
163
* @param ProductLoader|null $productLoader
164
+ * @param TableSwapper|null $tableSwapper
163
165
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
166
+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)
164
167
*/
165
168
public function __construct (
166
169
RuleCollectionFactory $ ruleCollectionFactory ,
@@ -180,7 +183,8 @@ public function __construct(
180
183
ReindexRuleProductPrice $ reindexRuleProductPrice = null ,
181
184
RuleProductPricesPersistor $ pricesPersistor = null ,
182
185
\Magento \Catalog \Model \ResourceModel \Indexer \ActiveTableSwitcher $ activeTableSwitcher = null ,
183
- ProductLoader $ productLoader = null
186
+ ProductLoader $ productLoader = null ,
187
+ TableSwapper $ tableSwapper = null
184
188
) {
185
189
$ this ->resource = $ resource ;
186
190
$ this ->connection = $ resource ->getConnection ();
@@ -212,12 +216,11 @@ public function __construct(
212
216
$ this ->pricesPersistor = $ pricesPersistor ?? ObjectManager::getInstance ()->get (
213
217
RuleProductPricesPersistor::class
214
218
);
215
- $ this ->activeTableSwitcher = $ activeTableSwitcher ?? ObjectManager::getInstance ()->get (
216
- \Magento \Catalog \Model \ResourceModel \Indexer \ActiveTableSwitcher::class
217
- );
218
219
$ this ->productLoader = $ productLoader ?? ObjectManager::getInstance ()->get (
219
220
ProductLoader::class
220
221
);
222
+ $ this ->tableSwapper = $ tableSwapper ??
223
+ ObjectManager::getInstance ()->get (TableSwapper::class);
221
224
}
222
225
223
226
/**
@@ -296,22 +299,14 @@ public function reindexFull()
296
299
*/
297
300
protected function doReindexFull ()
298
301
{
299
- $ this ->connection ->truncateTable (
300
- $ this ->getTable ($ this ->activeTableSwitcher ->getAdditionalTableName ('catalogrule_product ' ))
301
- );
302
- $ this ->connection ->truncateTable (
303
- $ this ->getTable ($ this ->activeTableSwitcher ->getAdditionalTableName ('catalogrule_product_price ' ))
304
- );
305
-
306
302
foreach ($ this ->getAllRules () as $ rule ) {
307
303
$ this ->reindexRuleProduct ->execute ($ rule , $ this ->batchCount , true );
308
304
}
309
305
310
306
$ this ->reindexRuleProductPrice ->execute ($ this ->batchCount , null , true );
311
307
$ this ->reindexRuleGroupWebsite ->execute (true );
312
308
313
- $ this ->activeTableSwitcher ->switchTable (
314
- $ this ->connection ,
309
+ $ this ->tableSwapper ->swapIndexTables (
315
310
[
316
311
$ this ->getTable ('catalogrule_product ' ),
317
312
$ this ->getTable ('catalogrule_product_price ' ),
0 commit comments