Here is the php way to do it (and yes, I know you shouldn't use the objectmanager but I'm not going to explain that here). I'm making a one-off script that cleans up the mess from the migration thing. The code below removes the 'Migration_' attribute codes and assigns the lower values originally used, as well as deleting the new defaults. You can use this code as you see fit. The important part is calling the clear()
function so magento doesn't use values from memory instead of reading your changes to the database.
<?php
echo "RUNNING";
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
ini_set('memory_limit', '5G');
error_reporting(E_ALL);
use Magento\Framework\App\Bootstrap;
require 'app/bootstrap.php';
$bootstrap = Bootstrap::create(BP, $_SERVER);
$objectManager = $bootstrap->getObjectManager();
$state = $objectManager->get('Magento\Framework\App\State');
$state->setAreaCode('frontend');
$scb = $objectManager->get('Magento\Framework\Api\SearchCriteriaBuilder');
$typeConfig = $objectManager->create('Magento\Eav\Model\Entity\Type');
$modelConfig = $objectManager->create('Magento\Eav\Model\Config');
$eavConfig = $objectManager->create('Magento\Eav\Api\AttributeSetRepositoryInterface');
$eavSetup = $objectManager->create('Magento\Eav\Setup\EavSetup');
$filter = $scb->addFilter('attribute_set_id',null,'neq')->create();
$list = $eavConfig->getList($filter)->getItems();
foreach ($list as $item) {
$attributeSetName = $item->getAttributeSetName();
$newItemName = explode('Migration_', $attributeSetName);
if (is_array($newItemName) && count($newItemName) > 1) {
$newItemName = $newItemName[1];
if (strpos($item->getAttributeSetName(), 'Migration') !== false) {
// See if attribute set name exists already
// If yes
// See if the attribute set ID is higher or lower
// If lower, delete this one
// If higher, delete found one and save this one.
// If No
// Save attribute set without "Migration_"
foreach ($list as $innerItem) {
if ($item != $innerItem) {
$innerAttributeSetName = $innerItem->getAttributeSetName();
if ($newItemName == $innerAttributeSetName && $innerItem->getEntityTypeId() == $item->getEntityTypeId()) {
if ($innerItem->getAttributeSetId() > $item->getAttributeSetId()) {
$type = $typeConfig->load($item->getEntityTypeId())
->setData('default_attribute_set_id', $item->getAttributeSetId())
->save();
$modelConfig->clear();
$resource = $innerItem->getResource();
$resource->delete($innerItem);
}
}
}
}
$item->setName($newItemName);
$item->save();
}
}
}
?>