From 601955e60d9b4b1b97a9c2055c946fb73fcbff27 Mon Sep 17 00:00:00 2001 From: xboard Date: Fri, 2 Jan 2026 18:30:21 +0800 Subject: [PATCH] fix: read plugin enabled from DB for consistency --- app/Traits/HasPluginConfig.php | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/app/Traits/HasPluginConfig.php b/app/Traits/HasPluginConfig.php index 138b09a..a44e2fc 100644 --- a/app/Traits/HasPluginConfig.php +++ b/app/Traits/HasPluginConfig.php @@ -17,6 +17,11 @@ trait HasPluginConfig */ protected ?string $pluginCode = null; + /** + * 插件启用状态(仅当前对象生命周期内缓存) + */ + protected ?bool $pluginEnabled = null; + /** * 获取插件配置 */ @@ -82,6 +87,7 @@ trait HasPluginConfig { $this->pluginCode = $pluginCode; $this->pluginConfig = null; // 重置配置缓存 + $this->pluginEnabled = null; } /** @@ -114,7 +120,15 @@ trait HasPluginConfig */ public function isPluginEnabled(): bool { - return (bool) $this->getConfig('enable', false); + if ($this->pluginEnabled !== null) { + return $this->pluginEnabled; + } + + $pluginCode = $this->getPluginCode(); + $isEnabled = Plugin::where('code', $pluginCode)->value('is_enabled'); + $this->pluginEnabled = (bool) $isEnabled; + + return $this->pluginEnabled; } /** @@ -125,5 +139,6 @@ trait HasPluginConfig $pluginCode = $this->getPluginCode(); Cache::forget("plugin_config_{$pluginCode}"); $this->pluginConfig = null; + $this->pluginEnabled = null; } } \ No newline at end of file