* finish the erase, uninstall, deactivate, activate features.

This commit is contained in:
wangchunsheng
2011-04-20 02:54:07 +00:00
parent 64b3f26073
commit 0813df9761
7 changed files with 195 additions and 29 deletions
+17 -4
View File
@@ -130,7 +130,12 @@ class extension extends control
}
/* Extract the package. */
$this->extension->extractPackage($extension);
$return = $this->extension->extractPackage($extension);
if($return->result != 'ok')
{
$this->view->error = sprintf($this->lang->extension->errorExtracted, $packageFile, $return->error);
die($this->display());
}
/* Save to database. */
$this->extension->saveExtension($extension);
@@ -172,9 +177,11 @@ class extension extends control
*/
public function uninstall($extension)
{
$this->extension->removePackage($extension);
$this->extension->executeDB($extension, 'uninstall');
$this->extension->updateExtension($extension, array('status' => 'available'));
$this->view->removeCommands = $this->extension->removePackage($extension);
$this->view->header->title = $this->lang->extension->uninstallFinished;
$this->display();
}
/**
@@ -188,6 +195,8 @@ class extension extends control
{
$this->extension->copyPackageFiles($extension);
$this->extension->updateExtension($extension, array('status' => 'installed'));
$this->view->header->title = $this->lang->extension->activateFinished;
$this->display();
}
/**
@@ -199,8 +208,10 @@ class extension extends control
*/
public function deactivate($extension)
{
$this->extension->removePackage($extension);
$this->extension->updateExtension($extension, array('status' => 'deactivated'));
$this->view->removeCommands = $this->extension->removePackage($extension);
$this->view->header->title = $this->lang->extension->deactivateFinished;
$this->display();
}
/**
@@ -231,6 +242,8 @@ class extension extends control
*/
public function erase($extension)
{
$this->extension->erasePackage($extension);
$this->view->removeCommands = $this->extension->erasePackage($extension);
$this->view->header->title = $this->lang->extension->eraseFinished;
$this->display();
}
}
+9
View File
@@ -46,17 +46,26 @@ $lang->extension->byCategory = '分类浏览';
$lang->extension->installFailed = '安装失败,错误原因如下:';
$lang->extension->installFinished = '恭喜您,插件顺利的安装成功!';
$lang->extension->refreshPage = '刷新页面';
$lang->extension->uninstallFinished = '插件已经成功卸载';
$lang->extension->deactivateFinished = '插件已经成功禁用';
$lang->extension->activateFinished = '插件已经成功激活';
$lang->extension->eraseFinished = '插件已经成功清除';
$lang->extension->unremovedFiles = '有一些文件或目录未能删除,需要手工删除';
$lang->extension->refreshPage = '刷新页面';
$lang->extension->executeCommands = '<h3>执行下面的命令来修正这些问题:</h3>';
$lang->extension->successDownloadedPackage = '成功下载插件';
$lang->extension->successCopiedFiles = '成功拷贝文件';
$lang->extension->successInstallDB = '成功安装数据库';
$lang->extension->viewInstalled = '查看已安装插件';
$lang->extension->viewAvailable = '查看可安装插件';
$lang->extension->viewDeactivated = '查看已禁用插件';
$lang->extension->errorDownloadPathNotFound = '插件下载存储路径<strong>%s</strong>不存在。<br />linux下面请执行命令:<strong>mkdir %s</strong>来修正。';
$lang->extension->errorDownloadPathNotWritable = '插件下载存储路径<strong>%s</strong>不可写。<br />linux下面请执行命令:<strong>sudo chmod 777 %s</strong>来修正。';
$lang->extension->errorPackageFileExists = '下载路径已经有一个名为的<strong>%s</strong>附件。<h3>重新安装,<a href="%s">请点击此链接</a></h3>';
$lang->extension->errorDownloadFailed = '下载失败,请重新下载。如果多次重试还不行,请尝试手工下载,然后通过上传功能上传。';
$lang->extension->errorMd5Checking = '下载文件不完整,请重新下载。如果多次重试还不行,请尝试手工下载,然后通过上传功能上传。';
$lang->extension->errorExtracted = '包文件<strong> %s </strong>解压缩失败,可能不是一个有效的zip文件。错误信息如下:<br />';
$lang->extension->errorPackageNotFound = '包文件 <strong>%s </strong>没有找到,可能是因为自动下载失败。您可以尝试再次下载。';
$lang->extension->errorTargetPathNotWritable = '目标路径 <strong>%s </strong>不可写。';
$lang->extension->errorTargetPathNotExists = '目标路径 <strong>%s </strong>不存在。';
+50 -25
View File
@@ -279,17 +279,25 @@ class extensionModel extends model
*
* @param string $extension
* @access public
* @return void
* @return object
*/
public function extractPackage($extension)
public function extractPackage($extension)
{
/* Extract the zip file. */
$return->result = 'ok';
$return->error = '';
$packageFile = $this->getPackageFile($extension);
$this->app->loadClass('pclzip', true);
$zip = new pclzip($packageFile);
$files = $zip->listContent();
$removePath = $files[0]['filename'];
$zip->extract(PCLZIP_OPT_PATH, "ext/$extension", PCLZIP_OPT_REMOVE_PATH, $removePath);
if($zip->extract(PCLZIP_OPT_PATH, "ext/$extension", PCLZIP_OPT_REMOVE_PATH, $removePath) == 0)
{
$return->result = 'fail';
$return->error = $zip->errorInfo(true);
}
return $return;
}
/**
@@ -308,12 +316,15 @@ class extensionModel extends model
$this->app->loadClass('pclzip', true);
$zip = new pclzip($packageFile);
$files = $zip->listContent();
foreach($files as $file)
if($files)
{
$file = (object)$file;
if($file->folder) continue;
$file->filename = substr($file->filename, strpos($file->filename, '/') + 1);
$pathes[] = dirname($file->filename);
foreach($files as $file)
{
$file = (object)$file;
if($file->folder) continue;
$file->filename = substr($file->filename, strpos($file->filename, '/') + 1);
$pathes[] = dirname($file->filename);
}
}
/* Append the pathes to stored the extracted files. */
@@ -350,25 +361,21 @@ class extensionModel extends model
*
* @param string $extension
* @access public
* @return array un removed files.
* @return array the remove commands need executed manually.
*/
public function removePackage($extension)
{
$extension = $this->getInfoFromDB($extension);
$dirs = json_decode($extension->dirs);
$files = json_decode($extension->files);
$unremovedDirs = array();
$unremovedFiles = array();
$appRoot = $this->app->getAppRoot();
$removeCommands = array();
if($dirs)
{
foreach($dirs as $dir)
{
if(!@rmdir($appRoot . $dir))
{
$unremovedDirs[] = $appRoot . $dir;
}
if(!@rmdir($appRoot . $dir)) $removeCommands[] = "rmdir $appRoot$dir";
}
}
@@ -376,13 +383,16 @@ class extensionModel extends model
{
foreach($files as $file)
{
if(!@unlink($appRoot . $file))
$file = $appRoot . $file;
if(!file_exists($file)) continue;
if(!@unlink($file))
{
$unremovedFiles[] = $appRoot . $file;
$removeCommands[] = PHP_OS == 'Linux' ? "rm -fr $file" : "del $file";
}
}
}
return array('unremovedDirs' => $unremovedDirs, 'unremovedFiles' => $unremovedFiles);
return $removeCommands;
}
/**
@@ -390,13 +400,29 @@ class extensionModel extends model
*
* @param string $extension
* @access public
* @return void
* @return array the remove commands need executed manually.
*/
public function erasePackage($extension)
{
$packageFile = $this->getPackageFile($extension);
unlink($packageFile);
$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) and !@unlink($packageFile))
{
$removeCommands[] = PHP_OS == 'Linux' ? "rm -fr $packageFile" : "del $packageFile";
}
/* Remove the extracted files. */
$extractedDir = realpath("ext/$extension");
if(!$this->removeDir($extractedDir))
{
$removeCommands[] = PHP_OS == 'Linux' ? "rm -fr $extractedDir" : "rmdir $extractedDir /s";
}
return $removeCommands;
}
/**
@@ -487,9 +513,8 @@ class extensionModel extends model
$data = (object)$data;
$appRoot = $this->app->getAppRoot();
if(isset($data->dirs))
if(isset($data->dirs) and $data->dirs)
{
foreach($data->dirs as $key => $dir)
{
$data->dirs[$key] = str_replace($appRoot, '', $dir);
@@ -584,7 +609,7 @@ class extensionModel extends model
$this->removeDir($fullEntry);
}
}
rmdir($dir);
if(!@rmdir($dir)) return false;
return true;
}
}
+26
View File
@@ -0,0 +1,26 @@
<?php
/**
* The deactivate view file of extension module of ZenTaoPMS.
*
* @copyright Copyright 2009-2011 QingDao Nature Easy Soft Network Technology Co,LTD (www.cnezsoft.com)
* @license LGPL (http://www.gnu.org/licenses/lgpl.html)
* @author Chunsheng Wang <chunsheng@cnezsoft.com>
* @package extension
* @version $Id$
* @link http://www.zentao.net
*/
?>
<?php include '../../common/view/header.lite.html.php';?>
<table class='table-1'>
<caption><?php echo $header->title;?></caption>
<tr>
<td valign='middle'>
<?php
echo "<h3 class='a-center success'>{$header->title}</h3>";
echo "<p class='a-center'>" . html::commonButton($lang->extension->viewInstalled, 'onclick=parent.location.href="' . inlink('browse', 'type=installed') . '"') . '</p>';
?>
</td>
</tr>
</table>
</body>
</html>
+31
View File
@@ -0,0 +1,31 @@
<?php
/**
* The deactivate view file of extension module of ZenTaoPMS.
*
* @copyright Copyright 2009-2011 QingDao Nature Easy Soft Network Technology Co,LTD (www.cnezsoft.com)
* @license LGPL (http://www.gnu.org/licenses/lgpl.html)
* @author Chunsheng Wang <chunsheng@cnezsoft.com>
* @package extension
* @version $Id$
* @link http://www.zentao.net
*/
?>
<?php include '../../common/view/header.lite.html.php';?>
<table class='table-1'>
<caption><?php echo $header->title;?></caption>
<tr>
<td valign='middle'>
<?php
echo "<h3 class='a-center success'>{$header->title}</h3>";
if($removeCommands)
{
echo "<p class='strong'>{$lang->extension->unremovedFiles}</p>";
echo join($removeCommands, '<br />');
}
echo "<p class='a-center'>" . html::commonButton($lang->extension->viewDeactivated, 'onclick=parent.location.href="' . inlink('browse', 'type=deactivated') . '"') . '</p>';
?>
</td>
</tr>
</table>
</body>
</html>
+31
View File
@@ -0,0 +1,31 @@
<?php
/**
* The erase view file of extension module of ZenTaoPMS.
*
* @copyright Copyright 2009-2011 QingDao Nature Easy Soft Network Technology Co,LTD (www.cnezsoft.com)
* @license LGPL (http://www.gnu.org/licenses/lgpl.html)
* @author Chunsheng Wang <chunsheng@cnezsoft.com>
* @package extension
* @version $Id$
* @link http://www.zentao.net
*/
?>
<?php include '../../common/view/header.lite.html.php';?>
<table class='table-1'>
<caption><?php echo $header->title;?></caption>
<tr>
<td valign='middle'>
<?php
echo "<h3 class='a-center success'>{$header->title}</h3>";
if($removeCommands)
{
echo "<p class='strong'>{$lang->extension->unremovedFiles}</p>";
echo join($removeCommands, '<br />');
}
echo "<p class='a-center'>" . html::commonButton($lang->extension->viewAvailable, 'onclick=parent.location.href="' . inlink('browse', 'type=available') . '"') . '</p>';
?>
</td>
</tr>
</table>
</body>
</html>
+31
View File
@@ -0,0 +1,31 @@
<?php
/**
* The uninstall view file of extension module of ZenTaoPMS.
*
* @copyright Copyright 2009-2011 QingDao Nature Easy Soft Network Technology Co,LTD (www.cnezsoft.com)
* @license LGPL (http://www.gnu.org/licenses/lgpl.html)
* @author Chunsheng Wang <chunsheng@cnezsoft.com>
* @package extension
* @version $Id$
* @link http://www.zentao.net
*/
?>
<?php include '../../common/view/header.lite.html.php';?>
<table class='table-1'>
<caption><?php echo $header->title;?></caption>
<tr>
<td valign='middle'>
<?php
echo "<h3 class='a-center success'>{$header->title}</h3>";
if($removeCommands)
{
echo "<p class='strong'>{$lang->extension->unremovedFiles}</p>";
echo join($removeCommands, '<br />');
}
echo "<p class='a-center'>" . html::commonButton($lang->extension->viewAvailable, 'onclick=parent.location.href="' . inlink('browse', 'type=available') . '"') . '</p>';
?>
</td>
</tr>
</table>
</body>
</html>