【问题标题】:Import Magento1 admin users to Magento2将 Magento1 管理员用户导入 Magento2
【发布时间】:2019-01-24 15:06:23
【问题描述】:
我已经使用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
【解决方案1】:
问题出在/vendor/magento/framework/Serialize/Serializer/Json.php有一个
函数反序列化($string)
有一个解决方法——你可以检查字符串是否被序列化,然后使用serialize($string)。
将反序列化更改为:
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;
}
【解决方案2】:
更改核心文件不是一个好主意,所以我建议通过查看异常来识别表,然后描述该表以查看哪个字段可以包含序列化值,通过选择查询找到它,一旦你确定了序列化字段table 将其转换为 json 并更新为 table,这是将序列化数据转换为 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:"roger@test.org";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:"Jessica@test.org";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:"mickey@test.org";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:"donald@test.org";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;