install plugin
This commit is contained in:
parent
6b1663f54b
commit
f75848afcf
|
|
@ -11,6 +11,7 @@
|
||||||
|
|
||||||
namespace Beike\Admin\Http\Controllers;
|
namespace Beike\Admin\Http\Controllers;
|
||||||
|
|
||||||
|
use Beike\Repositories\PluginRepo;
|
||||||
use Exception;
|
use Exception;
|
||||||
use Beike\Plugin\Manager;
|
use Beike\Plugin\Manager;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
|
|
@ -38,8 +39,8 @@ class PluginController extends Controller
|
||||||
*/
|
*/
|
||||||
public function install(Request $request, $code): array
|
public function install(Request $request, $code): array
|
||||||
{
|
{
|
||||||
$plugin = (new Manager)->getPlugin($code);
|
$plugin = (new Manager)->getPluginOrFail($code);
|
||||||
// dd($plugin);
|
PluginRepo::installPlugin($plugin);
|
||||||
return json_success("安装成功");
|
return json_success("安装成功");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -52,8 +53,8 @@ class PluginController extends Controller
|
||||||
*/
|
*/
|
||||||
public function uninstall(Request $request, $code): array
|
public function uninstall(Request $request, $code): array
|
||||||
{
|
{
|
||||||
$plugin = (new Manager)->getPlugin($code);
|
$plugin = (new Manager)->getPluginOrFail($code);
|
||||||
// dd($plugin);
|
PluginRepo::uninstallPlugin($plugin);
|
||||||
return json_success("卸载成功");
|
return json_success("卸载成功");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -66,7 +67,7 @@ class PluginController extends Controller
|
||||||
*/
|
*/
|
||||||
public function edit(Request $request, $code): View
|
public function edit(Request $request, $code): View
|
||||||
{
|
{
|
||||||
$data['plugin'] = (new Manager)->getPlugin($code);
|
$data['plugin'] = (new Manager)->getPluginOrFail($code);
|
||||||
return view('admin::pages.plugins.form', $data);
|
return view('admin::pages.plugins.form', $data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -79,10 +80,7 @@ class PluginController extends Controller
|
||||||
*/
|
*/
|
||||||
public function update(Request $request, $code): array
|
public function update(Request $request, $code): array
|
||||||
{
|
{
|
||||||
$plugin = (new Manager)->getPlugin($code);
|
(new Manager)->getPluginOrFail($code);
|
||||||
if (empty($plugin)) {
|
|
||||||
throw new Exception("无效的插件");
|
|
||||||
}
|
|
||||||
$fields = $request->all();
|
$fields = $request->all();
|
||||||
SettingRepo::update('plugin', $code, $fields);
|
SettingRepo::update('plugin', $code, $fields);
|
||||||
return json_success("编辑成功");
|
return json_success("编辑成功");
|
||||||
|
|
@ -97,10 +95,7 @@ class PluginController extends Controller
|
||||||
*/
|
*/
|
||||||
public function updateStatus(Request $request, $code): array
|
public function updateStatus(Request $request, $code): array
|
||||||
{
|
{
|
||||||
$plugin = (new Manager)->getPlugin($code);
|
(new Manager)->getPluginOrFail($code);
|
||||||
if (empty($plugin)) {
|
|
||||||
throw new Exception("无效的插件");
|
|
||||||
}
|
|
||||||
$status = $request->get('status');
|
$status = $request->get('status');
|
||||||
SettingRepo::update('plugin', $code, ['status' => $status]);
|
SettingRepo::update('plugin', $code, ['status' => $status]);
|
||||||
return json_success("编辑成功");
|
return json_success("编辑成功");
|
||||||
|
|
|
||||||
|
|
@ -76,6 +76,20 @@ class Manager
|
||||||
return $plugins[$code] ?? null;
|
return $plugins[$code] ?? null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取单个插件
|
||||||
|
*
|
||||||
|
* @throws \Exception
|
||||||
|
*/
|
||||||
|
public function getPluginOrFail($code): ?Plugin
|
||||||
|
{
|
||||||
|
$plugin = $this->getPlugin($code);
|
||||||
|
if (empty($plugin)) {
|
||||||
|
throw new \Exception('无效的插件');
|
||||||
|
}
|
||||||
|
return $plugin;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取插件目录以及配置
|
* 获取插件目录以及配置
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,43 @@ class PluginRepo
|
||||||
{
|
{
|
||||||
public static $installedPlugins;
|
public static $installedPlugins;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 安装插件到系统: 插入数据
|
||||||
|
* @param $plugin
|
||||||
|
*/
|
||||||
|
public static function installPlugin($plugin)
|
||||||
|
{
|
||||||
|
$type = $plugin->type;
|
||||||
|
$code = $plugin->code;
|
||||||
|
$plugin = Plugin::query()
|
||||||
|
->where('type', $type)
|
||||||
|
->where('code', $code)
|
||||||
|
->first();
|
||||||
|
if (empty($plugin)) {
|
||||||
|
Plugin::query()->create([
|
||||||
|
'type' => $type,
|
||||||
|
'code' => $code,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 从系统卸载插件: 删除数据
|
||||||
|
* @param $plugin
|
||||||
|
*/
|
||||||
|
public static function uninstallPlugin($plugin)
|
||||||
|
{
|
||||||
|
$type = $plugin->type;
|
||||||
|
$code = $plugin->code;
|
||||||
|
Plugin::query()
|
||||||
|
->where('type', $type)
|
||||||
|
->where('code', $code)
|
||||||
|
->delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 判断插件是否安装
|
* 判断插件是否安装
|
||||||
*
|
*
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue