Revert "refactor: core plugins to plugins-core"

This reverts commit c0b6ee1763.
This commit is contained in:
Xboard
2026-04-19 08:06:51 +00:00
parent c36054b970
commit e61e3b6563
25 changed files with 107 additions and 137 deletions
+13 -60
View File
@@ -14,7 +14,6 @@ use Illuminate\Support\Str;
class PluginManager
{
protected string $pluginPath;
protected string $corePluginPath;
protected array $loadedPlugins = [];
protected bool $pluginsInitialized = false;
protected array $configTypesCache = [];
@@ -22,7 +21,6 @@ class PluginManager
public function __construct()
{
$this->pluginPath = base_path('plugins');
$this->corePluginPath = base_path('plugins-core');
}
/**
@@ -33,42 +31,14 @@ class PluginManager
return 'Plugin\\' . Str::studly($pluginCode);
}
public function resolvePluginPath(string $pluginCode): ?string
{
$dirName = Str::studly($pluginCode);
$corePath = $this->corePluginPath . '/' . $dirName;
if (File::isDirectory($corePath)) {
return $corePath;
}
$userPath = $this->pluginPath . '/' . $dirName;
if (File::isDirectory($userPath)) {
return $userPath;
}
return null;
}
/**
* 获取插件的基础路径
*/
public function getPluginPath(string $pluginCode): string
{
return $this->resolvePluginPath($pluginCode)
?? $this->pluginPath . '/' . Str::studly($pluginCode);
}
public function getUserPluginPath(string $pluginCode): string
{
return $this->pluginPath . '/' . Str::studly($pluginCode);
}
public function isCorePlugin(string $pluginCode): bool
{
$dirName = Str::studly($pluginCode);
return File::isDirectory($this->corePluginPath . '/' . $dirName);
}
public function getPluginPaths(): array
{
return [$this->corePluginPath, $this->pluginPath];
}
/**
* 加载插件类
*/
@@ -429,19 +399,17 @@ class PluginManager
*/
public function delete(string $pluginCode): bool
{
// 先卸载插件
if (Plugin::where('code', $pluginCode)->exists()) {
$this->uninstall($pluginCode);
}
if ($this->isCorePlugin($pluginCode)) {
throw new \Exception('核心插件不允许删除');
}
$pluginPath = $this->getUserPluginPath($pluginCode);
$pluginPath = $this->getPluginPath($pluginCode);
if (!File::exists($pluginPath)) {
throw new \Exception('插件不存在');
}
// 删除插件目录
File::deleteDirectory($pluginPath);
return true;
@@ -559,7 +527,7 @@ class PluginManager
throw new \Exception('插件配置文件格式错误');
}
$targetPath = $this->getUserPluginPath($config['code']);
$targetPath = $this->pluginPath . '/' . Str::studly($config['code']);
if (File::exists($targetPath)) {
$installedConfigPath = $targetPath . '/config.json';
if (!File::exists($installedConfigPath)) {
@@ -710,27 +678,12 @@ class PluginManager
*/
public static function installDefaultPlugins(): void
{
$pluginManager = app(self::class);
$coreDir = base_path('plugins-core');
if (!File::isDirectory($coreDir)) {
return;
}
foreach (File::directories($coreDir) as $directory) {
$configFile = $directory . '/config.json';
if (!File::exists($configFile)) {
continue;
}
$config = json_decode(File::get($configFile), true);
$code = $config['code'] ?? null;
if (!$code) {
continue;
}
if (!Plugin::where('code', $code)->exists()) {
$pluginManager->install($code);
$pluginManager->enable($code);
Log::info("Installed and enabled core plugin: {$code}");
foreach (Plugin::PROTECTED_PLUGINS as $pluginCode) {
if (!Plugin::where('code', $pluginCode)->exists()) {
$pluginManager = app(self::class);
$pluginManager->install($pluginCode);
$pluginManager->enable($pluginCode);
Log::info("Installed and enabled default plugin: {$pluginCode}");
}
}
}