将Magento1管理员用户导入Magento2

问题描述 投票:0回答:2

我使用magento 1.9.x到2.2.4的数据迁移工具完成了数据迁移,但它没有像文档中提到的那样导入管理员用户,我们需要手动复制管理员用户。

我所做的是,我只是将用户从magento1DB.admin_user复制到magento2DB.admin_user表。我可以看到用户现在出现在Magento2后端,但是当我尝试编辑任何管理员用户时,它会抛出异常。

Exception #0 (InvalidArgumentException): Unable to unserialize value

另外,我无法使用Magento2管理员面板中的Magento1管理员用户登录。

找不到任何帮助,有人有想法吗?

magento2 magento-1.9 data-migration
2个回答
0
投票

问题是在/vendor/magento/framework/Serialize/Serializer/Json.php中有一个函数unserialize($ string)

有一种解决方法 - 您可以检查字符串是否已序列化,然后使用serialize($string)。将unserialize更改为:

public function unserialize($string)
{
    /* Workaround: serialize first if is serialized */
    if($this->is_serialized($string))
    {
        $string = $this->serialize($string);
    }
    $result = json_decode($string, true);
    if (json_last_error() !== JSON_ERROR_NONE) {
         throw new \InvalidArgumentException('Unable to unserialize value.');

    }
    return $result;
}

并添加函数以检查字符串是否已序列化:

function is_serialized($value, &$result = null)
{
    // Bit of a give away this one
    if (!is_string($value))
    {
        return false;
    }
    // Serialized false, return true. unserialize() returns false on an
    // invalid string or it could return false if the string is serialized
    // false, eliminate that possibility.
    if ($value === 'b:0;')
    {
        $result = false;
        return true;
    }
    $length = strlen($value);
    $end    = '';
    switch ($value[0])
    {
        case 's':
            if ($value[$length - 2] !== '"')
            {
                return false;
            }
        case 'b':
        case 'i':
        case 'd':
            // This looks odd but it is quicker than isset()ing
            $end .= ';';
        case 'a':
        case 'O':
            $end .= '}';
            if ($value[1] !== ':')
            {
                return false;
            }
            switch ($value[2])
            {
                case 0:
                case 1:
                case 2:
                case 3:
                case 4:
                case 5:
                case 6:
                case 7:
                case 8:
                case 9:
                    break;
                default:
                    return false;
            }
        case 'N':
            $end .= ';';
            if ($value[$length - 1] !== $end[0])
            {
                return false;
            }
            break;
        default:
            return false;
    }
    if (($result = @unserialize($value)) === false)
    {
        $result = null;
        return false;
    }
    return true;
}

0
投票

更改核心文件并不是一个好主意,所以我建议通过查看异常来识别表,然后描述该表以查看哪个字段可以包含searialized值,通过select查询找到它,一旦你在表中识别序列化字段就转换到json并更新到表,这是将序列化数据转换为json数据的代码:

// Pull serialized data 
$serializeddata = 'a:2:{i:6517;a:2:{i:0;a:5:{s:10:"first_name";s:5:"Roger";s:9:"last_name";s:6:"Rabbit";s:5:"email";s:19:"[email protected]";s:7:"is_lead";b:1;s:12:"is_cancelled";b:0;}i:1;a:5:{s:10:"first_name";s:7:"Jessica";s:9:"last_name";s:6:"Rabbit";s:5:"email";s:21:"[email protected]";s:7:"is_lead";b:0;s:12:"is_cancelled";b:0;}}i:6518;a:2:{i:0;a:5:{s:10:"first_name";s:6:"Mickey";s:9:"last_name";s:5:"Mouse";s:5:"email";s:20:"[email protected]";s:7:"is_lead";b:0;s:12:"is_cancelled";b:0;}i:1;a:5:{s:10:"first_name";s:6:"Donald";s:9:"last_name";s:4:"Duck";s:5:"email";s:20:"[email protected]";s:7:"is_lead";b:0;s:12:"is_cancelled";b:0;}}}';

// Unserialize it into a standard array
$array = unserialize($serializeddata);

$jsonData = json_encode($array);

// Print Array
echo $jsonData;
© www.soinside.com 2019 - 2024. All rights reserved.