diff --git a/niucloud/app/adminapi/controller/addon/Addon.php b/niucloud/app/adminapi/controller/addon/Addon.php index b40eeb57e..ed3833804 100644 --- a/niucloud/app/adminapi/controller/addon/Addon.php +++ b/niucloud/app/adminapi/controller/addon/Addon.php @@ -85,6 +85,16 @@ class Addon extends BaseAdminController return success('ADDON_UNINSTALL_SUCCESS'); } + /** + * 插件安装环境检测 + * @param $addon + * @return Response + */ + public function uninstallCheck($addon) + { + return (new AddonService())->uninstallCheck($addon); + } + /** * 插件列表 * @return Response diff --git a/niucloud/app/adminapi/route/addon.php b/niucloud/app/adminapi/route/addon.php index 632cac092..f95670b87 100644 --- a/niucloud/app/adminapi/route/addon.php +++ b/niucloud/app/adminapi/route/addon.php @@ -43,6 +43,8 @@ Route::group(function () { //插件类型 Route::get('addontype', 'addon.Addon/getType'); + //卸载插件环境检测 + Route::get('addon/uninstall/check/:addon', 'addon.Addon/uninstallCheck'); //卸载插件 Route::post('addon/uninstall/:addon', 'addon.Addon/uninstall'); //应用列表(...) diff --git a/niucloud/app/service/admin/addon/AddonService.php b/niucloud/app/service/admin/addon/AddonService.php index 307af2ad7..5e99b9de5 100644 --- a/niucloud/app/service/admin/addon/AddonService.php +++ b/niucloud/app/service/admin/addon/AddonService.php @@ -100,6 +100,15 @@ class AddonService extends BaseAdminService return success('SUCCESS', $data); } + /** + * @param string $addon + * @return void + */ + public function uninstallCheck(string $addon) { + $data = ( new CoreAddonInstallService($addon) )->uninstallCheck(); + return success('SUCCESS', $data); + } + /** * 卸载插件 * @param string $addon diff --git a/niucloud/app/service/core/addon/CoreAddonInstallService.php b/niucloud/app/service/core/addon/CoreAddonInstallService.php index f550a2aea..da6052843 100644 --- a/niucloud/app/service/core/addon/CoreAddonInstallService.php +++ b/niucloud/app/service/core/addon/CoreAddonInstallService.php @@ -463,6 +463,43 @@ class CoreAddonInstallService extends CoreAddonBaseService (new CoreAddonCloudService())->cloudBuild($this->addon); } + /** + * 插件卸载环境检测 + * @param string $addon + * @return void + */ + public function uninstallCheck() { + $data = [ + // 目录检测 + 'dir' => [ + // 要求可读权限 + 'is_readable' => [], + // 要求可写权限 + 'is_write' => [] + ] + ]; + + // 将要删除的根目录 + $to_admin_dir = $this->root_path . 'admin' . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . $this->addon . DIRECTORY_SEPARATOR; + $to_web_dir = $this->root_path . 'web' . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . $this->addon . DIRECTORY_SEPARATOR; + $to_wap_dir = $this->root_path . 'uni-app' . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . $this->addon . DIRECTORY_SEPARATOR; + $to_resource_dir = public_path() . 'addon' . DIRECTORY_SEPARATOR . $this->addon . DIRECTORY_SEPARATOR; + + if (is_dir($to_admin_dir)) $data['dir']['is_write'][] = ['dir' => str_replace(project_path(), '', $to_admin_dir), 'status' => is_write($to_admin_dir)]; + if (is_dir($to_web_dir)) $data['dir']['is_write'][] = ['dir' => str_replace(project_path(), '', $to_web_dir), 'status' => is_write($to_web_dir)]; + if (is_dir($to_wap_dir)) $data['dir']['is_write'][] = ['dir' => str_replace(project_path(), '', $to_wap_dir), 'status' => is_write($to_wap_dir)]; + if (is_dir($to_resource_dir)) $data['dir']['is_write'][] = ['dir' => str_replace(project_path(), '', $to_resource_dir), 'status' => is_write($to_resource_dir)]; + + $check_res = array_merge( + array_column($data['dir']['is_readable'], 'status'), + array_column($data['dir']['is_write'], 'status') + ); + + // 是否通过校验 + $data['is_pass'] = !in_array(false, $check_res); + return $data; + } + /** * 卸载插件 * @return true