Skip to content

Commit c614f89

Browse files
committed
remove unused code
1 parent c7def24 commit c614f89

File tree

1 file changed

+39
-128
lines changed

1 file changed

+39
-128
lines changed

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

Lines changed: 39 additions & 128 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,21 @@
77
namespace Magento\CatalogRule\Model\Indexer;
88

99
use Magento\Catalog\Model\Product;
10+
use Magento\Catalog\Model\ProductFactory;
11+
use Magento\Catalog\Model\ResourceModel\Indexer\ActiveTableSwitcher;
1012
use Magento\CatalogRule\Model\ResourceModel\Rule\Collection as RuleCollection;
1113
use Magento\CatalogRule\Model\ResourceModel\Rule\CollectionFactory as RuleCollectionFactory;
1214
use Magento\CatalogRule\Model\Rule;
15+
use Magento\Eav\Model\Config;
1316
use Magento\Framework\App\ObjectManager;
17+
use Magento\Framework\App\ResourceConnection;
18+
use Magento\Framework\Exception\LocalizedException;
1419
use Magento\Framework\Pricing\PriceCurrencyInterface;
1520
use Magento\CatalogRule\Model\Indexer\IndexBuilder\ProductLoader;
1621
use Magento\CatalogRule\Model\Indexer\IndexerTableSwapperInterface as TableSwapper;
22+
use Magento\Framework\Stdlib\DateTime;
23+
use Magento\Store\Model\StoreManagerInterface;
24+
use Psr\Log\LoggerInterface;
1725

1826
/**
1927
* Catalog rule index builder
@@ -46,12 +54,12 @@ class IndexBuilder
4654
protected $_catalogRuleGroupWebsiteColumnsList = ['rule_id', 'customer_group_id', 'website_id'];
4755

4856
/**
49-
* @var \Magento\Framework\App\ResourceConnection
57+
* @var ResourceConnection
5058
*/
5159
protected $resource;
5260

5361
/**
54-
* @var \Magento\Store\Model\StoreManagerInterface
62+
* @var StoreManagerInterface
5563
*/
5664
protected $storeManager;
5765

@@ -61,7 +69,7 @@ class IndexBuilder
6169
protected $ruleCollectionFactory;
6270

6371
/**
64-
* @var \Psr\Log\LoggerInterface
72+
* @var LoggerInterface
6573
*/
6674
protected $logger;
6775

@@ -71,22 +79,22 @@ class IndexBuilder
7179
protected $priceCurrency;
7280

7381
/**
74-
* @var \Magento\Eav\Model\Config
82+
* @var Config
7583
*/
7684
protected $eavConfig;
7785

7886
/**
79-
* @var \Magento\Framework\Stdlib\DateTime
87+
* @var DateTime
8088
*/
8189
protected $dateFormat;
8290

8391
/**
84-
* @var \Magento\Framework\Stdlib\DateTime\DateTime
92+
* @var DateTime\DateTime
8593
*/
8694
protected $dateTime;
8795

8896
/**
89-
* @var \Magento\Catalog\Model\ProductFactory
97+
* @var ProductFactory
9098
*/
9199
protected $productFactory;
92100

@@ -135,61 +143,52 @@ class IndexBuilder
135143
*/
136144
private $pricesPersistor;
137145

138-
/**
139-
* @var \Magento\Catalog\Model\ResourceModel\Indexer\ActiveTableSwitcher
140-
*/
141-
private $activeTableSwitcher;
142-
143146
/**
144147
* @var TableSwapper
145148
*/
146149
private $tableSwapper;
147150

148-
/**
149-
* @var ProductLoader
150-
*/
151-
private $productLoader;
152-
153151
/**
154152
* @param RuleCollectionFactory $ruleCollectionFactory
155153
* @param PriceCurrencyInterface $priceCurrency
156-
* @param \Magento\Framework\App\ResourceConnection $resource
157-
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
158-
* @param \Psr\Log\LoggerInterface $logger
159-
* @param \Magento\Eav\Model\Config $eavConfig
160-
* @param \Magento\Framework\Stdlib\DateTime $dateFormat
161-
* @param \Magento\Framework\Stdlib\DateTime\DateTime $dateTime
162-
* @param \Magento\Catalog\Model\ProductFactory $productFactory
154+
* @param ResourceConnection $resource
155+
* @param StoreManagerInterface $storeManager
156+
* @param LoggerInterface $logger
157+
* @param Config $eavConfig
158+
* @param DateTime $dateFormat
159+
* @param DateTime\DateTime $dateTime
160+
* @param ProductFactory $productFactory
163161
* @param int $batchCount
164162
* @param ProductPriceCalculator|null $productPriceCalculator
165163
* @param ReindexRuleProduct|null $reindexRuleProduct
166164
* @param ReindexRuleGroupWebsite|null $reindexRuleGroupWebsite
167165
* @param RuleProductsSelectBuilder|null $ruleProductsSelectBuilder
168166
* @param ReindexRuleProductPrice|null $reindexRuleProductPrice
169167
* @param RuleProductPricesPersistor|null $pricesPersistor
170-
* @param \Magento\Catalog\Model\ResourceModel\Indexer\ActiveTableSwitcher|null $activeTableSwitcher
168+
* @param ActiveTableSwitcher|null $activeTableSwitcher
171169
* @param ProductLoader|null $productLoader
172170
* @param TableSwapper|null $tableSwapper
173171
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
172+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
174173
*/
175174
public function __construct(
176175
RuleCollectionFactory $ruleCollectionFactory,
177176
PriceCurrencyInterface $priceCurrency,
178-
\Magento\Framework\App\ResourceConnection $resource,
179-
\Magento\Store\Model\StoreManagerInterface $storeManager,
180-
\Psr\Log\LoggerInterface $logger,
181-
\Magento\Eav\Model\Config $eavConfig,
182-
\Magento\Framework\Stdlib\DateTime $dateFormat,
183-
\Magento\Framework\Stdlib\DateTime\DateTime $dateTime,
184-
\Magento\Catalog\Model\ProductFactory $productFactory,
177+
ResourceConnection $resource,
178+
StoreManagerInterface $storeManager,
179+
LoggerInterface $logger,
180+
Config $eavConfig,
181+
DateTime $dateFormat,
182+
DateTime\DateTime $dateTime,
183+
ProductFactory $productFactory,
185184
$batchCount = 1000,
186185
ProductPriceCalculator $productPriceCalculator = null,
187186
ReindexRuleProduct $reindexRuleProduct = null,
188187
ReindexRuleGroupWebsite $reindexRuleGroupWebsite = null,
189188
RuleProductsSelectBuilder $ruleProductsSelectBuilder = null,
190189
ReindexRuleProductPrice $reindexRuleProductPrice = null,
191190
RuleProductPricesPersistor $pricesPersistor = null,
192-
\Magento\Catalog\Model\ResourceModel\Indexer\ActiveTableSwitcher $activeTableSwitcher = null,
191+
ActiveTableSwitcher $activeTableSwitcher = null,
193192
ProductLoader $productLoader = null,
194193
TableSwapper $tableSwapper = null
195194
) {
@@ -223,12 +222,6 @@ public function __construct(
223222
$this->pricesPersistor = $pricesPersistor ?? ObjectManager::getInstance()->get(
224223
RuleProductPricesPersistor::class
225224
);
226-
$this->activeTableSwitcher = $activeTableSwitcher ?? ObjectManager::getInstance()->get(
227-
\Magento\Catalog\Model\ResourceModel\Indexer\ActiveTableSwitcher::class
228-
);
229-
$this->productLoader = $productLoader ?? ObjectManager::getInstance()->get(
230-
ProductLoader::class
231-
);
232225
$this->tableSwapper = $tableSwapper ??
233226
ObjectManager::getInstance()->get(TableSwapper::class);
234227
}
@@ -237,6 +230,7 @@ public function __construct(
237230
* Reindex by id
238231
*
239232
* @param int $id
233+
* @throws LocalizedException
240234
* @return void
241235
* @api
242236
*/
@@ -246,7 +240,7 @@ public function reindexById($id)
246240
$this->doReindexByIds([$id]);
247241
} catch (\Exception $e) {
248242
$this->critical($e);
249-
throw new \Magento\Framework\Exception\LocalizedException(
243+
throw new LocalizedException(
250244
__("Catalog rule indexing failed. See details in exception log.")
251245
);
252246
}
@@ -256,7 +250,7 @@ public function reindexById($id)
256250
* Reindex by ids
257251
*
258252
* @param array $ids
259-
* @throws \Magento\Framework\Exception\LocalizedException
253+
* @throws LocalizedException
260254
* @return void
261255
* @api
262256
*/
@@ -266,7 +260,7 @@ public function reindexByIds(array $ids)
266260
$this->doReindexByIds($ids);
267261
} catch (\Exception $e) {
268262
$this->critical($e);
269-
throw new \Magento\Framework\Exception\LocalizedException(
263+
throw new LocalizedException(
270264
__("Catalog rule indexing failed. See details in exception log.")
271265
);
272266
}
@@ -300,7 +294,7 @@ protected function doReindexByIds($ids)
300294
/**
301295
* Full reindex
302296
*
303-
* @throws \Magento\Framework\Exception\LocalizedException
297+
* @throws LocalizedException
304298
* @return void
305299
* @api
306300
*/
@@ -310,7 +304,7 @@ public function reindexFull()
310304
$this->doReindexFull();
311305
} catch (\Exception $e) {
312306
$this->critical($e);
313-
throw new \Magento\Framework\Exception\LocalizedException(
307+
throw new LocalizedException(
314308
__("Catalog rule indexing failed. See details in exception log.")
315309
);
316310
}
@@ -375,65 +369,6 @@ protected function cleanByIds($productIds)
375369
$this->cleanProductPriceIndex($productIds);
376370
}
377371

378-
/**
379-
* Assign product to rule
380-
*
381-
* @param Rule $rule
382-
* @param int $productEntityId
383-
* @param array $websiteIds
384-
* @return void
385-
* @throws \Exception
386-
* @deprecated
387-
* @see ReindexRuleProduct::execute
388-
*/
389-
private function assignProductToRule(Rule $rule, int $productEntityId, array $websiteIds): void
390-
{
391-
$ruleId = (int) $rule->getId();
392-
$ruleProductTable = $this->getTable('catalogrule_product');
393-
$this->connection->delete(
394-
$ruleProductTable,
395-
[
396-
'rule_id = ?' => $ruleId,
397-
'product_id = ?' => $productEntityId,
398-
]
399-
);
400-
401-
$customerGroupIds = $rule->getCustomerGroupIds();
402-
$fromTime = strtotime($rule->getFromDate());
403-
$toTime = strtotime($rule->getToDate());
404-
$toTime = $toTime ? $toTime + self::SECONDS_IN_DAY - 1 : 0;
405-
$sortOrder = (int)$rule->getSortOrder();
406-
$actionOperator = $rule->getSimpleAction();
407-
$actionAmount = $rule->getDiscountAmount();
408-
$actionStop = $rule->getStopRulesProcessing();
409-
410-
$rows = [];
411-
foreach ($websiteIds as $websiteId) {
412-
foreach ($customerGroupIds as $customerGroupId) {
413-
$rows[] = [
414-
'rule_id' => $ruleId,
415-
'from_time' => $fromTime,
416-
'to_time' => $toTime,
417-
'website_id' => $websiteId,
418-
'customer_group_id' => $customerGroupId,
419-
'product_id' => $productEntityId,
420-
'action_operator' => $actionOperator,
421-
'action_amount' => $actionAmount,
422-
'action_stop' => $actionStop,
423-
'sort_order' => $sortOrder,
424-
];
425-
426-
if (count($rows) == $this->batchCount) {
427-
$this->connection->insertMultiple($ruleProductTable, $rows);
428-
$rows = [];
429-
}
430-
}
431-
}
432-
if ($rows) {
433-
$this->connection->insertMultiple($ruleProductTable, $rows);
434-
}
435-
}
436-
437372
/**
438373
* Apply rule
439374
*
@@ -457,30 +392,6 @@ protected function applyRule(Rule $rule, $product)
457392
return $this;
458393
}
459394

460-
/**
461-
* Apply rules
462-
*
463-
* @param RuleCollection $ruleCollection
464-
* @param Product $product
465-
* @deprecated
466-
* @see ReindexRuleProduct::execute
467-
* @return void
468-
*/
469-
private function applyRules(RuleCollection $ruleCollection, Product $product): void
470-
{
471-
foreach ($ruleCollection as $rule) {
472-
if (!$rule->validate($product)) {
473-
continue;
474-
}
475-
476-
$websiteIds = array_intersect($product->getWebsiteIds(), $rule->getWebsiteIds());
477-
$this->assignProductToRule($rule, $product->getId(), $websiteIds);
478-
}
479-
480-
$this->cleanProductPriceIndex([$product->getId()]);
481-
$this->reindexRuleProductPrice->execute($this->batchCount, $product->getId());
482-
}
483-
484395
/**
485396
* Retrieve table name
486397
*
@@ -580,7 +491,7 @@ protected function calcRuleProductPrice($ruleData, $productData = null)
580491
* @param int $websiteId
581492
* @param Product|null $product
582493
* @return \Zend_Db_Statement_Interface
583-
* @throws \Magento\Framework\Exception\LocalizedException
494+
* @throws LocalizedException
584495
* @deprecated 100.2.0
585496
* @see RuleProductsSelectBuilder::build
586497
*/

0 commit comments

Comments
 (0)