Skip to content

Commit 604c2cf

Browse files
committed
MC-18954: Nightly build jobs were failing lately after un-skipping tests in MC-5777
1 parent 358ea7d commit 604c2cf

File tree

1 file changed

+40
-13
lines changed

1 file changed

+40
-13
lines changed

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

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,19 @@
88

99
use Magento\CatalogRule\Model\Indexer\IndexerTableSwapperInterface as TableSwapper;
1010
use Magento\Catalog\Model\ResourceModel\Indexer\ActiveTableSwitcher;
11-
use Magento\Framework\App\ObjectManager;
11+
use Magento\CatalogRule\Model\Rule;
12+
use Magento\Framework\App\Config\ScopeConfigInterface;
13+
use Magento\Framework\App\ResourceConnection;
14+
use Magento\Framework\Stdlib\DateTime\TimezoneInterface;
15+
use Magento\Store\Model\ScopeInterface;
1216

1317
/**
1418
* Reindex rule relations with products.
1519
*/
1620
class ReindexRuleProduct
1721
{
1822
/**
19-
* @var \Magento\Framework\App\ResourceConnection
23+
* @var ResourceConnection
2024
*/
2125
private $resource;
2226

@@ -31,33 +35,48 @@ class ReindexRuleProduct
3135
private $tableSwapper;
3236

3337
/**
34-
* @param \Magento\Framework\App\ResourceConnection $resource
38+
* @var ScopeConfigInterface
39+
*/
40+
private $scopeConfig;
41+
42+
/**
43+
* @var TimezoneInterface
44+
*/
45+
private $localeDate;
46+
47+
/**
48+
* @param ResourceConnection $resource
3549
* @param ActiveTableSwitcher $activeTableSwitcher
36-
* @param TableSwapper|null $tableSwapper
50+
* @param TableSwapper $tableSwapper
51+
* @param ScopeConfigInterface $scopeConfig
52+
* @param TimezoneInterface $localeDate
3753
*/
3854
public function __construct(
39-
\Magento\Framework\App\ResourceConnection $resource,
55+
ResourceConnection $resource,
4056
ActiveTableSwitcher $activeTableSwitcher,
41-
TableSwapper $tableSwapper = null
57+
TableSwapper $tableSwapper,
58+
ScopeConfigInterface $scopeConfig,
59+
TimezoneInterface $localeDate
4260
) {
4361
$this->resource = $resource;
4462
$this->activeTableSwitcher = $activeTableSwitcher;
45-
$this->tableSwapper = $tableSwapper ??
46-
ObjectManager::getInstance()->get(TableSwapper::class);
63+
$this->tableSwapper = $tableSwapper;
64+
$this->scopeConfig = $scopeConfig;
65+
$this->localeDate = $localeDate;
4766
}
4867

4968
/**
5069
* Reindex information about rule relations with products.
5170
*
52-
* @param \Magento\CatalogRule\Model\Rule $rule
71+
* @param Rule $rule
5372
* @param int $batchCount
5473
* @param bool $useAdditionalTable
5574
* @return bool
5675
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
5776
* @SuppressWarnings(PHPMD.NPathComplexity)
5877
*/
5978
public function execute(
60-
\Magento\CatalogRule\Model\Rule $rule,
79+
Rule $rule,
6180
$batchCount,
6281
$useAdditionalTable = false
6382
) {
@@ -84,9 +103,6 @@ public function execute(
84103

85104
$ruleId = $rule->getId();
86105
$customerGroupIds = $rule->getCustomerGroupIds();
87-
$fromTime = strtotime($rule->getFromDate());
88-
$toTime = strtotime($rule->getToDate());
89-
$toTime = $toTime ? $toTime + \Magento\CatalogRule\Model\Indexer\IndexBuilder::SECONDS_IN_DAY - 1 : 0;
90106
$sortOrder = (int)$rule->getSortOrder();
91107
$actionOperator = $rule->getSimpleAction();
92108
$actionAmount = $rule->getDiscountAmount();
@@ -99,6 +115,16 @@ public function execute(
99115
if (empty($validationByWebsite[$websiteId])) {
100116
continue;
101117
}
118+
119+
$scopeTzPath = $this->localeDate->getDefaultTimezonePath();
120+
$scopeTz = new \DateTimeZone(
121+
$this->scopeConfig->getValue($scopeTzPath, ScopeInterface::SCOPE_WEBSITE, $websiteId)
122+
);
123+
$fromTime = (new \DateTime($rule->getFromDate(), $scopeTz))->getTimestamp();
124+
$toTime = $rule->getToDate()
125+
? (new \DateTime($rule->getToDate(), $scopeTz))->getTimestamp() + IndexBuilder::SECONDS_IN_DAY - 1
126+
: 0;
127+
102128
foreach ($customerGroupIds as $customerGroupId) {
103129
$rows[] = [
104130
'rule_id' => $ruleId,
@@ -123,6 +149,7 @@ public function execute(
123149
if (!empty($rows)) {
124150
$connection->insertMultiple($indexTable, $rows);
125151
}
152+
126153
return true;
127154
}
128155
}

0 commit comments

Comments
 (0)