From 37425ce477d74c394f9d1d78fd8427e7b6f2b7d0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=A6=99=E7=A0=81=E7=94=9F=E8=8A=B1?= <18523774412@qq.com>
Date: Tue, 30 Aug 2022 03:01:25 +0800
Subject: [PATCH] =?UTF-8?q?feat:=E6=A8=A1=E5=9D=97=E5=AE=89=E8=A3=85?=
=?UTF-8?q?=E7=AD=89=E5=BE=85=E7=83=AD=E9=87=8D=E8=BD=BD=E6=8F=90=E7=A4=BA?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
extend/ba/module/Manage.php | 108 +++++++++---------
web/src/lang/pages/en/module.ts | 3 -
web/src/lang/pages/zh-cn/module.ts | 3 -
.../backend/module/components/install.vue | 34 +++++-
web/src/views/backend/module/index.ts | 28 +++--
5 files changed, 107 insertions(+), 69 deletions(-)
diff --git a/extend/ba/module/Manage.php b/extend/ba/module/Manage.php
index 04148d55..ca154dfc 100644
--- a/extend/ba/module/Manage.php
+++ b/extend/ba/module/Manage.php
@@ -121,7 +121,7 @@ class Manage
// 删除下载的zip
@unlink($zipFile);
- // 设置为安装中状态
+ // 设置为待安装状态
$this->setInfo([
'state' => self::WAIT_INSTALL,
]);
@@ -141,65 +141,23 @@ class Manage
public function enable(string $trigger)
{
- $info = $this->getInfo();
- if ($info['state'] == self::WAIT_INSTALL || $info['state'] == self::CONFLICT_PENDING) {
- $this->conflictHandle($trigger);
- $info = $this->getInfo();
- }
+ $this->conflictHandle($trigger);
+ $this->dependUpdateHandle();
// 执行启用脚本
Server::execEvent($this->uid, 'enable');
-
- if ($info['state'] == self::DEPENDENT_WAIT_INSTALL) {
- $waitInstall = [];
- if (isset($info['composer_dependent_wait_install'])) {
- $waitInstall[] = 'composer_dependent_wait_install';
- }
- if (isset($info['npm_dependent_wait_install'])) {
- $waitInstall[] = 'npm_dependent_wait_install';
- }
- if ($waitInstall) {
- throw new moduleException('dependent wait install', -2, [
- 'uid' => $this->uid,
- 'state' => self::DEPENDENT_WAIT_INSTALL,
- 'wait_install' => $waitInstall,
- 'fullreload' => $info['fullreload'],
- ]);
- } else {
- $this->setInfo([
- 'state' => self::INSTALLED,
- ]);
- }
- }
- }
-
- public function dependentInstallComplete(string $type)
- {
- $info = $this->getInfo();
- if ($info['state'] == self::DEPENDENT_WAIT_INSTALL) {
- if ($type == 'npm') {
- unset($info['npm_dependent_wait_install']);
- }
- if ($type == 'composer') {
- unset($info['composer_dependent_wait_install']);
- }
- if ($type == 'all') {
- unset($info['npm_dependent_wait_install'], $info['composer_dependent_wait_install']);
- }
- if (!isset($info['npm_dependent_wait_install']) && !isset($info['composer_dependent_wait_install'])) {
- $info['state'] = self::INSTALLED;
- }
- $this->setInfo([], $info);
- }
}
/**
* 处理依赖和文件冲突,并完成与前端的冲突处理交互
- * @throws moduleException
+ * @throws moduleException|Exception
*/
- public function conflictHandle(string $trigger)
+ public function conflictHandle(string $trigger): bool
{
-
+ $info = $this->getInfo();
+ if ($info['state'] != self::WAIT_INSTALL && $info['state'] != self::CONFLICT_PENDING) {
+ return false;
+ }
$fileConflict = Server::getFileList($this->modulesDir, true);// 文件冲突
$dependConflict = Server::dependConflictCheck($this->modulesDir);// 依赖冲突
$installFiles = Server::getFileList($this->modulesDir);// 待安装文件
@@ -293,7 +251,6 @@ class Manage
}
if ($depends) {
- $info = $this->getInfo();
$npm = false;
$composer = false;
foreach ($depends as $key => $item) {
@@ -363,6 +320,53 @@ class Manage
}
}
}
+ return true;
+ }
+
+ public function dependUpdateHandle()
+ {
+ $info = $this->getInfo();
+ if ($info['state'] == self::DEPENDENT_WAIT_INSTALL) {
+ $waitInstall = [];
+ if (isset($info['composer_dependent_wait_install'])) {
+ $waitInstall[] = 'composer_dependent_wait_install';
+ }
+ if (isset($info['npm_dependent_wait_install'])) {
+ $waitInstall[] = 'npm_dependent_wait_install';
+ }
+ if ($waitInstall) {
+ throw new moduleException('dependent wait install', -2, [
+ 'uid' => $this->uid,
+ 'state' => self::DEPENDENT_WAIT_INSTALL,
+ 'wait_install' => $waitInstall,
+ 'fullreload' => $info['fullreload'],
+ ]);
+ } else {
+ $this->setInfo([
+ 'state' => self::INSTALLED,
+ ]);
+ }
+ }
+ }
+
+ public function dependentInstallComplete(string $type)
+ {
+ $info = $this->getInfo();
+ if ($info['state'] == self::DEPENDENT_WAIT_INSTALL) {
+ if ($type == 'npm') {
+ unset($info['npm_dependent_wait_install']);
+ }
+ if ($type == 'composer') {
+ unset($info['composer_dependent_wait_install']);
+ }
+ if ($type == 'all') {
+ unset($info['npm_dependent_wait_install'], $info['composer_dependent_wait_install']);
+ }
+ if (!isset($info['npm_dependent_wait_install']) && !isset($info['composer_dependent_wait_install'])) {
+ $info['state'] = self::INSTALLED;
+ }
+ $this->setInfo([], $info);
+ }
}
public function checkPackage(): bool
diff --git a/web/src/lang/pages/en/module.ts b/web/src/lang/pages/en/module.ts
index 335e643a..ee32f963 100644
--- a/web/src/lang/pages/en/module.ts
+++ b/web/src/lang/pages/en/module.ts
@@ -2,9 +2,6 @@ export default {
'stateTitle init': 'Module installer initialization...',
'stateTitle download': 'Downloading module...',
'stateTitle install': 'Installing module...',
- 'stateTitle handleConflicts': 'Processing conflicts...',
- 'stateTitle installDepend': 'Installing dependencies, please check the terminal window...',
- 'stateTitle installRepublish': 'Republishing, please check the terminal window...',
'env require': 'Composer',
'env require-dev': 'Composer-dev',
'env dependencies': 'NPM',
diff --git a/web/src/lang/pages/zh-cn/module.ts b/web/src/lang/pages/zh-cn/module.ts
index cee2eb10..75d15ca0 100644
--- a/web/src/lang/pages/zh-cn/module.ts
+++ b/web/src/lang/pages/zh-cn/module.ts
@@ -2,9 +2,6 @@ export default {
'stateTitle init': '模块安装器初始化...',
'stateTitle download': '正在下载模块...',
'stateTitle install': '正在安装模块...',
- 'stateTitle handleConflicts': '正在处理冲突...',
- 'stateTitle installDepend': '正在安装依赖,请查看终端窗口...',
- 'stateTitle installRepublish': '正在重新发布,请查看终端窗口...',
'env require': '后端依赖(composer)',
'env require-dev': '后端开发环境依赖(composer)',
'env dependencies': '前端依赖(NPM)',
diff --git a/web/src/views/backend/module/components/install.vue b/web/src/views/backend/module/components/install.vue
index 83b5b4ea..d50f48f7 100644
--- a/web/src/views/backend/module/components/install.vue
+++ b/web/src/views/backend/module/components/install.vue
@@ -18,8 +18,21 @@
>