问题症状
Ubuntu 18.04 (使用php7.2) 未安装 php7.2-zip 依赖,购买成功应用市场插件后点击“点击安装”,图标提示加载,但之后失去响应,既没有成功,也无错误提示。观察浏览器开发者工具Console面板,提示:
Failed to load resource: the server responded with a status of 500 (Internal Server Error)
按钮对应HTML和JS:
<a title="点击该按钮,进行应用的在线安装" class="abutton" href="javascript:void(0)" addonname="furnilife模板,简洁风格的模板" rel="fectfurnilife" foldername="furnilife_theme" packagename="fecmall">点击安装</a>
$(document).off("click").on("click",".abutton",function(){
namespace = $(this).attr('rel');
var packageName = $(this).attr('packageName');
var addonName = $(this).attr('addonName');
var folderName = $(this).attr('folderName');
var url = "<?= Yii::$service->url->getUrl("system/extensionmarket/install"); ?>";
url += '?namespace=' + namespace;
url += '&packageName=' + packageName;
url += '&folderName=' + folderName;
url += '&addonName=' + encodeURIComponent(addonName);
$.ajax({
url: url,
async: true,
timeout: 800000,
dataType: 'json',
type: 'get',
success:function(data, textStatus){
if(data.statusCode == 200){
//alert(data.statusCode);
message = data.message;
alertMsg.correct(message);
navTab.reloadFlag('page1');
} else if (data.statusCode == 300){
message = data.message;
alertMsg.error(message)
} else {
alertMsg.error("错误");
}
//
},
error:function(){
}
});
});
从浏览器端看不到太多有价值的信息,用 xdebug 调试
ZipFile.php:28, fecshop\services\helper\ZipFile->unzip()
ExtensionmarketController.php:148, fecshop\app\appadmin\modules\System\controllers\ExtensionmarketController->actionInstall()
InlineAction.php:57, call_user_func_array:{/home/zime/DATA/www/xymall/vendor/yiisoft/yii2/base/InlineAction.php:57}()
InlineAction.php:57, yii\base\InlineAction->runWithParams()
Controller.php:157, fecshop\app\appadmin\modules\System\controllers\ExtensionmarketController->runAction()
Module.php:528, yii\web\Application->runAction()
Application.php:103, yii\web\Application->handleRequest()
Application.php:386, yii\web\Application->run()
index.php:50, {main}()
到以下代码中 zip_open 时出现异常
class ZipFile extends Service
{
public function unzip($src_file, $dest_dir=false, $create_zip_name_dir=true, $overwrite=true){
if ($dest_dir) {
$dest_dir .= '/';
}
if ($zip = zip_open($src_file)){
...................
}else{
return false;
}
return true;
}
由于 zip_open 异常,不会执行到unzip()的任何一条 return 语句,所以 ExtensionmarketController.php 的以下代码不能响应给浏览器合适的 AJAX 响应
// 进行zip文件的解压
$dest_dir = dirname($zipFilePath);
if (!Yii::$service->helper->zipFile->unzip($zipFilePath, $dest_dir, true, true)) {
echo json_encode([
'statusCode' => '300',
'message' => Yii::$service->page->translate->__('unzip addons fail'),
]);
exit;
}
调试中可以知道 yiisoft/yii2/base/ErrorHandler.php中handleException()的异常消息为
Call to undefined function fecshop\services\helper\zip_open()
所以可以联想到是 zip_open 函数对应的扩展没有安装
预期的结果
安装插件应该有阶段性指示:如 正在下载插件安装包、正在解压安装包、正在安装插件、正在清理、安装成功
可以考虑的fix
@fecshop/services/helper/ZipFile.php 文件
@@ -28,1 +28,1 @@ public function unzip($src_file, $dest_dir=false, $create_zip_name_dir=true, $overwrite=true){
- if ($zip = zip_open($src_file)){
+ if (function_exists('zip_open') && ($zip = zip_open($src_file))){
这样,最起码能够看到 unzip addons fail 的提示,当然,提示语句最好改为 unzip addons fail, please make sure php extension zip is installed
Additional info
Q |
A |
Fecshop version |
2.3.6 |
PHP version |
7.2 |
Operating system |
Ubuntu 18.04 |