cs_Moderate_Post_Move(最后的注释)
ALTER PROCEDURE [dbo].cs_Moderate_Post_Move
/**//*因为某些原因,我的伙伴要离开.低落啊!注释这些东西感觉多了也没什么必要.虽然有的都很长很麻烦,
但是真正看起来还是挺简单的,就是不要太去弄清他是什么意思.这样的话你首先得很清楚他的业务逻辑.
我看一般就是看大体的结构,然后细看.存储过程注释到此开告一段落了,我的伙伴走好.*/
(
@PostID int,
@MoveToSectionID int,
@MovedBy int,
@SettingsID int
)
AS
SET Transaction Isolation Level Read UNCOMMITTED
/**//*设置事务隔离级别,Read UNCOMMITTED 执行脏读或 0 级隔离锁定,这表示不发出共享锁,
也不接受排它锁。当设置该选项时,可以对数据执行未提交读或脏读;在事务结束前可以更
改数据内的数值,行也可以出现在数据集中或从数据集消失。该选项的作用与在事务内所有
语句中的所有表上设置 NOLOCK 相同。这是四个隔离级别中限制最小的级别。*/
DECLARE @ThreadID INT
DECLARE @SectionID INT
DECLARE @IsApproved BIT
DECLARE @PostLevel INT
DECLARE @Notes NVARCHAR(1024)
-- First, get information about the post that is about to be moved.
-- 首先获取要移动帖子的信息
SELECT
@ThreadID = ThreadID,
@SectionID = SectionID,
@PostLevel = PostLevel,
@IsApproved = IsApproved
FROM
cs_Posts
WHERE
PostID = @PostID and SettingsID = @SettingsID
-- EAD: We only move the post if it is a top level post.
IF @PostLevel = 1
BEGIN
DECLARE @MoveToIsModerated SMALLINT
-- Get information about the destination forum.
SELECT
@MoveToIsModerated = IsModerated
FROM
cs_Sections
WHERE
SectionID = @MoveToSectionID and SettingsID = @SettingsID
-- If the post is not already approved, check the moderation status and permissions on the moderator for approved status.
IF @IsApproved = 0
BEGIN
-- If the destination forum requires moderation, make sure the moderator has permission.
IF @MoveToIsModerated = 1
BEGIN
IF EXISTS(
SELECT
A.UserId
FROM
aspnet_UsersInRoles A, cs_UserProfile U
WHERE
U.MembershipID = A.UserId and
U.UserID = @MovedBy and U.SettingsID = @SettingsID
AND A.RoleId IN (
SELECT
RoleID
FROM
cs_SectionPermissions
WHERE
SectionID = @SectionID
AND AllowMask & convert(bigint,0x0000100000000000) = convert(bigint,0x0000100000000000) and SettingsID = @SettingsID
)
)
BEGIN
-- The moderator has permissions to move the post and approve it.
UPDATE
cs_Posts
SET
SectionID = @MoveToSectionID
WHERE
ThreadID = @ThreadID and SettingsID = @SettingsID
UPDATE
cs_PostAttachments
SET
SectionID = @MoveToSectionID
WHERE
PostID IN (SELECT PostID FROM cs_Posts WHERE ThreadID = @ThreadID AND SettingsID = @SettingsID)
UPDATE
cs_Threads
SET
SectionID = @MoveToSectionID
WHERE
ThreadID = @ThreadID and SettingsID = @SettingsID
-- approve the post
EXEC cs_Moderate_ApprovePost @PostID, @MovedBy, @SettingsID
SET @Notes = 'The post was moved and approved.'
PRINT @Notes
SELECT 2
END
ELSE BEGIN
-- The moderator has permissions to move the post but not approve.
UPDATE
cs_Posts
SET
SectionID = @MoveToSectionID
WHERE
ThreadID = @ThreadID and SettingsID = @SettingsID
UPDATE
cs_PostAttachments
SET
SectionID = @MoveToSectionID
WHERE
PostID IN (SELECT PostID FROM cs_Posts WHERE ThreadID = @ThreadID AND SettingsID = @SettingsID)
UPDATE
cs_Threads
SET
SectionID = @MoveToSectionID
WHERE
ThreadID = @ThreadID and SettingsID = @SettingsID
SET @Notes = 'The post was moved but not approved.'
PRINT @Notes
SELECT 1
END
END
ELSE BEGIN
UPDATE
cs_Posts
SET
SectionID = @MoveToSectionID
WHERE
ThreadID = @ThreadID and SettingsID = @SettingsID
UPDATE
cs_PostAttachments
SET
SectionID = @MoveToSectionID
WHERE
PostID IN (SELECT PostID FROM cs_Posts WHERE ThreadID = @ThreadID AND SettingsID = @SettingsID)
UPDATE
cs_Threads
SET
SectionID = @MoveToSectionID
WHERE
ThreadID = @ThreadID and SettingsID = @SettingsID
-- The destination forum is not moderated, approve the post and move the post.
EXEC cs_Moderate_ApprovePost @PostID, @MovedBy, @SettingsID
SET @Notes = 'The post was moved and approved.'
PRINT @Notes
SELECT 2
END
END
ELSE BEGIN
-- The post is already approved, move the post.
UPDATE
cs_Posts
SET
SectionID = @MoveToSectionID
WHERE
ThreadID = @ThreadID and SettingsID = @SettingsID
UPDATE
cs_PostAttachments
SET
SectionID = @MoveToSectionID
WHERE
PostID IN (SELECT PostID FROM cs_Posts WHERE ThreadID = @ThreadID AND SettingsID = @SettingsID)
UPDATE
cs_Threads
SET
SectionID = @MoveToSectionID
WHERE
ThreadID = @ThreadID and SettingsID = @SettingsID
print 'The approved post was moved.'
SET @Notes = 'The approved post was moved.'
SELECT 3
END
-- Reset the statistics on both forums.
EXEC cs_system_ResetForumStatistics @SectionID
EXEC cs_system_ResetForumStatistics @MoveToSectionID
-- Reset the thread statistics on the moved thread.
EXEC cs_system_ResetThreadStatistics @ThreadID
-- Update Moderation Audit table
EXEC cs_system_ModerationAction_AuditEntry 3, @MovedBy, @PostID, null, @SectionID, @SettingsID, @Notes
END
ELSE BEGIN
print 'The post was not moved.'
SELECT 0
END
ALTER PROCEDURE [dbo].cs_Moderate_Post_Move
/**//*因为某些原因,我的伙伴要离开.低落啊!注释这些东西感觉多了也没什么必要.虽然有的都很长很麻烦,
但是真正看起来还是挺简单的,就是不要太去弄清他是什么意思.这样的话你首先得很清楚他的业务逻辑.
我看一般就是看大体的结构,然后细看.存储过程注释到此开告一段落了,我的伙伴走好.*/
(
@PostID int,
@MoveToSectionID int,
@MovedBy int,
@SettingsID int
)
AS
SET Transaction Isolation Level Read UNCOMMITTED
/**//*设置事务隔离级别,Read UNCOMMITTED 执行脏读或 0 级隔离锁定,这表示不发出共享锁,
也不接受排它锁。当设置该选项时,可以对数据执行未提交读或脏读;在事务结束前可以更
改数据内的数值,行也可以出现在数据集中或从数据集消失。该选项的作用与在事务内所有
语句中的所有表上设置 NOLOCK 相同。这是四个隔离级别中限制最小的级别。*/
DECLARE @ThreadID INT
DECLARE @SectionID INT
DECLARE @IsApproved BIT
DECLARE @PostLevel INT
DECLARE @Notes NVARCHAR(1024)
-- First, get information about the post that is about to be moved.
-- 首先获取要移动帖子的信息
SELECT
@ThreadID = ThreadID,
@SectionID = SectionID,
@PostLevel = PostLevel,
@IsApproved = IsApproved
FROM
cs_Posts
WHERE
PostID = @PostID and SettingsID = @SettingsID
-- EAD: We only move the post if it is a top level post.
IF @PostLevel = 1
BEGIN
DECLARE @MoveToIsModerated SMALLINT
-- Get information about the destination forum.
SELECT
@MoveToIsModerated = IsModerated
FROM
cs_Sections
WHERE
SectionID = @MoveToSectionID and SettingsID = @SettingsID
-- If the post is not already approved, check the moderation status and permissions on the moderator for approved status.
IF @IsApproved = 0
BEGIN
-- If the destination forum requires moderation, make sure the moderator has permission.
IF @MoveToIsModerated = 1
BEGIN
IF EXISTS(
SELECT
A.UserId
FROM
aspnet_UsersInRoles A, cs_UserProfile U
WHERE
U.MembershipID = A.UserId and
U.UserID = @MovedBy and U.SettingsID = @SettingsID
AND A.RoleId IN (
SELECT
RoleID
FROM
cs_SectionPermissions
WHERE
SectionID = @SectionID
AND AllowMask & convert(bigint,0x0000100000000000) = convert(bigint,0x0000100000000000) and SettingsID = @SettingsID
)
)
BEGIN
-- The moderator has permissions to move the post and approve it.
UPDATE
cs_Posts
SET
SectionID = @MoveToSectionID
WHERE
ThreadID = @ThreadID and SettingsID = @SettingsID
UPDATE
cs_PostAttachments
SET
SectionID = @MoveToSectionID
WHERE
PostID IN (SELECT PostID FROM cs_Posts WHERE ThreadID = @ThreadID AND SettingsID = @SettingsID)
UPDATE
cs_Threads
SET
SectionID = @MoveToSectionID
WHERE
ThreadID = @ThreadID and SettingsID = @SettingsID
-- approve the post
EXEC cs_Moderate_ApprovePost @PostID, @MovedBy, @SettingsID
SET @Notes = 'The post was moved and approved.'
PRINT @Notes
SELECT 2
END
ELSE BEGIN
-- The moderator has permissions to move the post but not approve.
UPDATE
cs_Posts
SET
SectionID = @MoveToSectionID
WHERE
ThreadID = @ThreadID and SettingsID = @SettingsID
UPDATE
cs_PostAttachments
SET
SectionID = @MoveToSectionID
WHERE
PostID IN (SELECT PostID FROM cs_Posts WHERE ThreadID = @ThreadID AND SettingsID = @SettingsID)
UPDATE
cs_Threads
SET
SectionID = @MoveToSectionID
WHERE
ThreadID = @ThreadID and SettingsID = @SettingsID
SET @Notes = 'The post was moved but not approved.'
PRINT @Notes
SELECT 1
END
END
ELSE BEGIN
UPDATE
cs_Posts
SET
SectionID = @MoveToSectionID
WHERE
ThreadID = @ThreadID and SettingsID = @SettingsID
UPDATE
cs_PostAttachments
SET
SectionID = @MoveToSectionID
WHERE
PostID IN (SELECT PostID FROM cs_Posts WHERE ThreadID = @ThreadID AND SettingsID = @SettingsID)
UPDATE
cs_Threads
SET
SectionID = @MoveToSectionID
WHERE
ThreadID = @ThreadID and SettingsID = @SettingsID
-- The destination forum is not moderated, approve the post and move the post.
EXEC cs_Moderate_ApprovePost @PostID, @MovedBy, @SettingsID
SET @Notes = 'The post was moved and approved.'
PRINT @Notes
SELECT 2
END
END
ELSE BEGIN
-- The post is already approved, move the post.
UPDATE
cs_Posts
SET
SectionID = @MoveToSectionID
WHERE
ThreadID = @ThreadID and SettingsID = @SettingsID
UPDATE
cs_PostAttachments
SET
SectionID = @MoveToSectionID
WHERE
PostID IN (SELECT PostID FROM cs_Posts WHERE ThreadID = @ThreadID AND SettingsID = @SettingsID)
UPDATE
cs_Threads
SET
SectionID = @MoveToSectionID
WHERE
ThreadID = @ThreadID and SettingsID = @SettingsID
print 'The approved post was moved.'
SET @Notes = 'The approved post was moved.'
SELECT 3
END
-- Reset the statistics on both forums.
EXEC cs_system_ResetForumStatistics @SectionID
EXEC cs_system_ResetForumStatistics @MoveToSectionID
-- Reset the thread statistics on the moved thread.
EXEC cs_system_ResetThreadStatistics @ThreadID
-- Update Moderation Audit table
EXEC cs_system_ModerationAction_AuditEntry 3, @MovedBy, @PostID, null, @SectionID, @SettingsID, @Notes
END
ELSE BEGIN
print 'The post was not moved.'
SELECT 0
END
cs_Moderate_Forums
ALTER procedure [dbo].cs_Moderate_Forums
(
@SettingsID int,
@UserID int,
@ApplicationType smallint = 0
)
AS
SET Transaction Isolation Level Read UNCOMMITTED
/**//*设置事务隔离级别,Read UNCOMMITTED 执行脏读或 0 级隔离锁定,这表示不发出共享锁,
也不接受排它锁。当设置该选项时,可以对数据执行未提交读或脏读;在事务结束前可以更
改数据内的数值,行也可以出现在数据集中或从数据集消失。该选项的作用与在事务内所有
语句中的所有表上设置 NOLOCK 相同。这是四个隔离级别中限制最小的级别。*/
BEGIN
SELECT
PostsToModerate = (SELECT Count(PostID) FROM cs_Posts P WHERE SectionID = F.SectionID AND P.IsApproved = 0 and P.SettingsID = @SettingsID),
LastUserActivity = '1/1/1797',
F.SectionID, F.SettingsID, F.IsActive, F.ParentID, F.GroupID, F.Name, F.NewsgroupName, F.Description, F.DateCreated, F.Url, F.IsModerated,
F.DaysToView, F.SortOrder, F.TotalPosts, F.TotalThreads, F.DisplayMask, F.EnablePostStatistics, F.EnablePostPoints, F.EnableAutoDelete, F.EnableAnonymousPosting,
F.AutoDeleteThreshold, F.MostRecentPostID, F.MostRecentThreadID, F.MostRecentThreadReplies, F.MostRecentPostSubject, F.MostRecentPostAuthor,
F.MostRecentPostAuthorID, F.MostRecentPostDate, F.PostsToModerate, F.ForumType, F.IsSearchable, F.ApplicationType, F.ApplicationKey, F.Path,
F.PropertyNames as SectionPropertyNames, F.PropertyValues as SectionPropertyValues
FROM
cs_Sections F
WHERE
F.IsActive = 1 AND F.SettingsID = @SettingsID AND F.ApplicationType = @ApplicationType
END
ALTER procedure [dbo].cs_Moderate_Forums
(
@SettingsID int,
@UserID int,
@ApplicationType smallint = 0
)
AS
SET Transaction Isolation Level Read UNCOMMITTED
/**//*设置事务隔离级别,Read UNCOMMITTED 执行脏读或 0 级隔离锁定,这表示不发出共享锁,
也不接受排它锁。当设置该选项时,可以对数据执行未提交读或脏读;在事务结束前可以更
改数据内的数值,行也可以出现在数据集中或从数据集消失。该选项的作用与在事务内所有
语句中的所有表上设置 NOLOCK 相同。这是四个隔离级别中限制最小的级别。*/
BEGIN
SELECT
PostsToModerate = (SELECT Count(PostID) FROM cs_Posts P WHERE SectionID = F.SectionID AND P.IsApproved = 0 and P.SettingsID = @SettingsID),
LastUserActivity = '1/1/1797',
F.SectionID, F.SettingsID, F.IsActive, F.ParentID, F.GroupID, F.Name, F.NewsgroupName, F.Description, F.DateCreated, F.Url, F.IsModerated,
F.DaysToView, F.SortOrder, F.TotalPosts, F.TotalThreads, F.DisplayMask, F.EnablePostStatistics, F.EnablePostPoints, F.EnableAutoDelete, F.EnableAnonymousPosting,
F.AutoDeleteThreshold, F.MostRecentPostID, F.MostRecentThreadID, F.MostRecentThreadReplies, F.MostRecentPostSubject, F.MostRecentPostAuthor,
F.MostRecentPostAuthorID, F.MostRecentPostDate, F.PostsToModerate, F.ForumType, F.IsSearchable, F.ApplicationType, F.ApplicationKey, F.Path,
F.PropertyNames as SectionPropertyNames, F.PropertyValues as SectionPropertyValues
FROM
cs_Sections F
WHERE
F.IsActive = 1 AND F.SettingsID = @SettingsID AND F.ApplicationType = @ApplicationType
END
cs_Moderate_Forum_Roles
ALTER procedure [dbo].cs_Moderate_Forum_Roles
(
@SectionID int,
@SettingsID int
)
AS
SET Transaction Isolation Level Read UNCOMMITTED
/**//*设置事务隔离级别,Read UNCOMMITTED 执行脏读或 0 级隔离锁定,这表示不发出共享锁,
也不接受排它锁。当设置该选项时,可以对数据执行未提交读或脏读;在事务结束前可以更
改数据内的数值,行也可以出现在数据集中或从数据集消失。该选项的作用与在事务内所有
语句中的所有表上设置 NOLOCK 相同。这是四个隔离级别中限制最小的级别。*/
SELECT
R.RoleID,
R.RoleName as [Name],
Description
FROM
cs_SectionPermissions P,
aspnet_roles R
WHERE
P.RoleID = R.RoleID AND
P.allowmask & convert(bigint,0x0000100000000000) = convert(bigint,0x0000100000000000) AND
SectionID = @SectionID and P.SettingsID = @SettingsID
ALTER procedure [dbo].cs_Moderate_Forum_Roles
(
@SectionID int,
@SettingsID int
)
AS
SET Transaction Isolation Level Read UNCOMMITTED
/**//*设置事务隔离级别,Read UNCOMMITTED 执行脏读或 0 级隔离锁定,这表示不发出共享锁,
也不接受排它锁。当设置该选项时,可以对数据执行未提交读或脏读;在事务结束前可以更
改数据内的数值,行也可以出现在数据集中或从数据集消失。该选项的作用与在事务内所有
语句中的所有表上设置 NOLOCK 相同。这是四个隔离级别中限制最小的级别。*/
SELECT
R.RoleID,
R.RoleName as [Name],
Description
FROM
cs_SectionPermissions P,
aspnet_roles R
WHERE
P.RoleID = R.RoleID AND
P.allowmask & convert(bigint,0x0000100000000000) = convert(bigint,0x0000100000000000) AND
SectionID = @SectionID and P.SettingsID = @SettingsID