fix: read plugin enabled from DB for consistency
This commit is contained in:
@@ -17,6 +17,11 @@ trait HasPluginConfig
|
|||||||
*/
|
*/
|
||||||
protected ?string $pluginCode = null;
|
protected ?string $pluginCode = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 插件启用状态(仅当前对象生命周期内缓存)
|
||||||
|
*/
|
||||||
|
protected ?bool $pluginEnabled = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取插件配置
|
* 获取插件配置
|
||||||
*/
|
*/
|
||||||
@@ -82,6 +87,7 @@ trait HasPluginConfig
|
|||||||
{
|
{
|
||||||
$this->pluginCode = $pluginCode;
|
$this->pluginCode = $pluginCode;
|
||||||
$this->pluginConfig = null; // 重置配置缓存
|
$this->pluginConfig = null; // 重置配置缓存
|
||||||
|
$this->pluginEnabled = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -114,7 +120,15 @@ trait HasPluginConfig
|
|||||||
*/
|
*/
|
||||||
public function isPluginEnabled(): bool
|
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();
|
$pluginCode = $this->getPluginCode();
|
||||||
Cache::forget("plugin_config_{$pluginCode}");
|
Cache::forget("plugin_config_{$pluginCode}");
|
||||||
$this->pluginConfig = null;
|
$this->pluginConfig = null;
|
||||||
|
$this->pluginEnabled = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user