完善扩展插件机制
This commit is contained in:
@@ -18,7 +18,8 @@ class Addons extends \think\Model {
|
||||
protected $insert = ['create_time'];
|
||||
|
||||
protected $type = [
|
||||
'hooks' => 'json'
|
||||
'hooks' => 'json',
|
||||
'config' => 'json'
|
||||
];
|
||||
|
||||
protected function setStatusAttr($value) {
|
||||
@@ -90,16 +91,15 @@ class Addons extends \think\Model {
|
||||
return $admin;
|
||||
}
|
||||
|
||||
public function install($data) {
|
||||
public static function install($data) {
|
||||
if ($data) {
|
||||
$info = $this->where('name', $data['name'])->value('id');
|
||||
if ($info) {
|
||||
$result = $this->save(array('isinstall'=>1, 'status'=>1), array('id'=>$info));
|
||||
}else{
|
||||
$result = false;
|
||||
$id = self::where('name', strtolower($data['name']))->value('id');
|
||||
$result = false;
|
||||
if ($id) {
|
||||
$result = self::update(['isinstall'=>1, 'status'=>1], ['id'=>$id]);
|
||||
}
|
||||
if (false !== $result) {
|
||||
return model('Hooks')->addHooks($data['name']);
|
||||
return Hooks::addHooks(strtolower($data['name']));
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
@@ -108,16 +108,16 @@ class Addons extends \think\Model {
|
||||
}
|
||||
}
|
||||
|
||||
public function uninstall($id) {
|
||||
$info = $this->get($id);
|
||||
public static function uninstall($id) {
|
||||
$info = self::find($id);
|
||||
if (!$info) {
|
||||
$this->error = "无此插件!";
|
||||
return false;
|
||||
}
|
||||
$class = get_addon_class($info['name']);
|
||||
$class = get_addons_class($info['name']);
|
||||
if (class_exists($class)) {
|
||||
//插件卸载方法
|
||||
$addons = new $class;
|
||||
$addons = get_addons_instance($info['name']);
|
||||
if (!method_exists($addons, 'uninstall')) {
|
||||
$this->error = "插件卸载方法!";
|
||||
return false;
|
||||
@@ -125,9 +125,9 @@ class Addons extends \think\Model {
|
||||
$result = $addons->uninstall();
|
||||
if ($result) {
|
||||
//卸载挂载点中的插件
|
||||
$result = model('Hooks')->removeHooks($info['name']);
|
||||
$result = Hooks::removeHooks($info['name']);
|
||||
//删除插件表中数据
|
||||
$this->where(array('id' => $id))->delete();
|
||||
$info->save(['isinstall' => 0]);
|
||||
return true;
|
||||
} else {
|
||||
$this->error = "无法卸载插件!";
|
||||
|
||||
Reference in New Issue
Block a user