Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ReindexRuleGroupWebsite.php
Go to the documentation of this file.
1 <?php
8 
12 
17 {
21  private $dateTime;
22 
26  private $resource;
27 
31  private $catalogRuleGroupWebsiteColumnsList = ['rule_id', 'customer_group_id', 'website_id'];
32 
36  private $activeTableSwitcher;
37 
41  private $tableSwapper;
42 
49  public function __construct(
50  \Magento\Framework\Stdlib\DateTime\DateTime $dateTime,
51  \Magento\Framework\App\ResourceConnection $resource,
52  ActiveTableSwitcher $activeTableSwitcher,
53  TableSwapper $tableSwapper = null
54  ) {
55  $this->dateTime = $dateTime;
56  $this->resource = $resource;
57  $this->activeTableSwitcher = $activeTableSwitcher;
58  $this->tableSwapper = $tableSwapper ??
59  ObjectManager::getInstance()->get(TableSwapper::class);
60  }
61 
68  public function execute($useAdditionalTable = false)
69  {
70  $connection = $this->resource->getConnection();
71  $timestamp = $this->dateTime->gmtTimestamp();
72 
73  $indexTable = $this->resource->getTableName('catalogrule_group_website');
74  $ruleProductTable = $this->resource->getTableName('catalogrule_product');
75  if ($useAdditionalTable) {
76  $indexTable = $this->resource->getTableName(
77  $this->tableSwapper->getWorkingTableName('catalogrule_group_website')
78  );
79  $ruleProductTable = $this->resource->getTableName(
80  $this->tableSwapper->getWorkingTableName('catalogrule_product')
81  );
82  }
83 
84  $connection->delete($indexTable);
85  $select = $connection->select()->distinct(
86  true
87  )->from(
88  $ruleProductTable,
89  $this->catalogRuleGroupWebsiteColumnsList
90  )->where(
91  "{$timestamp} >= from_time AND (({$timestamp} <= to_time AND to_time > 0) OR to_time = 0)"
92  );
93  $query = $select->insertFromSelect($indexTable, $this->catalogRuleGroupWebsiteColumnsList);
94  $connection->query($query);
95  return true;
96  }
97 }
__construct(\Magento\Framework\Stdlib\DateTime\DateTime $dateTime, \Magento\Framework\App\ResourceConnection $resource, ActiveTableSwitcher $activeTableSwitcher, TableSwapper $tableSwapper=null)
$resource
Definition: bulk.php:12
$connection
Definition: bulk.php:13
$dateTime