Stored Procedure Icon dbo.forums_MovePost

Stored Procedure Properties

Name Value
Owner dbo
Created 2004-05-31
Startup False
Encrypted False

Creation Options

Name Value
QUOTED_IDENTIFIER ON
ANSI_NULLS ON

Parameters

Name DataType Length Type
@PostID int 4 INPUT
@MoveToForumID int 4 INPUT
@UserName nvarchar 100 INPUT

Total: 3 parameter(s)

SQL

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO




CREATE     PROCEDURE forums_MovePost
(
	@PostID		int,
	@MoveToForumID	int,
	@UserName	nvarchar(50)
)
 AS
DECLARE @CurrentForum int
DECLARE @ApproveSetting bit
DECLARE @ForumName nvarchar(100)

	SELECT @ApproveSetting = Approved FROM Posts (nolock) WHERE PostID = @PostID
	IF @ApproveSetting = 0
		-- ok, so we're dealing with a post that is being moved via moderation
		-- does the user moving this have rights to moderate in the new forum? (or is the forum unmoderated?
		IF EXISTS(SELECT NULL FROM Moderators (nolock) WHERE (ForumID = @MoveToForumID OR ForumID = 0) AND Username = @UserName)
			OR (SELECT Moderated FROM Forums (nolock) WHERE ForumID = @MoveToForumID) = 0
			-- this user has rights, so we'll want to automagically approve the post in the new forum
			SELECT @ApproveSetting = 1
		
	-- only allow top-level messages to be moved
	IF (SELECT ParentID FROM Posts (nolock) WHERE PostID = @PostID) <> @PostID
		SELECT 0
	ELSE
	  BEGIN

		-- Get the forum we are moving from
		SELECT
			@CurrentForum = ForumID
		FROM
			Posts
		WHERE
			PostID = @PostID	

		-- Update the post with a new forum id
		UPDATE 
			Posts
		SET 
			ForumID = @MoveToForumID,
			Approved = @ApproveSetting
		WHERE 
			PostID = @PostID

		-- Update the forum statistics for the from forum
		exec Statistics_ResetForumStatistics @CurrentForum

		-- Update the forum statistics for the to forum
		exec Statistics_ResetForumStatistics @MoveToForumID

		-- Record to our moderation audit log
		INSERT INTO
			ModerationAudit
		VALUES
			(GetDate(), @PostID, @UserName, 3, null)

		IF @ApproveSetting = 0
			-- the post was moved but not approved
			SELECT 1
		ELSE
			-- the post was moved AND approved
			SELECT 2
	  END
















GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO


					

Generated on 26/08/2004 15:05:32 by DataAide.