关于删除帖子后论坛版块列表中不更新的解决办法
主要现象:当删除坛子中的帖子后对应的板块仍然显示最新已删除的帖子
解决办法:
1、未打开当前版块的回收站
打开系统中dnt_deletetopicbytidlist的存储过程
在“UPDATE [dnt_users] SET [posts] = [posts] - 1 WHERE [uid] = @tempPosterid”后插入
--更新forum开始
Declare @lasttid int
Declare @lastposterid int
Declare @lasttitle nvarchar(300)
Declare @lastpost datetime
Declare @lastposter nvarchar(100)
--更新lasttitle
SELECT TOP 2 @lasttid = [tid], @lastposterid = [posterid], @lasttitle = [title], @lastpost = [postdatetime], @lastposter = [poster] FROM [dnt_posts1] WHERE [tid] in (select tid from dnt_topics where fid = @tempFid and displayorder>-1) ORDER BY [pid] DESC
UPDATE [dnt_forums] SET lasttid=@lasttid,lastposterid=@lastposterid,lasttitle=@lasttitle,lastpost=@lastpost,lastposter=@lastposter where fid=@tempFid
--更新forum结束
2、当前版块已打开回收站,则把dnt_deletetopicbytidlist存储过程替换为
[code]set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
---解决了删除帖子forum不更新的问题
ALTER PROCEDURE [dbo].[dnt_deletetopicbytidlist]
@tidlist AS VARCHAR(2000),
@posttablename AS VARCHAR(20)
AS
DECLARE @postcount int
DECLARE @topiccount int
DECLARE @todaycount int
DECLARE @sqlstr nvarchar(4000)
DECLARE @fid varchar(2000)
DECLARE @posterid varchar(200)
Declare @tempTid int
DECLARE @tempFid int
DECLARE @tempPosterid int
DECLARE @tempLayer int
DECLARE @temppostdatetime datetime
DECLARE @tempfidlist AS VARCHAR(1000)
SET @fid = ''
SET @posterid = ''
SET @postcount=0
SET @topiccount=0
SET @todaycount=0
SET @tempfidlist = '';
IF @tidlist<>''
BEGIN
--对于回收站中的帖子不做处理
SET @sqlstr = 'DECLARE cu_dnt_posts CURSOR FOR SELECT [tid],[fid],[posterid],[layer],[postdatetime] FROM [' + @posttablename + '] WHERE [tid] IN (' + @tidlist + ')'
EXEC (@sqlstr)
OPEN cu_dnt_posts
FETCH NEXT FROM cu_dnt_posts into @tempTid,@tempFid,@tempPosterid,@tempLayer,@temppostdatetime
WHILE @@FETCH_STATUS = 0
BEGIN
SET @postcount = @postcount + 1
IF @tempLayer = 0
BEGIN
SET @topiccount = @topiccount + 1
END
IF DATEDIFF(d,@temppostdatetime,GETDATE()) = 0
BEGIN
SET @todaycount = @todaycount + 1
END
IF CHARINDEX(',' + LTRIM(STR(@tempFid)) + ',',@fid + ',') = 0
BEGIN
--SET @fid = @fid + ',' + LTRIM(STR(@tempFid))
SELECT @tempfidlist = ISNULL([parentidlist],'') FROM [dnt_forums] WHERE [fid] = @tempFid
IF RTRIM(@tempfidlist)<>''
BEGIN
SET @fid = RTRIM(@fid) + ',' + RTRIM(@tempfidlist) + ',' + CAST(@tempFid AS VARCHAR(10))
END
ELSE
BEGIN
SET @fid =RTRIM(@fid) + ',' + CAST(@tempFid AS VARCHAR(10))
END
END
UPDATE [dnt_users] SET [posts] = [posts] - 1 WHERE [uid] = @tempPosterid
--更新forum开始 add by liudao
Declare @lasttid int
Declare @lastposterid int
Declare @lasttitle nvarchar(300)
Declare @lastpost datetime
Declare @lastposter nvarchar(100)
--更新lasttitle
SELECT TOP 1 @lasttid = [tid], @lastposterid = [posterid], @lasttitle = [title], @lastpost = [postdatetime], @lastposter = [poster] FROM [dnt_posts1] WHERE [tid] in (select tid from dnt_topics where fid = @tempFid and tid<>@tempTid and displayorder>-1) ORDER BY [pid] DESC
UPDATE [dnt_forums] SET lasttid=@lasttid,lastposterid=@lastposterid,lasttitle=@lasttitle,lastpost=@lastpost,lastposter=@lastposter where fid=@tempFid
--更新forum结束
FETCH NEXT FROM cu_dnt_posts into @tempTid,@tempFid,@tempPosterid,@tempLayer,@temppostdatetime
END
CLOSE cu_dnt_posts
DEALLOCATE cu_dnt_posts
IF LEN(@fid)>0
BEGIN
SET @fid = SUBSTRING(@fid,2,LEN(@fid)-1)
UPDATE [dnt_statistics] SET [totaltopic]=[totaltopic] - @topiccount, [totalpost]=[totalpost] - @postcount
SET @sqlstr = 'UPDATE [dnt_forums] SET [posts]=[posts] - ' + cast(@postcount AS VARCHAR(10)) +
', [topics]=[topics] - ' + cast(@topiccount AS VARCHAR(10)) +
', [todayposts] = [todayposts] - ' + cast(@todaycount AS VARCHAR(10)) +
' WHERE [fid] IN (' + @fid + ')'
EXEC (@sqlstr)
SET @sqlstr = 'DELETE FROM [dnt_favorites] WHERE [tid] IN (' + @tidlist + ')'
EXEC (@sqlstr)
SET @sqlstr = 'DELETE FROM [dnt_polls] WHERE [tid] IN (' + @tidlist + ')'
EXEC (@sqlstr)
SET @sqlstr = 'DELETE FROM [' + @posttablename + '] WHERE [tid] IN (' + @tidlist + ')'
EXEC (@sqlstr)
END
SET @sqlstr = 'DELETE FROM [dnt_topics] WHERE [closed] IN (' + @tidlist + ') OR [tid] IN (' + @tidlist + ')'
EXEC (@sqlstr)
END
Declare @lastposterid int
Declare @lasttitle nvarchar(300)
Declare @lastpost datetime
Declare @lastposter nvarchar(100)
--更新lasttitle
SELECT TOP 2 @lasttid = [tid], @lastposterid = [posterid], @lasttitle = [title], @lastpost = [postdatetime], @lastposter = [poster] FROM [dnt_posts1] WHERE [tid] in (select tid from dnt_topics where fid = @tempFid and displayorder>-1) ORDER BY [pid] DESC
UPDATE [dnt_forums] SET lasttid=@lasttid,lastposterid=@lastposterid,lasttitle=@lasttitle,lastpost=@lastpost,lastposter=@lastposter where fid=@tempFid
--更新forum结束
2、当前版块已打开回收站,则把dnt_deletetopicbytidlist存储过程替换为
[code]set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
---解决了删除帖子forum不更新的问题
ALTER PROCEDURE [dbo].[dnt_deletetopicbytidlist]
@tidlist AS VARCHAR(2000),
@posttablename AS VARCHAR(20)
AS
DECLARE @postcount int
DECLARE @topiccount int
DECLARE @todaycount int
DECLARE @sqlstr nvarchar(4000)
DECLARE @fid varchar(2000)
DECLARE @posterid varchar(200)
Declare @tempTid int
DECLARE @tempFid int
DECLARE @tempPosterid int
DECLARE @tempLayer int
DECLARE @temppostdatetime datetime
DECLARE @tempfidlist AS VARCHAR(1000)
SET @fid = ''
SET @posterid = ''
SET @postcount=0
SET @topiccount=0
SET @todaycount=0
SET @tempfidlist = '';
IF @tidlist<>''
BEGIN
--对于回收站中的帖子不做处理
SET @sqlstr = 'DECLARE cu_dnt_posts CURSOR FOR SELECT [tid],[fid],[posterid],[layer],[postdatetime] FROM [' + @posttablename + '] WHERE [tid] IN (' + @tidlist + ')'
EXEC (@sqlstr)
OPEN cu_dnt_posts
FETCH NEXT FROM cu_dnt_posts into @tempTid,@tempFid,@tempPosterid,@tempLayer,@temppostdatetime
WHILE @@FETCH_STATUS = 0
BEGIN
SET @postcount = @postcount + 1
IF @tempLayer = 0
BEGIN
SET @topiccount = @topiccount + 1
END
IF DATEDIFF(d,@temppostdatetime,GETDATE()) = 0
BEGIN
SET @todaycount = @todaycount + 1
END
IF CHARINDEX(',' + LTRIM(STR(@tempFid)) + ',',@fid + ',') = 0
BEGIN
--SET @fid = @fid + ',' + LTRIM(STR(@tempFid))
SELECT @tempfidlist = ISNULL([parentidlist],'') FROM [dnt_forums] WHERE [fid] = @tempFid
IF RTRIM(@tempfidlist)<>''
BEGIN
SET @fid = RTRIM(@fid) + ',' + RTRIM(@tempfidlist) + ',' + CAST(@tempFid AS VARCHAR(10))
END
ELSE
BEGIN
SET @fid =RTRIM(@fid) + ',' + CAST(@tempFid AS VARCHAR(10))
END
END
UPDATE [dnt_users] SET [posts] = [posts] - 1 WHERE [uid] = @tempPosterid
--更新forum开始 add by liudao
Declare @lasttid int
Declare @lastposterid int
Declare @lasttitle nvarchar(300)
Declare @lastpost datetime
Declare @lastposter nvarchar(100)
--更新lasttitle
SELECT TOP 1 @lasttid = [tid], @lastposterid = [posterid], @lasttitle = [title], @lastpost = [postdatetime], @lastposter = [poster] FROM [dnt_posts1] WHERE [tid] in (select tid from dnt_topics where fid = @tempFid and tid<>@tempTid and displayorder>-1) ORDER BY [pid] DESC
UPDATE [dnt_forums] SET lasttid=@lasttid,lastposterid=@lastposterid,lasttitle=@lasttitle,lastpost=@lastpost,lastposter=@lastposter where fid=@tempFid
--更新forum结束
FETCH NEXT FROM cu_dnt_posts into @tempTid,@tempFid,@tempPosterid,@tempLayer,@temppostdatetime
END
CLOSE cu_dnt_posts
DEALLOCATE cu_dnt_posts
IF LEN(@fid)>0
BEGIN
SET @fid = SUBSTRING(@fid,2,LEN(@fid)-1)
UPDATE [dnt_statistics] SET [totaltopic]=[totaltopic] - @topiccount, [totalpost]=[totalpost] - @postcount
SET @sqlstr = 'UPDATE [dnt_forums] SET [posts]=[posts] - ' + cast(@postcount AS VARCHAR(10)) +
', [topics]=[topics] - ' + cast(@topiccount AS VARCHAR(10)) +
', [todayposts] = [todayposts] - ' + cast(@todaycount AS VARCHAR(10)) +
' WHERE [fid] IN (' + @fid + ')'
EXEC (@sqlstr)
SET @sqlstr = 'DELETE FROM [dnt_favorites] WHERE [tid] IN (' + @tidlist + ')'
EXEC (@sqlstr)
SET @sqlstr = 'DELETE FROM [dnt_polls] WHERE [tid] IN (' + @tidlist + ')'
EXEC (@sqlstr)
SET @sqlstr = 'DELETE FROM [' + @posttablename + '] WHERE [tid] IN (' + @tidlist + ')'
EXEC (@sqlstr)
END
SET @sqlstr = 'DELETE FROM [dnt_topics] WHERE [closed] IN (' + @tidlist + ') OR [tid] IN (' + @tidlist + ')'
EXEC (@sqlstr)
END
然后再把Forum.TopicAdminFactory的567行
return toDustbin == 0 ? DeleteTopics(topiclist) : SetTopicStatus(topiclist, "displayorder", -1);
改为
if(toDustbin != 0 )//放入回收站
{
SetTopicStatus(topiclist, "displayorder", -1);
}
return DeleteTopics(topiclist);//利用存储过程删除
{
SetTopicStatus(topiclist, "displayorder", -1);
}
return DeleteTopics(topiclist);//利用存储过程删除
最后别忘了如果操作了第二步编译才生效
总之如果没有设置版块的回收站只需第一步修改存储过程即可,如果打开了回收站处理起来就比较麻烦一些了。
注意:修改任何文件前请做好数据备份,以免带来不必要的麻烦
本文转自 liudao 博客园博客,原文链接:http://www.cnblogs.com/liudao/archive/2007/12/10/989147.html,如需转载请自行联系原作者