📄 cs_weblog_deletestalespamcomments.prc
字号:
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[cs_weblog_DeleteStaleSpamComments]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[cs_weblog_DeleteStaleSpamComments]
GO
CREATE PROCEDURE [dbo].cs_weblog_DeleteStaleSpamComments
(
@SettingsID int,
@ExpirationDays int = 30
)
AS
SET Transaction Isolation Level Read UNCOMMITTED
DECLARE @CommentsToDelete TABLE
(PostID int)
-- temporarily store posts to delete
INSERT @CommentsToDelete
(PostID)
SELECT P.PostID
FROM cs_Posts P INNER JOIN cs_Sections S ON P.SectionID = S.SectionID
WHERE S.ApplicationType = 1 -- only posts in blogs
AND P.ApplicationPostType IN (4, 8) -- only comments/trackbacks
AND (P.PostStatus & 2) = 2 -- only posts marked as spam
AND P.PostDate < dateadd(d, -@ExpirationDays, getdate()) -- only posts that have been around for a while
-- archive deleted posts
INSERT cs_posts_deleted_archive
(PostID, UserID, SectionID, SettingsID, ApplicationType, Body, Subject, IPAddress, DeletedDate, ParentID, ThreadID, PostLevel, PostType)
SELECT P.PostID, P.UserID, P.SectionID, P.SettingsID, 1, P.Body, P.Subject, P.IPAddress, getdate(), P.ParentID, P.ThreadID, P.PostLevel, P.PostType
FROM cs_Posts P INNER JOIN @CommentsToDelete D ON P.PostID = D.PostID
-- actually delete posts
DELETE P
FROM cs_Posts P INNER JOIN @CommentsToDelete D ON P.PostID = D.PostID
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
grant execute on [dbo].[cs_weblog_DeleteStaleSpamComments] to public
go
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -