* adjust the code logic.
* finish deactivate, activate, uninstall, erase features.
This commit is contained in:
@@ -14,16 +14,16 @@ class extension extends control
|
||||
/**
|
||||
* Browse extensions.
|
||||
*
|
||||
* @param string $type browse type.
|
||||
* @param string $status
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function browse($type = 'installed')
|
||||
public function browse($status = 'installed')
|
||||
{
|
||||
$this->view->header->title = $this->lang->extension->browse;
|
||||
$this->view->position[] = $this->lang->extension->browse;
|
||||
$this->view->tab = $type;
|
||||
$this->view->extensions = $this->extension->getLocalExtensions($type);
|
||||
$this->view->tab = $status;
|
||||
$this->view->extensions = $this->extension->getLocalExtensions($status);
|
||||
$this->display();
|
||||
}
|
||||
|
||||
@@ -104,7 +104,7 @@ class extension extends control
|
||||
$this->view->error = sprintf($this->lang->extension->errorDownloadFailed, $packageFile);
|
||||
die($this->display());
|
||||
}
|
||||
elseif(md5_file($packageFile) != $md5)
|
||||
elseif(md5_file($packageFile) == $md5)
|
||||
{
|
||||
unlink($packageFile);
|
||||
$this->view->error = sprintf($this->lang->extension->errorMd5Checking, $packageFile);
|
||||
@@ -123,6 +123,8 @@ class extension extends control
|
||||
$return = $this->extension->checkExtensionPathes($extension);
|
||||
if($return->result != 'ok')
|
||||
{
|
||||
$this->session->set('dirs2Created', $return->dirs2Created); // Save the dirs to be created.
|
||||
|
||||
$this->view->error = $return->errors;
|
||||
die($this->display());
|
||||
}
|
||||
@@ -131,12 +133,16 @@ class extension extends control
|
||||
$this->extension->extractPackage($extension);
|
||||
|
||||
/* Save to database. */
|
||||
$this->extension->save2DB($extension);
|
||||
$this->extension->saveExtension($extension);
|
||||
|
||||
/* Copy files to target directory. */
|
||||
$this->view->files = $this->extension->copyPackageFiles($extension);
|
||||
|
||||
/* Judge need execute db install or not. */
|
||||
$data->status = 'installed';
|
||||
$data->dirs = $this->session->dirs2Created;
|
||||
$data->files = $this->view->files;
|
||||
|
||||
if($this->extension->needExecuteDB($extension, 'install'))
|
||||
{
|
||||
$return = $this->extension->executeDB($extension, 'install');
|
||||
@@ -145,11 +151,11 @@ class extension extends control
|
||||
$this->view->error = sprintf($this->lang->extension->errorInstallDB, $return->error);
|
||||
die($this->display());
|
||||
}
|
||||
$this->extension->updateStatus($extension, 'installed');
|
||||
$this->extension->updateExtension($extension, $data);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->extension->updateStatus($extension, 'installed');
|
||||
$this->extension->updateExtension($extension, $data);
|
||||
}
|
||||
|
||||
$this->view->downloadedPackage = !empty($downLink);
|
||||
@@ -157,15 +163,74 @@ class extension extends control
|
||||
$this->display();
|
||||
}
|
||||
|
||||
public function uninstall()
|
||||
/**
|
||||
* Uninstall an extension.
|
||||
*
|
||||
* @param string $extension
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function uninstall($extension)
|
||||
{
|
||||
$this->extension->removePackage($extension);
|
||||
$this->extension->executeDB($extension, 'uninstall');
|
||||
$this->extension->updateExtension($extension, array('status' => 'available'));
|
||||
}
|
||||
|
||||
public function activate()
|
||||
/**
|
||||
* Activate an extension;
|
||||
*
|
||||
* @param string $extension
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function activate($extension)
|
||||
{
|
||||
$this->extension->copyPackageFiles($extension);
|
||||
$this->extension->updateExtension($extension, array('status' => 'installed'));
|
||||
}
|
||||
|
||||
public function deactivate()
|
||||
/**
|
||||
* Deactivate an extension
|
||||
*
|
||||
* @param string $extension
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function deactivate($extension)
|
||||
{
|
||||
$this->extension->removePackage($extension);
|
||||
$this->extension->updateExtension($extension, array('status' => 'deactivated'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Upload an extension
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function upload()
|
||||
{
|
||||
if($_FILES)
|
||||
{
|
||||
$tmpName = $_FILES['file']['tmp_name'];
|
||||
$fileName = $_FILES['file']['name'];
|
||||
$extension = basename($fileName, '.zip');
|
||||
move_uploaded_file($tmpName, $this->app->getTmpRoot() . "/extension/$fileName");
|
||||
$this->locate(inlink('install', "extension=$extension"));
|
||||
}
|
||||
$this->display();
|
||||
}
|
||||
|
||||
/**
|
||||
* Erase an extension.
|
||||
*
|
||||
* @param string $extension
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function erase($extension)
|
||||
{
|
||||
$this->extension->erasePackage($extension);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
form{margin-top:150px}
|
||||
@@ -20,6 +20,7 @@ $lang->extension->obtain = '获得插件';
|
||||
$lang->extension->download = '下载插件';
|
||||
$lang->extension->downloadAB= '下载';
|
||||
$lang->extension->upload = '上传插件';
|
||||
$lang->extension->erase = '清除';
|
||||
|
||||
$lang->extension->installed = '已安装';
|
||||
$lang->extension->deactivated = '已禁用';
|
||||
@@ -49,6 +50,7 @@ $lang->extension->executeCommands = '<h3>执行下面的命令来修正
|
||||
$lang->extension->successDownloadedPackage = '成功下载插件';
|
||||
$lang->extension->successCopiedFiles = '成功拷贝文件';
|
||||
$lang->extension->successInstallDB = '成功安装数据库';
|
||||
$lang->extension->viewInstalled = '查看已安装插件';
|
||||
|
||||
$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>来修正。';
|
||||
|
||||
+184
-81
@@ -62,11 +62,6 @@ class extensionModel extends model
|
||||
$this->apiRoot = $this->config->extension->apiRoot;
|
||||
}
|
||||
|
||||
public function getLocalExtensions($status)
|
||||
{
|
||||
return $this->dao->findByStatus($status)->from(TABLE_EXTENSION)->fetchAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch data from an api.
|
||||
*
|
||||
@@ -116,6 +111,77 @@ class extensionModel extends model
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Download an extension.
|
||||
*
|
||||
* @param string $extension
|
||||
* @param string $downLink
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function downloadPackage($extension, $downLink)
|
||||
{
|
||||
$packageFile = $this->getPackageFile($extension);
|
||||
$this->agent->fetch($downLink);
|
||||
file_put_contents($packageFile, $this->agent->results);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get extensions by status.
|
||||
*
|
||||
* @param string $status
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function getLocalExtensions($status)
|
||||
{
|
||||
return $this->dao->select('*')->from(TABLE_EXTENSION)->where('status')->eq($status)->fi()->fetchAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get extension info from database.
|
||||
*
|
||||
* @param string $extension
|
||||
* @access public
|
||||
* @return object
|
||||
*/
|
||||
public function getInfoFromDB($extension)
|
||||
{
|
||||
return $this->dao->select('*')->from(TABLE_EXTENSION)->where('code')->eq($extension)->fi()->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get info of an extension from the package file.
|
||||
*
|
||||
* @param string $extension
|
||||
* @access public
|
||||
* @return object
|
||||
*/
|
||||
public function getInfoFromPackage($extension)
|
||||
{
|
||||
/* Init the data. */
|
||||
$data->name = $extension;
|
||||
$data->code = $extension;
|
||||
$data->version = 'unknown';
|
||||
$data->author = 'unknown';
|
||||
$data->desc = $extension;
|
||||
$data->site = 'unknown';
|
||||
$data->license = 'unknown';
|
||||
$data->zentaoVersion = '';
|
||||
|
||||
/* Redad the info file of the package. */
|
||||
$infoFile = "ext/$extension/doc/copyright.txt";
|
||||
if(!file_exists($infoFile)) return $data;
|
||||
|
||||
$info = (object)parse_ini_file($infoFile);
|
||||
foreach($info as $key => $value)
|
||||
{
|
||||
if(isset($data->$key)) $data->$key = $value;
|
||||
}
|
||||
if(isset($info->zentaoversion)) $data->zentaoVersion = $info->zentaoversion;
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the full path of the zip file of a extension.
|
||||
*
|
||||
@@ -176,9 +242,10 @@ class extensionModel extends model
|
||||
$return->errors = '';
|
||||
$return->mkdirCommands = '';
|
||||
$return->chmodCommands = '';
|
||||
$return->dirs2Created = array();
|
||||
|
||||
$appRoot = $this->app->getAppRoot();
|
||||
$pathes = $this->extractPathesFromPackage($extension);
|
||||
$pathes = $this->getPathesFromPackage($extension);
|
||||
foreach($pathes as $path)
|
||||
{
|
||||
if($path == 'db' or $path == 'doc') continue;
|
||||
@@ -196,6 +263,7 @@ class extensionModel extends model
|
||||
$return->errors .= sprintf($this->lang->extension->errorTargetPathNotExists, $path) . '<br />';
|
||||
$return->mkdirCommands .= "mkdir $path<br />";
|
||||
$return->chmodCommands .= "sudo chmod -R 777 $path<br />";
|
||||
$return->dirs2Created[] = $path;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -206,21 +274,6 @@ class extensionModel extends model
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Download an extension.
|
||||
*
|
||||
* @param string $extension
|
||||
* @param string $downLink
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function downloadPackage($extension, $downLink)
|
||||
{
|
||||
$packageFile = $this->getPackageFile($extension);
|
||||
$this->agent->fetch($downLink);
|
||||
file_put_contents($packageFile, $this->agent->results);
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract an extension.
|
||||
*
|
||||
@@ -240,13 +293,13 @@ class extensionModel extends model
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract pathes from an extension package.
|
||||
* Get pathes from an extension package.
|
||||
*
|
||||
* @param string $extension
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function extractPathesFromPackage($extension)
|
||||
public function getPathesFromPackage($extension)
|
||||
{
|
||||
$pathes = array();
|
||||
$packageFile = $this->getPackageFile($extension);
|
||||
@@ -292,6 +345,60 @@ class extensionModel extends model
|
||||
return $copiedFiles;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove an extension.
|
||||
*
|
||||
* @param string $extension
|
||||
* @access public
|
||||
* @return array un removed files.
|
||||
*/
|
||||
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();
|
||||
|
||||
if($dirs)
|
||||
{
|
||||
foreach($dirs as $dir)
|
||||
{
|
||||
if(!@rmdir($appRoot . $dir))
|
||||
{
|
||||
$unremovedDirs[] = $appRoot . $dir;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if($files)
|
||||
{
|
||||
foreach($files as $file)
|
||||
{
|
||||
if(!@unlink($appRoot . $file))
|
||||
{
|
||||
$unremovedFiles[] = $appRoot . $file;
|
||||
}
|
||||
}
|
||||
}
|
||||
return array('unremovedDirs' => $unremovedDirs, 'unremovedFiles' => $unremovedFiles);
|
||||
}
|
||||
|
||||
/**
|
||||
* Erase an extension's package file.
|
||||
*
|
||||
* @param string $extension
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function erasePackage($extension)
|
||||
{
|
||||
$packageFile = $this->getPackageFile($extension);
|
||||
unlink($packageFile);
|
||||
$this->dao->delete()->from(TABLE_EXTENSION)->where('code')->eq($extension)->exec();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the install db file.
|
||||
*
|
||||
@@ -352,6 +459,55 @@ class extensionModel extends model
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save the extension to database.
|
||||
*
|
||||
* @param int $extension
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function saveExtension($extension)
|
||||
{
|
||||
$extension = $this->getInfoFromPackage($extension);
|
||||
$extension->status = 'available';
|
||||
$this->dao->replace(TABLE_EXTENSION)->data($extension)->exec();
|
||||
}
|
||||
|
||||
/**
|
||||
* Update an extension.
|
||||
*
|
||||
* @param string $extension
|
||||
* @param string $status
|
||||
* @param array $files
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function updateExtension($extension, $data)
|
||||
{
|
||||
$data = (object)$data;
|
||||
$appRoot = $this->app->getAppRoot();
|
||||
|
||||
if(isset($data->dirs))
|
||||
{
|
||||
|
||||
foreach($data->dirs as $key => $dir)
|
||||
{
|
||||
$data->dirs[$key] = str_replace($appRoot, '', $dir);
|
||||
}
|
||||
$data->dirs = json_encode($data->dirs);
|
||||
}
|
||||
|
||||
if(isset($data->files))
|
||||
{
|
||||
foreach($data->files as $key => $file)
|
||||
{
|
||||
$data->files[$key] = str_replace($appRoot, '', $file);
|
||||
}
|
||||
$data->files = json_encode($data->files);
|
||||
}
|
||||
return $this->dao->update(TABLE_EXTENSION)->data($data)->where('code')->eq($extension)->exec();
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy a directory from an directory to another directory.
|
||||
*
|
||||
@@ -382,8 +538,12 @@ class extensionModel extends model
|
||||
$fullEntry = $from . $entry;
|
||||
if(is_file($fullEntry))
|
||||
{
|
||||
if(file_exists($to . $entry))
|
||||
{
|
||||
unlink($to . $entry);
|
||||
}
|
||||
copy($fullEntry, $to . $entry);
|
||||
$copiedFiles[] = $fullEntry;
|
||||
$copiedFiles[] = $to . $entry;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -427,61 +587,4 @@ class extensionModel extends model
|
||||
rmdir($dir);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save the extension to database.
|
||||
*
|
||||
* @param int $extension
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function save2DB($extension)
|
||||
{
|
||||
$extension = $this->getExtensionInfo($extension);
|
||||
$extension->status = 'available';
|
||||
$this->dao->replace(TABLE_EXTENSION)->data($extension)->exec();
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the status of an extension.
|
||||
*
|
||||
* @param string $extension
|
||||
* @param string $status
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function updateStatus($extension, $status)
|
||||
{
|
||||
return $this->dao->update(TABLE_EXTENSION)->set('status')->eq($status)->where('code')->eq($extension)->exec();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get info of an extension.
|
||||
*
|
||||
* @param string $extension
|
||||
* @access public
|
||||
* @return object
|
||||
*/
|
||||
public function getExtensionInfo($extension)
|
||||
{
|
||||
$data->name = $extension;
|
||||
$data->code = $extension;
|
||||
$data->version = 'unknown';
|
||||
$data->author = 'unknown';
|
||||
$data->desc = $extension;
|
||||
$data->site = 'unknown';
|
||||
$data->license = 'unknown';
|
||||
$data->zentaoVersion = '';
|
||||
|
||||
$infoFile = "ext/$extension/doc/copyright.txt";
|
||||
if(!file_exists($infoFile)) return $data;
|
||||
|
||||
$info = (object)parse_ini_file($infoFile);
|
||||
foreach($info as $key => $value)
|
||||
{
|
||||
if(isset($data->$key)) $data->$key = $value;
|
||||
}
|
||||
if(isset($info->zentaoversion)) $data->zentaoVersion = $info->zentaoversion;
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
<th class='w-50px'><?php echo $lang->extension->version;?></th>
|
||||
<th><?php echo $lang->extension->desc;?></th>
|
||||
<th class='w-100px'><?php echo $lang->extension->author;?></th>
|
||||
<th class='w-100px'><?php echo $lang->actions;?></th>
|
||||
<th class='w-150px'><?php echo $lang->actions;?></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@@ -29,9 +29,16 @@
|
||||
<td><?php echo $extension->desc;?></td>
|
||||
<td><?php echo $extension->author;?></td>
|
||||
<td class='a-center'>
|
||||
<?
|
||||
echo html::a(inlink('uninstall', "extension=$extension->code"), $lang->extension->uninstall, '', 'class=button-c');
|
||||
echo html::a(inlink('deactivate', "extension=$extension->code"), $lang->extension->deactivate, '', 'class=button-c');
|
||||
<?php
|
||||
$deactivateCode = html::a(inlink('deactivate', "extension=$extension->code"), $lang->extension->deactivate, '', "class='button-c iframe'");
|
||||
$activateCode = html::a(inlink('activate', "extension=$extension->code"), $lang->extension->activate, '', "class='button-c iframe'");
|
||||
$uninstallCode = html::a(inlink('uninstall', "extension=$extension->code"), $lang->extension->uninstall, '', "class='button-c iframe'");
|
||||
$installCode = html::a(inlink('install', "extension=$extension->code"), $lang->extension->install, '', "class='button-c iframe'");
|
||||
$eraseCode = html::a(inlink('erase', "extension=$extension->code"), $lang->extension->erase, '', "class='button-c iframe'");
|
||||
|
||||
if($extension->status == 'installed') echo $deactivateCode . $uninstallCode;
|
||||
if($extension->status == 'deactivated') echo $activateCode . $uninstallCode;
|
||||
if($extension->status == 'available') echo $installCode . $eraseCode;
|
||||
?>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
echo '<span id="deactivated">'. html::a(inlink('browse', "type=deactivated"), $lang->extension->deactivated) . '</span>';
|
||||
echo '<span id="available">' . html::a(inlink('browse', "type=available"), $lang->extension->available ) . '</span>';
|
||||
echo '<span id="obtain"> ' . html::a(inlink('obtain'), $lang->extension->obtain) . '</span>';
|
||||
echo '<span id="upload" >' . html::a(inlink('upload'), $lang->extension->upload) . '</span>';
|
||||
echo '<span id="upload" >' . html::a(inlink('upload'), $lang->extension->upload, '', "class='iframe'") . '</span>';
|
||||
?>
|
||||
<script>$('#<?php echo $tab;?>').addClass('active')</script>
|
||||
</div>
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
echo '</ul>';
|
||||
echo "<h3 class='success'>{$lang->extension->successInstallDB}</h3>";
|
||||
echo "<h1 class='a-center'>{$lang->extension->installFinished}</h1>";
|
||||
echo "<p class='a-center'>" . html::commonButton($lang->extension->viewInstalled, 'onclick=parent.location.href="' . inlink('browse') . '"') . '</p>';
|
||||
?>
|
||||
<?php endif;?>
|
||||
</td>
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
/**
|
||||
* The upload 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';?>
|
||||
<form method='post' enctype='multipart/form-data' class='a-center'>
|
||||
<input type='file' name='file' class='text-5' /></td>
|
||||
<?php echo html::submitButton($lang->extension->upload);?>
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user