fix 卸载插件时删除插件配置
This commit is contained in:
parent
d8afa339de
commit
dd7803c90a
@ -101,6 +101,8 @@ def uninstall_plugin(plugin_id: str,
|
||||
if plugin == plugin_id:
|
||||
install_plugins.remove(plugin)
|
||||
break
|
||||
# 删除插件配置
|
||||
SystemConfigOper().delete_by_key(plugin_id)
|
||||
# 保存
|
||||
SystemConfigOper().set(SystemConfigKey.UserInstalledPlugins, install_plugins)
|
||||
# 重载插件管理器
|
||||
|
@ -26,6 +26,11 @@ class PluginData(Base):
|
||||
db.query(PluginData).filter(PluginData.plugin_id == plugin_id, PluginData.key == key).delete()
|
||||
Base.commit(db)
|
||||
|
||||
@staticmethod
|
||||
def del_plugin_data_by_plugin_id(db: Session, plugin_id: str):
|
||||
db.query(PluginData).filter(PluginData.plugin_id == plugin_id).delete()
|
||||
Base.commit(db)
|
||||
|
||||
@staticmethod
|
||||
def get_plugin_data_by_plugin_id(db: Session, plugin_id: str):
|
||||
return db.query(PluginData).filter(PluginData.plugin_id == plugin_id).all()
|
||||
|
@ -43,13 +43,16 @@ class PluginDataOper(DbOper):
|
||||
return json.loads(data.value)
|
||||
return data.value
|
||||
|
||||
def del_data(self, plugin_id: str, key: str) -> Any:
|
||||
def del_data(self, plugin_id: str, key: str = None) -> Any:
|
||||
"""
|
||||
删除插件数据
|
||||
:param plugin_id: 插件id
|
||||
:param key: 数据key
|
||||
"""
|
||||
PluginData.del_plugin_data_by_key(self._db, plugin_id, key)
|
||||
if key:
|
||||
PluginData.del_plugin_data_by_key(self._db, plugin_id, key)
|
||||
else:
|
||||
PluginData.del_plugin_data_by_plugin_id(self._db, plugin_id)
|
||||
|
||||
def truncate(self):
|
||||
"""
|
||||
|
@ -3,6 +3,7 @@ from typing import Any, Union
|
||||
|
||||
from app.db import DbOper, SessionFactory
|
||||
from app.db.models.systemconfig import SystemConfig
|
||||
from app.db.plugindata_oper import PluginDataOper
|
||||
from app.schemas.types import SystemConfigKey
|
||||
from app.utils.object import ObjectUtils
|
||||
from app.utils.singleton import Singleton
|
||||
@ -17,8 +18,11 @@ class SystemConfigOper(DbOper, metaclass=Singleton):
|
||||
加载配置到内存
|
||||
"""
|
||||
self._db = SessionFactory()
|
||||
self._syscomconfig = SystemConfig()
|
||||
# 插件数据
|
||||
self.plugindata = PluginDataOper(self._db)
|
||||
super().__init__(self._db)
|
||||
for item in SystemConfig.list(self._db):
|
||||
for item in self._syscomconfig.list(self._db):
|
||||
if ObjectUtils.is_obj(item.value):
|
||||
self.__SYSTEMCONF[item.key] = json.loads(item.value)
|
||||
else:
|
||||
@ -37,7 +41,7 @@ class SystemConfigOper(DbOper, metaclass=Singleton):
|
||||
value = json.dumps(value)
|
||||
elif value is None:
|
||||
value = ''
|
||||
conf = SystemConfig.get_by_key(self._db, key)
|
||||
conf = self._syscomconfig.get_by_key(self._db, key)
|
||||
if conf:
|
||||
if value:
|
||||
conf.update(self._db, {"value": value})
|
||||
@ -57,6 +61,17 @@ class SystemConfigOper(DbOper, metaclass=Singleton):
|
||||
return self.__SYSTEMCONF
|
||||
return self.__SYSTEMCONF.get(key)
|
||||
|
||||
def delete_by_key(self, key: str = None) -> Any:
|
||||
"""
|
||||
删除系统设置
|
||||
"""
|
||||
if self.__SYSTEMCONF.get(f"plugin.{key}"):
|
||||
del self.__SYSTEMCONF[f"plugin.{key}"]
|
||||
# 删除系统配置
|
||||
self._syscomconfig.delete_by_key(db=self._db, key=f"plugin.{key}")
|
||||
# 删除插件数据
|
||||
self.plugindata.del_data(plugin_id=key)
|
||||
|
||||
def __del__(self):
|
||||
if self._db:
|
||||
self._db.close()
|
||||
|
Loading…
x
Reference in New Issue
Block a user