Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed Unable to apply data patch issue after upgrade in 2.4 #29365 #29804

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
}
}