Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save tete2soja/cdb31eb26147b54df84cee062667e177 to your computer and use it in GitHub Desktop.
Save tete2soja/cdb31eb26147b54df84cee062667e177 to your computer and use it in GitHub Desktop.
m242-wrap-price-indexer-with-transaction.patch
diff --git a/Model/Indexer/Product/Price/AbstractAction.php b/Model/Indexer/Product/Price/AbstractAction.php
index e69ab50..ce0c0f6 100644
--- a/Model/Indexer/Product/Price/AbstractAction.php
+++ b/Model/Indexer/Product/Price/AbstractAction.php
@@ -396,31 +396,39 @@ abstract class AbstractAction
},
ARRAY_FILTER_USE_KEY
);
- if (empty($typeIndexers)) {
- $this->deleteIndexData($changedIds);
- return $changedIds;
- }
- foreach ($typeIndexers as $productType => $indexer) {
- $entityIds = $productsTypes[$productType];
- if ($indexer instanceof DimensionalIndexerInterface) {
- foreach ($this->dimensionCollectionFactory->create() as $dimensions) {
- $this->tableMaintainer->createMainTmpTable($dimensions);
- $temporaryTable = $this->tableMaintainer->getMainTmpTable($dimensions);
- $this->_emptyTable($temporaryTable);
- $indexer->executeByDimensions($dimensions, \SplFixedArray::fromArray($entityIds, false));
- $mainTable = $this->tableMaintainer->getMainTableByDimensions($dimensions);
- $this->_insertFromTable($temporaryTable, $mainTable);
- $this->deleteOutdatedData($entityIds, $temporaryTable, $mainTable);
- }
- } else {
- // handle 3d-party indexers for backward compatibility
+ try {
+ $this->getConnection()->beginTransaction();
+ if (empty($typeIndexers)) {
$this->deleteIndexData($changedIds);
- $this->_emptyTable($this->_defaultIndexerResource->getIdxTable());
- $this->_copyRelationIndexData($entityIds);
- $indexer->reindexEntity($entityIds);
- $this->_syncData($entityIds);
+ return $changedIds;
+ }
+
+ foreach ($typeIndexers as $productType => $indexer) {
+ $entityIds = $productsTypes[$productType];
+ if ($indexer instanceof DimensionalIndexerInterface) {
+ foreach ($this->dimensionCollectionFactory->create() as $dimensions) {
+ $this->tableMaintainer->createMainTmpTable($dimensions);
+ $temporaryTable = $this->tableMaintainer->getMainTmpTable($dimensions);
+ $this->_emptyTable($temporaryTable);
+ $indexer->executeByDimensions($dimensions, \SplFixedArray::fromArray($entityIds, false));
+ $mainTable = $this->tableMaintainer->getMainTableByDimensions($dimensions);
+ $this->_insertFromTable($temporaryTable, $mainTable);
+ $this->deleteOutdatedData($entityIds, $temporaryTable, $mainTable);
+ }
+ } else {
+ // handle 3d-party indexers for backward compatibility
+ $this->deleteIndexData($changedIds);
+ $this->_emptyTable($this->_defaultIndexerResource->getIdxTable());
+ $this->_copyRelationIndexData($entityIds);
+ $indexer->reindexEntity($entityIds);
+ $this->_syncData($entityIds);
+ }
}
+ $this->getConnection()->commit();
+ } catch (\Exception $e) {
+ $this->getConnection()->rollBack();
+ throw $e;
}
return $changedIds;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment