yafuser2010
2010-01-11T03:37:59Z
Hi,
We are using YAF Source code to create our forum. But we faced some problem.
While creating a forum a 'Parent Forum' can be assigned to it, if the forum creation tree is like below ...

Forum1 (Parent for Forum2)
>Forum2 (Parent for Forum3)
>>Forum3

then again we can make Forum3 as Parent Forum for Forum1 like below...


Forum1 (Parent for Forum2)
>Forum2 (Parent for Forum3)
>>Forum3 (Parent for Forum1)
>>>Forum1

Then once the above scenario occurs the complete SET OF FORUMS WILL DISAPPEAR from forum list. i.e
Forum1,Forum2,Forum3.

How to over come from this scenario?
Please help.
New YAF User
Sponsor
bbobb
  •  bbobb
  • 100% (Exalted)
  • YAF Developer
2010-01-11T09:47:07Z
Mek noticed the problem
http://forum.yetanotherf...ild-forum.aspx#post39867 
It requires an sp or function to check circular dependencies.
This an untested temporary solution, and no garantee that there will not be bugs.
Add this to /mssql/functions.sql
create function [{databaseOwner}].[{objectQualifier}forum_save_parentschecker](@ForumID int, @ParentID int) returns int as

begin
-- Checks if the forum is already referenced as a parent  
	declare @dependency int = 0
	declare @haschildren int = 0
	declare @frmtmp int
	declare @prntmp int
	select @dependency=ForumID from [{databaseOwner}].[{objectQualifier}Forum] where ParentID=@ForumID AND ForumID = @ParentID;
    if @dependency > 0 
    begin
    return @ParentID 
    end
 
	if exists(select 1 from [{databaseOwner}].[{objectQualifier}Forum] where ParentID=@ForumID)
		begin		
		declare c cursor for
		select ForumID,ParentID from [{databaseOwner}].[{objectQualifier}Forum] 
		where ParentID = @ForumID
		
		open c
		
		fetch next from c into @frmtmp,@prntmp
		while @@FETCH_STATUS = 0
		begin
		if @frmtmp > 0 AND @frmtmp IS NOT NULL 
		 begin		 
		    set @haschildren= [{databaseOwner}].[{objectQualifier}forum_save_parentschecker](@frmtmp,@ParentID)			
		    if  @prntmp = @ParentID
		    begin
		    set @dependency= @ParentID
		    end	
		    else if @haschildren > 0
		    begin
		    set @dependency= @haschildren
		    end		
		end
		fetch next from c into @frmtmp,@prntmp
		end
		close c
		deallocate c	
    end
	return @dependency
end
GO

and replace this in /mssql/procedures.sql
CREATE procedure [{databaseOwner}].[{objectQualifier}forum_save](
	@ForumID 		int,
	@CategoryID		int,
	@ParentID		int=null,
	@Name			nvarchar(50),
	@Description	nvarchar(255),
	@SortOrder		smallint,
	@Locked			bit,
	@Hidden			bit,
	@IsTest			bit,
	@Moderated		bit,
	@RemoteURL		nvarchar(100)=null,
	@ThemeURL		nvarchar(100)=null,
	@AccessMaskID	int = null
       
) as
begin
	declare @BoardID	int
	declare @Flags		int
        declare @HasDependency	int	
	
	set @Flags = 0
	if @Locked<>0 set @Flags = @Flags | 1
	if @Hidden<>0 set @Flags = @Flags | 2
	if @IsTest<>0 set @Flags = @Flags | 4
	if @Moderated<>0 set @Flags = @Flags | 8

	if @ForumID>0 begin
           if @ParentID > 0 begin
          SET @HasDependency = [{databaseOwner}].[{objectQualifier}forum_save](@ForumID, @ParentID)
           end
           if (@HasDependency <= 0 OR @HasDependency IS NULL) begin                       	
		update [{databaseOwner}].[{objectQualifier}Forum] set 
			ParentID=@ParentID,
			Name=@Name,
			Description=@Description,
			SortOrder=@SortOrder,
			CategoryID=@CategoryID,
			RemoteURL = @RemoteURL,
			ThemeURL = @ThemeURL,
			Flags = @Flags
		where ForumID=@ForumID	
        end
        end
	else begin
		select @BoardID=BoardID from [{databaseOwner}].[{objectQualifier}Category] where CategoryID=@CategoryID
	
		insert into [{databaseOwner}].[{objectQualifier}Forum](ParentID,Name,Description,SortOrder,CategoryID,NumTopics,NumPosts,RemoteURL,ThemeURL,Flags)
		values(@ParentID,@Name,@Description,@SortOrder,@CategoryID,0,0,@RemoteURL,@ThemeURL,@Flags)
		select @ForumID = SCOPE_IDENTITY()

		insert into [{databaseOwner}].[{objectQualifier}ForumAccess](GroupID,ForumID,AccessMaskID) 
		select GroupID,@ForumID,@AccessMaskID
		from [{databaseOwner}].[{objectQualifier}Group]
		where BoardID=@BoardID
	end
	select ForumID = @ForumID
end
GO

yafuser2010
2010-01-12T08:49:44Z
Thank you bbobb, it worked for us. 🙂
New YAF User

About Us

The YAF.NET is an open source .NET forum project. YAF.NET is supported by an team of international developers who are build community by building community software.

Powered by Resharper Donate with PayPal button

Project Twitter Updates

Copyright © YetAnotherForum.NET & Ingo Herbote. All rights reserved