Skip to content

Commit 0cebdfa

Browse files
ENGCOM-5307: Resolve issue with improper EAV attribute join statement #23100
- Merge Pull Request #23100 from udovicic/magento2:bugfix/flat-indexer-memory-issue - Merged commits: 1. 0a11ce5
2 parents ef49ac6 + 0a11ce5 commit 0cebdfa

File tree

1 file changed

+20
-3
lines changed
  • app/code/Magento/Catalog/Model/Indexer/Product/Flat/Action

1 file changed

+20
-3
lines changed

app/code/Magento/Catalog/Model/Indexer/Product/Flat/Action/Eraser.php

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
use Magento\Framework\App\ResourceConnection;
1111
use Magento\Catalog\Model\Product\Attribute\Source\Status;
12+
use Magento\Framework\EntityManager\MetadataPool;
1213
use Magento\Store\Model\Store;
1314

1415
/**
@@ -31,19 +32,28 @@ class Eraser
3132
*/
3233
protected $storeManager;
3334

35+
/**
36+
* @var MetadataPool
37+
*/
38+
private $metadataPool;
39+
3440
/**
3541
* @param \Magento\Framework\App\ResourceConnection $resource
3642
* @param \Magento\Catalog\Helper\Product\Flat\Indexer $productHelper
3743
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
44+
* @param MetadataPool|null $metadataPool
3845
*/
3946
public function __construct(
4047
\Magento\Framework\App\ResourceConnection $resource,
4148
\Magento\Catalog\Helper\Product\Flat\Indexer $productHelper,
42-
\Magento\Store\Model\StoreManagerInterface $storeManager
49+
\Magento\Store\Model\StoreManagerInterface $storeManager,
50+
MetadataPool $metadataPool = null
4351
) {
4452
$this->productIndexerHelper = $productHelper;
4553
$this->connection = $resource->getConnection();
4654
$this->storeManager = $storeManager;
55+
$this->metadataPool = $metadataPool ?:
56+
\Magento\Framework\App\ObjectManager::getInstance()->get(MetadataPool::class);
4757
}
4858

4959
/**
@@ -81,17 +91,24 @@ public function removeDisabledProducts(array &$ids, $storeId)
8191
/* @var $statusAttribute \Magento\Eav\Model\Entity\Attribute */
8292
$statusAttribute = $this->productIndexerHelper->getAttribute('status');
8393

94+
/** @var \Magento\Framework\EntityManager\EntityMetadataInterface $metadata */
95+
$metadata = $this->metadataPool->getMetadata(\Magento\Catalog\Api\Data\ProductInterface::class);
96+
8497
$select = $this->getSelectForProducts($ids);
8598
$select->joinLeft(
8699
['status_global_attr' => $statusAttribute->getBackendTable()],
87100
' status_global_attr.attribute_id = ' . (int)$statusAttribute->getAttributeId()
88-
. ' AND status_global_attr.store_id = ' . Store::DEFAULT_STORE_ID,
101+
. ' AND status_global_attr.store_id = ' . Store::DEFAULT_STORE_ID
102+
. ' AND status_global_attr.' . $statusAttribute->getEntityIdField() . '='
103+
. 'product_table.' . $metadata->getLinkField(),
89104
[]
90105
);
91106
$select->joinLeft(
92107
['status_attr' => $statusAttribute->getBackendTable()],
93108
' status_attr.attribute_id = ' . (int)$statusAttribute->getAttributeId()
94-
. ' AND status_attr.store_id = ' . $storeId,
109+
. ' AND status_attr.store_id = ' . $storeId
110+
. ' AND status_attr.' . $statusAttribute->getEntityIdField() . '='
111+
. 'product_table.' . $metadata->getLinkField(),
95112
[]
96113
);
97114
$select->where('IFNULL(status_attr.value, status_global_attr.value) = ?', Status::STATUS_DISABLED);

0 commit comments

Comments
 (0)