Try our conversational search powered by Generative AI!

Geta Categories Plugin Error: CategoryRoot(1)" is not allowed to be created under parent of content type "SysContentFolder"

Vote:
 

We wanted to use the geta categories plugin. This worked on local pc without a problem. But on development environment we get an exception on start

EPiServer.Core.EPiServerException: Content type "CategoryRoot(1)" is not allowed to be created under parent of content type "SysContentFolder"    at EPiServer.Core.Internal.DefaultContentRepository.ValidateContentTypeAvailability(IContent content, ContentReference parentLink)    at EPiServer.Core.Internal.DefaultContentRepository.Save(IContent content, SaveAction action, AccessLevel access)    at Geta.Optimizely.Categories.Extensions.ContentRepositoryExtensions.GetOrCreateCategoriesRoot(IContentRepository contentRepository, ContentReference parentLink, String name, String routeSegment)    at Geta.Optimizely.Categories.Extensions.ContentRepositoryExtensions.GetOrCreateGlobalCategoriesRoot(IContentRepository contentRepository)    at GlobalCategoriesRootGetter(Object )  ....

I wonder why the plugin or Epi is trying to create a new ContentType CategoryRoot(1), that looks like there is already one CategoryRoot. But then i wonder why it could not be resolved on start in GetOrCreateCategoriesRoot. The exception itself seems to come because the CategoryRoot is not allowed under the SysContentFolder. I think the table where i find this is tblContentTypeToContentType. It's empty on local, which explains why we had no issues there. But even if i use this sql to create it in dev, it does not fix the issue:

INSERT INTO tblContentTypeToContentType
  (fkContentTypeParentID, fkContentTypeChildID, Access, Availability, Allow)
  VALUES
  ((select pkId from tblContentType Where Name = 'SysContentFolder'), (select pkId from tblContentType Where Name = 'CategoryRoot'), 0, 0, 1)

What is the cause of the error and what can i do to fix it? Even if we decide to not use the geta plugin we need the category-root for the default categories. Currently they don't exist in the CMS.

We removed the plugin and dev started to work again. But as said, we need the categories, so what's causing it?


Thanks in advance, Tim

Edit: I wanted to give an update... To fix this error i have integrated the source of the geta categories plugin into our solution as a separate project(.NET 6). I could fix the exception by modifying the IContectRepositoryExtensions-class. The method GetOrCreateCategoriesRoot was causing an EPiServerException because the CategoryRoot could not be saved under SysContentFolder, so i changed it. The try-catch is new, the old source just contained the Save-call:

private static ContentReference GetOrCreateCategoriesRoot(this IContentRepository contentRepository, ContentReference parentLink, string name, string routeSegment)
{
	LoaderOptions loaderOptions = new()
	{
		LanguageLoaderOption.FallbackWithMaster()
	};

	CategoryRoot? rootCategory = contentRepository.GetChildren<CategoryRoot>(parentLink, loaderOptions).FirstOrDefault();

	if (rootCategory != null)
	{
		return rootCategory.ContentLink;
	}

	rootCategory = contentRepository.GetDefault<CategoryRoot>(parentLink);
	rootCategory.Name = name;
	rootCategory.RouteSegment = routeSegment;

	try
	{
		IContentTypeRepository? contentTypeRepository = ServiceLocator.Current.GetInstance<IContentTypeRepository>();
		ContentType? sysContentFolderType = contentTypeRepository?.Load("SysContentFolder");
		IAvailableSettingsRepository availabilityRepository = ServiceLocator.Current.GetInstance<IAvailableSettingsRepository>();
		AvailableSetting existingSetting = availabilityRepository.GetSetting(sysContentFolderType) 
			?? new AvailableSetting() { Availability = Availability.Specific };
		const string categoryRootName = nameof(CategoryRoot);
		if (!existingSetting.AllowedContentTypeNames.Contains(categoryRootName))
		{
			existingSetting.AllowedContentTypeNames.Add(categoryRootName);
		}
		availabilityRepository.RegisterSetting(sysContentFolderType, existingSetting);
		return contentRepository.Save(rootCategory, SaveAction.Publish, AccessLevel.NoAccess);
	}
	catch (EPiServerException)
	{
		return ContentReference.EmptyReference;
	}
}
#310634
Edited, Oct 11, 2023 15:39
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.