2.1 升级到 2.2 后,Upgrading data.. Unable to unserialize value.
2.1 升级到 2.2 后,Upgrading data.. Unable to unserialize value.
2.2.2后,后台configration 多行数据的保存 从序列化serialize改成json_encode()了。同时前台也是通过json_decode读取数据的。
所以 如果你前台用json_decode读取数据的话 就会出问题。
需要先修改core_config_data的数据,把serialize的数据改成json_encode来保存。
代码如下:
比如在项目路径/cli下新建一个php文件,updateConfiValue.php
<?php if (php_sapi_name() != &#39;cli&#39;)die; include(&#39;app/bootstrap.php&#39;); use MagentoFrameworkAppBootstrap; use MagentoFrameworkAppObjectManager; use MagentoImportExportModelImportAdapter as ImportAdapter; use MagentoFrameworkAppFilesystemDirectoryList; use MagentoCatalogApiCategoryRepositoryInterface; $bootstrap = Bootstrap::create(BP, $_SERVER); $objectManager = $bootstrap->getObjectManager(); $resource = $objectManager->get(&#39;MagentoFrameworkAppResourceConnection&#39;); $connection = $resource->getConnection(); $tableName = $resource->getTableName(&#39;core_config_data&#39;); //gives table name with prefix //Select Data from table //$sql = "Select * FROM " . $tableName . " WHERE `path`=&#39;carriers/flatrate/postcoderanges&#39;"; $sql = "Select * FROM {$tableName}"; $result = $connection->fetchAll($sql); // gives associated array, table fields as key in array. foreach ($result as $row) { if (checkIsSerialized($row[&#39;value&#39;])) { $value = json_encode(unserialize($row[&#39;value&#39;])); $configId = $row[&#39;config_id&#39;]; $sql = "Update " . $tableName . " Set value = "."&#39;".$value."&#39;"." where config_id = $configId"; $connection->query($sql); } } function checkIsSerialized($str) { $data = @unserialize($str); if ($str === &#39;b:0;&#39; || $data !== false) { return true; } return false; }
执行代码:
php cli/updateConfiValue.php
这样就都改过来了。
最后于 9月前 被admin编辑 ,原因: