首先,这篇文章是写给Z-Blog插件开发人员作为参考的,仅仅提供一种思路。
新版Z-Blog中的PluginS插件已经支持检测插件版本了,给插件的安装和升级带来了很多方便。但是插件升级的同时可能造成插件数据库已经配置文件的覆盖,也就是说,升级后你可能只拥有一个初始化的插件。
这里提供一个方案,由插件自己解决这个问题,下面是相册插件windsphoto的include.asp部分代码,发出来说明一下,供参考。
- '定义数据库路径
- Const WP_DATA_PATH="data/20086282253180.mdb"
- '注册插件
- Call RegisterPlugin("WindsPhoto","ActivePlugin_WindsPhoto")
- '安装插件
- Function InstallPlugin_WindsPhoto()
- On Error Resume Next
- Call SetBlogHint_Custom("‼ 提示:[WindsPhoto]已启用,现在进入初始化系统设置.")
- Call WindsPhoto_Rebackup_Include()
- Call WindsPhoto_Database_Rename()
- Err.Clear
- End Function
- '首次安装数据库改名....
- Function WindsPhoto_Database_Rename()
- Dim fso, f, s, pathnew, ranNum
- randomize
- ranNum=int((99-10+1)*rnd+99)
- pathnew=year(now)&month(now)&day(now)&hour(now)&minute(now)&second(now)&ranNum& ".mdb"
- Set fso = CreateObject("Scripting.FileSystemObject")
- if fso.fileexists(BlogPath & "/plugin/windsphoto/data/winds.mdb") then
- Set f = fso.GetFile(BlogPath & "plugin/windsphoto/"& WP_DATA_PATH)
- f.name=pathnew
- Set f = Nothing
- Dim strContent,strWP_DATA_PATH
- strContent=LoadFromFile(BlogPath & "/PLUGIN/WindsPhoto/include.asp","utf-8")
- strWP_DATA_PATH="data/" & pathnew
- Call SaveValueForSetting(strContent,True,"String","WP_DATA_PATH",strWP_DATA_PATH)
- Call SaveToFile(BlogPath & "/PLUGIN/WindsPhoto/include.asp",strContent,"utf-8",False)
- end if
- End Function
- '还原备份设置
- Function WindsPhoto_Rebackup_Include()
- Dim strContent,fso
- Set fso=server.createobject("scripting.filesystemobject")
- if fso.fileexists(BlogPath & "/plugin/windsphoto/include.asp.bak") then
- strContent=LoadFromFile(BlogPath & "/plugin/windsphoto/include.asp.bak","utf-8")
- Call SaveToFile(BlogPath & "/plugin/windsphoto/include.asp",strContent,"utf-8",True)
- '删除初始数据库
- Call DelSiteFile("/plugin/windsphoto/data/winds.mdb")
- '跳转到插件设置
- Response.Redirect "../plugin/windsphoto/admin_setting.asp"
- End if
- Set fso=nothing
- End Function
两个函数,说明一下。WindsPhoto_Rebackup_Include() ,用来还原备份的配置文件include.asp.bak,这个文件可以在设置页面自动备份。同样,如果存在则还原,然后删除包里的初始数据库winds.mdb,后面一句跳转到设置页面也许就是多余的。
WindsPhoto_Database_Rename(),用来重命名初始数据库,先检查是否存在winds.mdb,如果存在,则利用当前时间+随机数重命名该文件,并保存到配置文件中。因为时间的唯一性,这样可以防止原来的数据库被覆盖的。
另外由于数据库的自动重命名,所以需要把数据库路径以变量的形式保存在配置文件include.asp中。
因为mdb格式的数据库文件比较大,所有采取这种方式。如果是XML做数据库,直接用还原配置文件的方法就可以了。
PS:我不是职业的程序员,对程序的驾驭能力很差,一切与计算机相关的纯属自学,如果有什么不妥的地方还请多多指教。