* split function removepackage into functions removeExtensionFiles and removeExtensionDirs.

This commit is contained in:
wangyuting
2023-12-08 14:39:10 +08:00
parent 64c1eebe61
commit f28218664b
4 changed files with 45 additions and 13 deletions
+4 -1
View File
@@ -17,10 +17,13 @@ title=测试 apiModel->createDemoData();
timeout=0
cid=1
- 测试正常初始化数据。 @1
- 测试错误初始化数据。 @0
*/
global $tester, $lang, $app;
$tester->loadModel('api');
$app->setAppRoot('', dirname(__FILE__, 5));
r($tester->api->createDemoData($lang->api->zentaoAPI, commonModel::getSysURL() . $app->config->webRoot . 'api.php/v1', '16.0')) && p() && e(1); // 测试正常初始化数据。
r($tester->api->createDemoData($lang->api->zentaoAPI, commonModel::getSysURL() . $app->config->webRoot . 'api.php/v2', '16.0')) && p() && e(0); // 测试错误初始化数据。
-1
View File
@@ -27,6 +27,5 @@ cid=1
global $tester;
$tester->loadModel('api');
$app->setAppRoot('', dirname(__FILE__, 5));
r($tester->api->getDemoData('apistruct', '16.0')) && p('0:id,lib,name,type') && e('1,853,user,json'); //获取数据结构表的初始化数据。
r($tester->api->getDemoData('module', '16.0')) && p('0:id,root,name;3:id,root,name') && e('2964,853,工单,2961,853,项目'); //获取模块表的初始化数据。
+41 -10
View File
@@ -406,17 +406,34 @@ class extensionModel extends model
* @access public
* @return array
*/
public function removePackage(string $extension)
public function removePackage(string $extension): array
{
$extension = $this->getInfoFromDB($extension);
if($extension->type == 'patch') return true; // 无法删除补丁类型的插件包。
if(empty($extension)) return array();
if($extension->type == 'patch') return array(); // 无法删除补丁类型的插件包。
$removeFilesTips = $this->removeExtensionFiles($extension->files);
$removeDirsTips = $this->removeExtensionDirs($extension->dirs);
/* Clean model cache files. */
$this->cleanModelCache();
return array_merge($removeFilesTips, $removeDirsTips);
}
/**
* 删除安装插件时拷贝到禅道目录的插件文件。
* Remove extension files.
*
* @param string $files
* @access private
* @return array
*/
private function removeExtensionFiles(string $files): array
{
$commandTips = array();
$appRoot = $this->app->getAppRoot();
$dirs = json_decode($extension->dirs);
$files = json_decode($extension->files);
/* 删除安装插件时拷贝到禅道目录的插件文件, 如果没有权限或者删除失败则返回提示信息。*/
$files = json_decode($files);
if($files)
{
foreach($files as $file => $savedMD5)
@@ -424,6 +441,7 @@ class extensionModel extends model
$file = $appRoot . $file;
if(!file_exists($file)) continue;
/* 如果没有权限或者删除失败则返回提示信息。 */
$parentDir = mb_substr($file, 0, strripos($file, '/'));
if(!is_writable($file) || !is_writable($parentDir))
{
@@ -440,7 +458,22 @@ class extensionModel extends model
}
}
/* 删除安装插件时在禅道目录新增的文件夹, 如果没有权限或者删除失败则返回提示信息。*/
return $commandTips;
}
/**
* 删除安装插件时在禅道目录新增的文件夹。
* Remove extension dirs.
*
* @param string $dirs
* @access private
* @return array
*/
private function removeExtensionDirs(string $dirs): array
{
$commandTips = array();
$appRoot = $this->app->getAppRoot();
$dirs = json_decode($dirs);
if($dirs)
{
rsort($dirs); // remove from the lower level directory.
@@ -449,6 +482,7 @@ class extensionModel extends model
$path = rtrim($appRoot . $dir, '/');
if(!is_dir($path)) continue;
/* 如果没有权限或者删除失败则返回提示信息。*/
$parentDir = mb_substr($path, 0, strripos($path, '/'));
if(!is_writable($path) || !is_writable($parentDir))
{
@@ -461,9 +495,6 @@ class extensionModel extends model
}
}
/* Clean model cache files. */
$this->cleanModelCache();
return $commandTips;
}
@@ -18,7 +18,6 @@ zdTable('extension')->gen(10);
global $tester, $app;
$tester->loadModel('extension');
$app->setAppRoot('', dirname(__FILE__, 5));
$result = $tester->extension->removePackage('code1');
r(is_array($result)) && p() && e(1); // 删除安装的code1插件文件检查返回值是否是数组。
r($result) && p() && e(0); // 删除安装的code1插件文件并检查有没有错误信息。