Files
esun3d/app/code/Esun/Translation/Setup/Patch/Data/MigrateOldConfig.php
T
2026-09-15 10:35:56 +08:00

70 lines
2.0 KiB
PHP

<?php
declare(strict_types=1);
namespace Esun\Translation\Setup\Patch\Data;
use Magento\Framework\App\ResourceConnection;
use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Framework\Setup\Patch\DataPatchInterface;
class MigrateOldConfig implements DataPatchInterface
{
private const OLD_PREFIX = 'evebit_product_translation/';
private const NEW_PREFIX = 'esun_translation/';
public function __construct(
private readonly ModuleDataSetupInterface $moduleDataSetup,
private readonly ResourceConnection $resourceConnection
) {
}
public function apply(): self
{
$this->moduleDataSetup->getConnection()->startSetup();
$connection = $this->resourceConnection->getConnection();
$table = $this->resourceConnection->getTableName('core_config_data');
$rows = $connection->fetchAll(
$connection->select()
->from($table)
->where('path LIKE ?', self::OLD_PREFIX . '%')
);
foreach ($rows as $row) {
$newPath = self::NEW_PREFIX . substr((string)$row['path'], strlen(self::OLD_PREFIX));
$exists = $connection->fetchOne(
$connection->select()
->from($table, ['config_id'])
->where('scope = ?', $row['scope'])
->where('scope_id = ?', $row['scope_id'])
->where('path = ?', $newPath)
->limit(1)
);
if ($exists) {
continue;
}
$connection->insert($table, [
'scope' => $row['scope'],
'scope_id' => $row['scope_id'],
'path' => $newPath,
'value' => $row['value'],
]);
}
$this->moduleDataSetup->getConnection()->endSetup();
return $this;
}
public static function getDependencies(): array
{
return [];
}
public function getAliases(): array
{
return [];
}
}