Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'magento2/2.4-develop' into unlock-admin…
…-user
- Loading branch information
Showing
76 changed files
with
1,253 additions
and
469 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
app/code/Magento/Catalog/Setup/Patch/Data/UpdateMultiselectAttributesBackendTypes.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
namespace Magento\Catalog\Setup\Patch\Data; | ||
|
||
use Magento\Catalog\Model\Product; | ||
use Magento\Eav\Setup\EavSetup; | ||
use Magento\Eav\Setup\EavSetupFactory; | ||
use Magento\Framework\Exception\LocalizedException; | ||
use Magento\Framework\Setup\ModuleDataSetupInterface; | ||
use Magento\Framework\Setup\Patch\DataPatchInterface; | ||
|
||
class UpdateMultiselectAttributesBackendTypes implements DataPatchInterface | ||
{ | ||
/** | ||
* @var ModuleDataSetupInterface | ||
*/ | ||
private $dataSetup; | ||
/** | ||
* @var EavSetupFactory | ||
*/ | ||
private $eavSetupFactory; | ||
|
||
/** | ||
* MigrateMultiselectAttributesData constructor. | ||
* @param ModuleDataSetupInterface $dataSetup | ||
* @param EavSetupFactory $eavSetupFactory | ||
*/ | ||
public function __construct( | ||
ModuleDataSetupInterface $dataSetup, | ||
EavSetupFactory $eavSetupFactory | ||
) { | ||
$this->dataSetup = $dataSetup; | ||
$this->eavSetupFactory = $eavSetupFactory; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public static function getDependencies() | ||
{ | ||
return []; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function getAliases() | ||
{ | ||
return []; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function apply() | ||
{ | ||
$this->dataSetup->startSetup(); | ||
|
||
$connection = $this->dataSetup->getConnection(); | ||
$attributeTable = $connection->getTableName('eav_attribute'); | ||
/** @var EavSetup $eavSetup */ | ||
$eavSetup = $this->eavSetupFactory->create(['setup' => $this->dataSetup]); | ||
$entityTypeId = $eavSetup->getEntityTypeId(Product::ENTITY); | ||
$attributesToMigrate = $connection->fetchCol( | ||
$connection | ||
->select() | ||
->from($attributeTable, ['attribute_id']) | ||
->where('entity_type_id = ?', $entityTypeId) | ||
->where('backend_type = ?', 'varchar') | ||
->where('frontend_input = ?', 'multiselect') | ||
); | ||
|
||
$varcharTable = $connection->getTableName('catalog_product_entity_varchar'); | ||
$textTable = $connection->getTableName('catalog_product_entity_text'); | ||
$varcharTableDataSql = $connection | ||
->select() | ||
->from($varcharTable) | ||
->where('attribute_id in (?)', $attributesToMigrate); | ||
$dataToMigrate = array_map(static function ($row) { | ||
$row['value_id'] = null; | ||
return $row; | ||
}, $connection->fetchAll($varcharTableDataSql)); | ||
|
||
foreach (array_chunk($dataToMigrate, 2000) as $dataChunk) { | ||
$connection->insertMultiple($textTable, $dataChunk); | ||
} | ||
|
||
$connection->query($connection->deleteFromSelect($varcharTableDataSql, $varcharTable)); | ||
|
||
foreach ($attributesToMigrate as $attributeId) { | ||
$eavSetup->updateAttribute($entityTypeId, $attributeId, 'backend_type', 'text'); | ||
} | ||
|
||
$this->dataSetup->endSetup(); | ||
|
||
return $this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.