dateTime = $dateTime; $this->resource = $resource; $this->activeTableSwitcher = $activeTableSwitcher; $this->tableSwapper = $tableSwapper ?? ObjectManager::getInstance()->get(TableSwapper::class); } /** * Prepare and persist information about rule relations with customer groups and websites to index table. * * @param bool $useAdditionalTable * @return bool */ public function execute($useAdditionalTable = false) { $connection = $this->resource->getConnection(); $timestamp = $this->dateTime->gmtTimestamp(); $indexTable = $this->resource->getTableName('catalogrule_group_website'); $ruleProductTable = $this->resource->getTableName('catalogrule_product'); if ($useAdditionalTable) { $indexTable = $this->resource->getTableName( $this->tableSwapper->getWorkingTableName('catalogrule_group_website') ); $ruleProductTable = $this->resource->getTableName( $this->tableSwapper->getWorkingTableName('catalogrule_product') ); } $connection->delete($indexTable); $select = $connection->select()->distinct( true )->from( $ruleProductTable, $this->catalogRuleGroupWebsiteColumnsList )->where( "{$timestamp} >= from_time AND (({$timestamp} <= to_time AND to_time > 0) OR to_time = 0)" ); $query = $select->insertFromSelect($indexTable, $this->catalogRuleGroupWebsiteColumnsList); $connection->query($query); return true; } }