* Refactor extension function erasePackage and finish the unit test script.
This commit is contained in:
+14
-12
@@ -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";
|
||||
}
|
||||
|
||||
Executable
+23
@@ -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插件包并检查有没有错误信息。
|
||||
Reference in New Issue
Block a user