完善扩展插件机制
This commit is contained in:
@@ -10,6 +10,8 @@ namespace app\controller\admin;
|
||||
|
||||
use app\model\Addons as AddonsM;
|
||||
use app\model\Hooks;
|
||||
use think\facade\Cache;
|
||||
use think\facade\Config;
|
||||
|
||||
/**
|
||||
* @title 插件管理
|
||||
@@ -50,26 +52,22 @@ class Addons extends Base {
|
||||
* @title 安装插件
|
||||
*/
|
||||
public function install() {
|
||||
$addon_name = input('addon_name', '', 'trim,ucfirst');
|
||||
$class = get_addon_class($addon_name);
|
||||
$addon_name = input('addon_name', '', 'trim');
|
||||
$class = get_addons_class($addon_name);
|
||||
if (class_exists($class)) {
|
||||
$addons = new $class;
|
||||
$info = $addons->info;
|
||||
if (!$info || !$addons->checkInfo()) {
|
||||
//检测信息的正确性
|
||||
return $this->error('插件信息缺失');
|
||||
}
|
||||
$addons = get_addons_instance($addon_name);
|
||||
$info = $addons->getInfo();
|
||||
session('addons_install_error', null);
|
||||
$install_flag = $addons->install();
|
||||
if (!$install_flag) {
|
||||
return $this->error('执行插件预安装操作失败' . session('addons_install_error'));
|
||||
}
|
||||
$result = $this->addons->install($info);
|
||||
$result = AddonsM::install($info);
|
||||
if ($result) {
|
||||
cache('hooks', null);
|
||||
Cache::delete("sentcms_hooks");
|
||||
return $this->success('安装成功');
|
||||
} else {
|
||||
return $this->error($this->addons->getError());
|
||||
return $this->error("安装失败!");
|
||||
}
|
||||
} else {
|
||||
return $this->error('插件不存在');
|
||||
@@ -80,8 +78,9 @@ class Addons extends Base {
|
||||
* @title 卸载插件
|
||||
*/
|
||||
public function uninstall($id) {
|
||||
$result = $this->addons->uninstall($id);
|
||||
$result = AddonsM::uninstall($id);
|
||||
if ($result === false) {
|
||||
Cache::delete("sentcms_hooks");
|
||||
return $this->error($this->addons->getError(), '');
|
||||
} else {
|
||||
return $this->success('卸载成功!');
|
||||
@@ -91,12 +90,10 @@ class Addons extends Base {
|
||||
/**
|
||||
* @title 启用插件
|
||||
*/
|
||||
public function enable() {
|
||||
$id = input('id');
|
||||
cache('hooks', null);
|
||||
$model = model('Addons');
|
||||
$result = $model::where(array('id' => $id))->update(array('status' => 1));
|
||||
public function enable($id) {
|
||||
$result = AddonsM::update(['status' => 1], ['id' => $id]);
|
||||
if ($result) {
|
||||
Cache::delete('sentcms_hooks');
|
||||
return $this->success('启用成功');
|
||||
} else {
|
||||
return $this->error("启用失败!");
|
||||
@@ -106,12 +103,10 @@ class Addons extends Base {
|
||||
/**
|
||||
* @title 禁用插件
|
||||
*/
|
||||
public function disable() {
|
||||
$id = input('id');
|
||||
cache('hooks', null);
|
||||
$model = model('Addons');
|
||||
$result = $model::where(array('id' => $id))->update(array('status' => 0));
|
||||
public function disable($id) {
|
||||
$result = AddonsM::update(['status' => 0], ['id' => $id]);
|
||||
if ($result) {
|
||||
Cache::delete('sentcms_hooks');
|
||||
return $this->success('禁用成功');
|
||||
} else {
|
||||
return $this->error("禁用失败!");
|
||||
@@ -123,23 +118,30 @@ class Addons extends Base {
|
||||
*/
|
||||
public function config() {
|
||||
if ($this->request->isPost()) {
|
||||
# code...
|
||||
$config = $this->request->post();
|
||||
$id = $this->request->param('id');
|
||||
|
||||
$result = AddonsM::update(['config' => $config], ['id' => $id]);
|
||||
if ($result) {
|
||||
return $this->success('完成设置!');
|
||||
} else {
|
||||
return $this->error("无法完成设置!");
|
||||
}
|
||||
} else {
|
||||
$id = input('id', '', 'trim,intval');
|
||||
$id = $this->request->param('id');
|
||||
if (!$id) {
|
||||
return $this->error("非法操作!");
|
||||
}
|
||||
$info = $this->addons->find($id);
|
||||
$info = AddonsM::find($id);
|
||||
if (!empty($info)) {
|
||||
$class = get_addon_class($info['name']);
|
||||
$class = get_addons_instance($info['name']);
|
||||
|
||||
$keyList = array();
|
||||
$data = array(
|
||||
$keyList = $class->getConfig(true);
|
||||
$this->data = array(
|
||||
'keyList' => $keyList,
|
||||
'meta_title' => $info['title'] . " - 设置"
|
||||
);
|
||||
$this->assign($data);
|
||||
$this->setMeta($info['title'] . " - 设置");
|
||||
return $this->fetch('public/edit');
|
||||
return $this->fetch('admin/public/edit');
|
||||
} else {
|
||||
return $this->error("未安装此插件!");
|
||||
}
|
||||
@@ -222,7 +224,9 @@ class Addons extends Base {
|
||||
*/
|
||||
public function edithook($id) {
|
||||
if ($this->request->isPost()) {
|
||||
$result = $hooks->change();
|
||||
$data = $this->request->post();
|
||||
|
||||
$result = Hooks::update($data, ['id' => $data['id']]);
|
||||
if ($result !== false) {
|
||||
return $this->success("修改成功");
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user