Skip to content

Commit

Permalink
ENGCOM-8403: Fixed Unable to apply data patch issue after upgrade in …
Browse files Browse the repository at this point in the history
…2.4 #29365 #29804
  • Loading branch information
gabrieldagama authored Feb 4, 2021
2 parents d725ea3 + 281a389 commit 5749410
Showing 1 changed file with 23 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,27 @@ class UpdateUrlKeyForProducts implements DataPatchInterface, PatchVersionInterfa
*/
private $urlProduct;

/**
* @var \Magento\Framework\EntityManager\MetadataPool
*/
private $metadataPool;

/**
* @param ModuleDataSetupInterface $moduleDataSetup
* @param EavSetupFactory $eavSetupFactory
* @param Url $urlProduct
* @param \Magento\Framework\EntityManager\MetadataPool $metadataPool
*/
public function __construct(
ModuleDataSetupInterface $moduleDataSetup,
EavSetupFactory $eavSetupFactory,
Url $urlProduct
Url $urlProduct,
\Magento\Framework\EntityManager\MetadataPool $metadataPool
) {
$this->moduleDataSetup = $moduleDataSetup;
$this->eavSetup = $eavSetupFactory->create(['setup' => $moduleDataSetup]);
$this->urlProduct = $urlProduct;
$this->metadataPool = $metadataPool;
}

/**
Expand All @@ -58,7 +66,7 @@ public function apply()
$table = $this->moduleDataSetup->getTable('catalog_product_entity_varchar');
$select = $this->moduleDataSetup->getConnection()->select()->from(
$table,
['value_id', 'value']
[$this->getProductLinkField(), 'attribute_id', 'store_id', 'value_id', 'value']
)->where(
'attribute_id = ?',
$this->eavSetup->getAttributeId($productTypeId, 'url_key')
Expand Down Expand Up @@ -99,4 +107,17 @@ public function getAliases()
{
return [];
}

/**
* Return product id field name - entity_id|row_id
*
* @return string
* @throws \Exception
*/
private function getProductLinkField()
{
return $this->metadataPool
->getMetadata(\Magento\Catalog\Api\Data\ProductInterface::class)
->getLinkField();
}
}

0 comments on commit 5749410

Please sign in to comment.