From 52a37824ef73409951f27f3910e12b189fc29c28 Mon Sep 17 00:00:00 2001
From: caoming <604844710@qq.com>
Date: Tue, 5 Nov 2019 20:00:34 +0800
Subject: [PATCH] 1.版本信息添加ECS文件路径,保留原来ECS上传的文件,且支持切换升级包获取路径。
---
app-api/controllers/UpgradeController.php | 7 ++++++-
app-ht/modules/upgrade/controllers/UpgradeController.php | 5 +++--
app-ht/modules/upgrade/views/upgrade/create.php | 3 +++
app-ht/modules/upgrade/views/upgrade/edit.php | 3 +++
common/config/params.php | 1 +
domain/upgrade/Upgrade.php | 4 ++++
6 files changed, 20 insertions(+), 3 deletions(-)
diff --git a/app-api/controllers/UpgradeController.php b/app-api/controllers/UpgradeController.php
index b37c8d4..ec0c73f 100644
--- a/app-api/controllers/UpgradeController.php
+++ b/app-api/controllers/UpgradeController.php
@@ -177,7 +177,12 @@ class UpgradeController extends BaseController
$e->message = '有升级包';
$e->update_flag = $upgradeRecord->focuse;
$e->version = $upgradeRecord->version;
- $e->file_path = $domainURL.$upgradeRecord->path;
+ // 根据配置文件切换读取更新文件的路径
+ if (isset(Yii::$app->params["UPGRADE_FILE_FROM"]) && "FROM_OSS" == Yii::$app->params["UPGRADE_FILE_FROM"]) {
+ $e->file_path = Yii::$app->params["ossOptions"]["url"] . "/" . $upgradeRecord->path;
+ } else {
+ $e->file_path = $domainURL.$upgradeRecord->upload_path;
+ }
$e->file_md5 = $upgradeRecord->file_md5;
$e->size = $upgradeRecord->size;
$e->package_type = $upgradeRecord->package_type;
diff --git a/app-ht/modules/upgrade/controllers/UpgradeController.php b/app-ht/modules/upgrade/controllers/UpgradeController.php
index 59cb5a4..bec585a 100644
--- a/app-ht/modules/upgrade/controllers/UpgradeController.php
+++ b/app-ht/modules/upgrade/controllers/UpgradeController.php
@@ -519,7 +519,7 @@ class UpgradeController extends BaseController
$hashStr = substr(md5($pathInfo['basename']),8,16);
$hashName = time() . $hashStr . '.' .$pathInfo['extension'];
$uploadPath = $uploadDir . "/" .$hashName;
- $savePath = $savePath . "/" . $hashName;
+ $saveUploadPath = $savePath . "/" . $hashName;
if (!$out = fopen($uploadPath, "wb")) {
die('{"jsonrpc" : "2.0", "error" : {"code": 106, "message": "Failed to open output stream."}, "id" : "id"}');
}
@@ -545,6 +545,7 @@ class UpgradeController extends BaseController
'success' => true,
'oldName' => $oldName,
'filePath' => $savePath,
+ 'uploadPath' => $saveUploadPath,
'fileSize' => filesize($uploadPath),
'fileSuffixes' => $pathInfo['extension'], //文件后缀名
'file_md5' => md5_file($uploadPath),
@@ -554,7 +555,7 @@ class UpgradeController extends BaseController
$fileService = new FileService();
$fileService->add($uploadPath, $savePath);
// 删除服务器传成功的文件
- @unlink($uploadPath);
+ //@unlink($uploadPath);
/**
* 后台操作日志
diff --git a/app-ht/modules/upgrade/views/upgrade/create.php b/app-ht/modules/upgrade/views/upgrade/create.php
index ccbb675..ae210a1 100644
--- a/app-ht/modules/upgrade/views/upgrade/create.php
+++ b/app-ht/modules/upgrade/views/upgrade/create.php
@@ -76,6 +76,7 @@ $this->params['breadcrumbs'][] = $this->title;
"/>
"/>
+ "/>
"/>
"/>
"/>
@@ -233,6 +234,7 @@ $this->params['breadcrumbs'][] = $this->title;
$("#save").removeAttr("disabled");
//$list.append('');
$("input[name='path']").val(response.filePath);
+ $("input[name='upload_path']").val(response.uploadPath);
$("input[name='size']").val(response.fileSize);
$("input[name='file_md5']").val(response.file_md5);
$("input[name='oldName']").val(response.oldName);
@@ -241,6 +243,7 @@ $this->params['breadcrumbs'][] = $this->title;
// 文件上传失败,显示上传出错
uploader.on( 'uploadError', function( file ,response) {
$("input[name='path']").val("");
+ $("input[name='upload_path']").val("");
$("input[name='size']").val("");
$("input[name='file_md5']").val("");
$("input[name='oldName']").val("");
diff --git a/app-ht/modules/upgrade/views/upgrade/edit.php b/app-ht/modules/upgrade/views/upgrade/edit.php
index 435f11b..6e38c2e 100644
--- a/app-ht/modules/upgrade/views/upgrade/edit.php
+++ b/app-ht/modules/upgrade/views/upgrade/edit.php
@@ -76,6 +76,7 @@ $this->params['breadcrumbs'][] = $this->title;
"/>
"/>
"/>
+ "/>
"/>
"/>
"/>
@@ -224,6 +225,7 @@ $this->params['breadcrumbs'][] = $this->title;
$( '#'+file.id ).find('p.state').text('已上传');
//$list.append('');
$("input[name='path']").val(response.filePath);
+ $("input[name='upload_path']").val(response.uploadPath);
$("input[name='size']").val(response.fileSize);
$("input[name='file_md5']").val(response.file_md5);
$("input[name='oldName']").val(response.oldName);
@@ -233,6 +235,7 @@ $this->params['breadcrumbs'][] = $this->title;
uploader.on( 'uploadError', function( file ) {
$("input[name='path']").val("");
$("input[name='size']").val("");
+ $("input[name='upload_path']").val("");
$("input[name='file_md5']").val("");
$("input[name='oldName']").val("");
$( '#'+file.id ).find('p.state').text('上传出错');
diff --git a/common/config/params.php b/common/config/params.php
index d5da0a2..cf33723 100644
--- a/common/config/params.php
+++ b/common/config/params.php
@@ -11,4 +11,5 @@ return [
'url' => 'https://kingboard-prod.oss-cn-shenzhen.aliyuncs.com',
'styleUrl' => 'https://kingboard-prod.oss-cn-shenzhen.aliyuncs.com'
],
+ 'UPGRADE_FILE_FROM' => 'FROM_ECS'
];
diff --git a/domain/upgrade/Upgrade.php b/domain/upgrade/Upgrade.php
index c5ad6ab..6c8ab97 100644
--- a/domain/upgrade/Upgrade.php
+++ b/domain/upgrade/Upgrade.php
@@ -41,6 +41,7 @@ class Upgrade
$upgradeModel->model_id = $item["model_id"]; // 型号
$upgradeModel->desc = $item["desc"]; // 描述
$upgradeModel->path = $item["path"]; // 文件路径
+ $upgradeModel->upload_path = $item["upload_path"]; // 服务器文件路径
$upgradeModel->package_name = $item["package_name"]; // 安装包名称
if (isset($item["device_ids"])) {
$upgradeModel->device_ids = $item["指定deviceID,可以多个,多个用逗号隔开"]; // 版本
@@ -99,6 +100,9 @@ class Upgrade
if (isset($item['path']) && !empty($item['path'])) {
$upgradeModel->path = $item['path'];
}
+ if (isset($item['upload_path']) && !empty($item['upload_path'])) {
+ $upgradeModel->upload_path = $item['upload_path'];
+ }
if (isset($item['focuse']) && !empty($item['focuse'])) {
$upgradeModel->focuse = $item['focuse'];
}
--
libgit2 0.21.0