* Refactor extension function erasePackage and finish the unit test script.

This commit is contained in:
wangyuting
2023-12-08 14:58:21 +08:00
parent d7f44c8a6e
commit 6fb2e3fc6c
2 changed files with 37 additions and 12 deletions
+14 -12
View File
@@ -499,22 +499,23 @@ class extensionModel extends model
}
/**
* 删除禅道model的缓存文件。
* Clean model cache files.
*
* @access public
* @return void
* @return private
*/
public function cleanModelCache()
private function cleanModelCache()
{
$zfile = $this->app->loadClass('zfile');
$modelCacheFiles = glob($this->app->getTmpRoot() . 'model/*');
$zfile = $this->app->loadClass('zfile');
foreach($modelCacheFiles as $cacheFile)
{
if(is_dir($cacheFile))
{
$zfile->removeDir($cacheFile);
}
elseif(is_writable($cacheFile) and !is_dir($cacheFile))
elseif(is_writable($cacheFile) && !is_dir($cacheFile))
{
@unlink($cacheFile);
}
@@ -522,22 +523,23 @@ class extensionModel extends model
}
/**
* 清除插件并删除文件。
* Erase an extension's package file.
*
* @param string $extension
* @param string $extension
* @access public
* @return array the remove commands need executed manually.
* @return array
*/
public function erasePackage($extension)
public function erasePackage(string $extension): array
{
$removeCommands = array();
$this->dao->delete()->from(TABLE_EXTENSION)->where('code')->eq($extension)->exec();
/* Remove the zip file. */
$packageFile = $this->getPackageFile($extension);
if(!file_exists($packageFile)) return false;
if(file_exists($packageFile) and !@unlink($packageFile))
if(!file_exists($packageFile)) return array();
/* Remove the zip file. */
$removeCommands = array();
if(file_exists($packageFile) && !@unlink($packageFile))
{
$removeCommands[] = PHP_OS == 'Linux' ? "rm -fr $packageFile" : "del $packageFile";
}
+23
View File
@@ -0,0 +1,23 @@
#!/usr/bin/env php
<?php
/**
title=测试 extensionModel->erasePackage();
timeout=0
cid=1
- 清除安装的code1插件包检查返回值是否是数组。 @1
- 清除安装的code1插件包并检查有没有错误信息。 @0
*/
include dirname(__FILE__, 5) . '/test/lib/init.php';
su('admin');
zdTable('extension')->gen(10);
global $tester, $app;
$tester->loadModel('extension');
$result = $tester->extension->erasePackage('code1');
r(is_array($result)) && p() && e(1); // 清除安装的code1插件包检查返回值是否是数组。
r($result) && p() && e(0); // 清除安装的code1插件包并检查有没有错误信息。