InstantASP Community Forums
Home       Members    Calendar    Who's On
Welcome Guest ( Login | Register )
        


SQL Script for Forum Subscriptions Expand / Collapse
Author
Message
Posted 18/09/2005 16:51:43
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: Forum Members
Last Login: 27/10/2005 08:25:40
Posts: 6, Visits: 8
Here is a SQL script I created that will automatically subscribe all memebers to all forums in which they are a group member. 

The script was written quickly and probably needs to suggestions or adjustments.

I have added this script to execute as a trigger on the InstantForum_ForumsRoles and InstantASP_UsersRoles. Any time data is changed in these tables this trigger is fired.

One of the key points to this script is the second part. It automatically removes anyone from a forum subscription if their group permissions are removed from that forum. I am not that familiar with InstantASP Forum, my initial observation is if someone is removed from a forum, or banned from all the forums, they will still receive the subscription notices.

Anyway, take a look and let me know if this is problematic.

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

ALTER  PROCEDURE sp_MITS_UpdateForumSubscriptions
as

/* Insert any users that are assigned to forum roles in the forum subscriptions table */

INSERT INTO InstantForum_ForumSubscriptions (ForumId, UserId, SubscriptionType)
SELECT fo.ForumId, u.UserId, SubType=4
FROM InstantForum_ForumsRoles fr
JOIN InstantASP_Roles r ON fr.RoleId=r.RoleId
JOIN InstantForum_Forums fo ON fr.ForumId=fo.ForumId
JOIN InstantASP_UsersRoles ur ON fr.RoleId = ur.RoleId
JOIN InstantASP_Users u ON u.UserId = ur.UserId
LEFT OUTER JOIN InstantForum_ForumSubscriptions fs ON fs.UserId=u.UserId AND fs.ForumId=fo.ForumId
WHERE fo.IsCategory=0 AND fs.UserId is null
GROUP BY u.UserId, fo.ForumId


/*Remove any users that no longer belong to the correct roles from the subscriptions tables */

DELETE FROM InstantForum_ForumSubscriptions
WHERE ForumSubscriptionId IN
(
SELECT fs.ForumSubscriptionId
FROM InstantForum_ForumSubscriptions fs
LEFT OUTER JOIN
(
SELECT fs.ForumId, fs.UserId, fr.ForumRoleId
FROM InstantForum_ForumSubscriptions fs
JOIN InstantASP_UsersRoles ur ON fs.UserId=ur.UserId
LEFT OUTER JOIN InstantForum_ForumsRoles fr ON fs.ForumId=fr.ForumId AND ur.RoleId=fr.RoleId
WHERE fr.ForumRoleId is NOT NULL
)
fj ON fj.ForumId=fs.ForumId AND fj.UserId=fs.UserId
WHERE fj.ForumId IS NULL
)


GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO


CREATE TRIGGER tg_MITS_UpdateForumSubscriptions2
ON InstantForum_ForumsRoles
for DELETE,INSERT,UPDATE
AS
 EXEC sp_MITS_UpdateForumSubscriptions

go


CREATE TRIGGER tg_MITS_UpdateForumSubscriptions
ON InstantASP_UsersRoles

for DELETE,INSERT,UPDATE
AS
 EXEC sp_MITS_UpdateForumSubscriptions

go

Post #8518
Posted 19/09/2005 08:38:55


IF.NET 4.2 Coming Soon

IF.NET 4.2 Coming SoonIF.NET 4.2 Coming SoonIF.NET 4.2 Coming SoonIF.NET 4.2 Coming SoonIF.NET 4.2 Coming SoonIF.NET 4.2 Coming SoonIF.NET 4.2 Coming SoonIF.NET 4.2 Coming Soon

Group: Administrators
Last Login: 24/11/2008 12:47:40
Posts: 1,956, Visits: 3,019
Hi Jon,

Many thanks for making this available. When i have a moment i'll review the SQL and provide any further comments. Good stuff


Kindest Regards,

Ryan Healey
Director / Developer

Explore our products...
http://demos.instantasp.co.uk/

Post #8531
« Prev Topic | Next Topic »

Reading This Topic Expand / Collapse
Active Users: 0 (0 guests, 0 members, 0 anonymous members)
No members currently viewing this topic.
Forum Moderators: Ryan Healey, Mark Christianson, Bare, James Trott

Permissions Expand / Collapse

All times are GMT, Time now is 2:31am

Powered by InstantForum.NET v4.1.4 © 2008
Execution: 0.250. 10 queries. Compression Disabled.
Home | Products | Purchase | Support | Company | Contact Us
Privacy Statement | © 1999-2007 InstantASP Limited. All Rights Reserved.