Skip to content

Commit

Permalink
ENGCOM-7606: Refactoring create product with several websites and che…
Browse files Browse the repository at this point in the history
…ck url rewrites test #28391
  • Loading branch information
slavvka committed Jun 4, 2020
2 parents 125e788 + 8df804d commit b60e727
Show file tree
Hide file tree
Showing 28 changed files with 712 additions and 425 deletions.
20 changes: 7 additions & 13 deletions app/code/Magento/Bundle/Model/ResourceModel/Indexer/Price.php
Original file line number Diff line number Diff line change
Expand Up @@ -377,8 +377,7 @@ private function prepareBundlePriceByType($priceType, array $dimensions, $entity
]
);

$query = $select->insertFromSelect($this->getBundlePriceTable());
$connection->query($query);
$this->tableMaintainer->insertFromSelect($select, $this->getBundlePriceTable(), []);
}

/**
Expand Down Expand Up @@ -418,8 +417,7 @@ private function calculateBundleOptionPrice($priceTable, $dimensions)
]
);

$query = $select->insertFromSelect($this->getBundleOptionTable());
$connection->query($query);
$this->tableMaintainer->insertFromSelect($select, $this->getBundleOptionTable(), []);

$this->getConnection()->delete($priceTable->getTableName());
$this->applyBundlePrice($priceTable);
Expand Down Expand Up @@ -575,8 +573,7 @@ private function calculateFixedBundleSelectionPrice()
'tier_price' => $tierExpr,
]
);
$query = $select->insertFromSelect($this->getBundleSelectionTable());
$connection->query($query);
$this->tableMaintainer->insertFromSelect($select, $this->getBundleSelectionTable(), []);

$this->applyFixedBundleSelectionPrice();
}
Expand Down Expand Up @@ -627,8 +624,7 @@ private function calculateDynamicBundleSelectionPrice($dimensions)
'tier_price' => $tierExpr,
]
);
$query = $select->insertFromSelect($this->getBundleSelectionTable());
$connection->query($query);
$this->tableMaintainer->insertFromSelect($select, $this->getBundleSelectionTable(), []);
}

/**
Expand Down Expand Up @@ -697,8 +693,7 @@ private function prepareTierPriceIndex($dimensions, $entityIds)
$select->where($this->dimensionToFieldMapper[$dimension->getName()] . ' = ?', $dimension->getValue());
}

$query = $select->insertFromSelect($this->getTable('catalog_product_index_tier_price'));
$connection->query($query);
$this->tableMaintainer->insertFromSelect($select, $this->getTable('catalog_product_index_tier_price'), []);
}

/**
Expand All @@ -725,8 +720,7 @@ private function applyBundlePrice($priceTable): void
]
);

$query = $select->insertFromSelect($priceTable->getTableName());
$this->getConnection()->query($query);
$this->tableMaintainer->insertFromSelect($select, $priceTable->getTableName(), []);
}

/**
Expand Down Expand Up @@ -785,7 +779,7 @@ private function getMainTable($dimensions)
if ($this->fullReindexAction) {
return $this->tableMaintainer->getMainReplicaTable($dimensions);
}
return $this->tableMaintainer->getMainTable($dimensions);
return $this->tableMaintainer->getMainTableByDimensions($dimensions);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ protected function _syncData(array $processIds = [])
}
}

$query = $insertSelect->insertFromSelect($this->tableMaintainer->getMainTable($dimensions));
$query = $insertSelect->insertFromSelect($this->tableMaintainer->getMainTableByDimensions($dimensions));
$this->getConnection()->query($query);
}
return $this;
Expand Down Expand Up @@ -385,7 +385,7 @@ protected function _reindexRows($changedIds = [])
// copy to index
$this->_insertFromTable(
$temporaryTable,
$this->tableMaintainer->getMainTable($dimensions)
$this->tableMaintainer->getMainTableByDimensions($dimensions)
);
}
} else {
Expand All @@ -401,14 +401,16 @@ protected function _reindexRows($changedIds = [])
}

/**
* Delete Index data
*
* @param array $entityIds
* @return void
*/
private function deleteIndexData(array $entityIds)
{
foreach ($this->dimensionCollectionFactory->create() as $dimensions) {
$select = $this->getConnection()->select()->from(
['index_price' => $this->tableMaintainer->getMainTable($dimensions)],
['index_price' => $this->tableMaintainer->getMainTableByDimensions($dimensions)],
null
)->where('index_price.entity_id IN (?)', $entityIds);
$query = $select->deleteFromSelect('index_price');
Expand Down Expand Up @@ -476,7 +478,7 @@ private function getIndexTargetTableByDimension(array $dimensions)
{
$indexTargetTable = $this->getIndexTargetTable();
if ($indexTargetTable === self::getIndexTargetTable()) {
$indexTargetTable = $this->tableMaintainer->getMainTable($dimensions);
$indexTargetTable = $this->tableMaintainer->getMainTableByDimensions($dimensions);
}
if ($indexTargetTable === self::getIndexTargetTable() . '_replica') {
$indexTargetTable = $this->tableMaintainer->getMainReplicaTable($dimensions);
Expand All @@ -497,6 +499,8 @@ protected function getIndexTargetTable()
}

/**
* Get product Id field name
*
* @return string
*/
protected function getProductIdFieldName()
Expand Down Expand Up @@ -533,6 +537,7 @@ private function getProductsTypes(array $changedIds = [])

/**
* Get parent products types
*
* Used for add composite products to reindex if we have only simple products in changed ids set
*
* @param array $productsIds
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ private function switchTables(): void
$mainTablesByDimension = [];

foreach ($this->dimensionCollectionFactory->create() as $dimensions) {
$mainTablesByDimension[] = $this->dimensionTableMaintainer->getMainTable($dimensions);
$mainTablesByDimension[] = $this->dimensionTableMaintainer->getMainTableByDimensions($dimensions);

//Move data from indexers with old realisation
$this->moveDataFromReplicaTableToReplicaTables($dimensions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

/**
* Class to prepare new tables for new indexer mode
*
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class ModeSwitcher implements \Magento\Indexer\Model\ModeSwitcherInterface
{
Expand Down Expand Up @@ -98,7 +100,6 @@ public function switchMode(string $currentMode, string $previousMode)
* Create new tables
*
* @param string $currentMode
*
* @return void
* @throws \Zend_Db_Exception
*/
Expand All @@ -116,7 +117,6 @@ public function createTables(string $currentMode)
*
* @param string $currentMode
* @param string $previousMode
*
* @return void
*/
public function moveData(string $currentMode, string $previousMode)
Expand All @@ -125,17 +125,17 @@ public function moveData(string $currentMode, string $previousMode)
$dimensionsArrayForPreviousMode = $this->getDimensionsArray($previousMode);

foreach ($dimensionsArrayForCurrentMode as $dimensionsForCurrentMode) {
$newTable = $this->tableMaintainer->getMainTable($dimensionsForCurrentMode);
$newTable = $this->tableMaintainer->getMainTableByDimensions($dimensionsForCurrentMode);
if (empty($dimensionsForCurrentMode)) {
// new mode is 'none'
foreach ($dimensionsArrayForPreviousMode as $dimensionsForPreviousMode) {
$oldTable = $this->tableMaintainer->getMainTable($dimensionsForPreviousMode);
$oldTable = $this->tableMaintainer->getMainTableByDimensions($dimensionsForPreviousMode);
$this->insertFromOldTablesToNew($newTable, $oldTable);
}
} else {
// new mode is not 'none'
foreach ($dimensionsArrayForPreviousMode as $dimensionsForPreviousMode) {
$oldTable = $this->tableMaintainer->getMainTable($dimensionsForPreviousMode);
$oldTable = $this->tableMaintainer->getMainTableByDimensions($dimensionsForPreviousMode);
$this->insertFromOldTablesToNew($newTable, $oldTable, $dimensionsForCurrentMode);
}
}
Expand All @@ -146,7 +146,6 @@ public function moveData(string $currentMode, string $previousMode)
* Drop old tables
*
* @param string $previousMode
*
* @return void
*/
public function dropTables(string $previousMode)
Expand All @@ -164,7 +163,6 @@ public function dropTables(string $previousMode)
* Get dimensions array
*
* @param string $mode
*
* @return \Magento\Framework\Indexer\MultiDimensionProvider
*/
private function getDimensionsArray(string $mode): \Magento\Framework\Indexer\MultiDimensionProvider
Expand All @@ -184,7 +182,6 @@ private function getDimensionsArray(string $mode): \Magento\Framework\Indexer\Mu
* @param string $newTable
* @param string $oldTable
* @param Dimension[] $dimensions
*
* @return void
*/
private function insertFromOldTablesToNew(string $newTable, string $oldTable, array $dimensions = [])
Expand Down
Loading

0 comments on commit b60e727

Please sign in to comment.