private void UrlSlug_Insert_After(object sender, ObjectEventArgs e) { UrlSlugInfo UrlSlug = (UrlSlugInfo)e.Object; // Staging task should not be created, add entry so this task won't be generated UrlSlugStagingTaskIgnoreInfoProvider.SetUrlSlugStagingTaskIgnoreInfo(new UrlSlugStagingTaskIgnoreInfo() { UrlSlugStagingTaskIgnoreUrlSlugID = UrlSlug.UrlSlugID }); }
private void UrlSlug_Update_Before_IsCustomRebuild(object sender, ObjectEventArgs e) { UrlSlugInfo UrlSlug = (UrlSlugInfo)e.Object; TreeNode Node = new DocumentQuery() .WhereEquals("NodeID", UrlSlug.UrlSlugNodeID) .Columns("NodeSiteID, NodeAliasPath, NodeGuid, NodeAlias") .FirstOrDefault(); // First check if there is already a custom URL slug, if so cancel if (UrlSlug.UrlSlugIsCustom) { var ExistingMatchingSlug = UrlSlugInfoProvider.GetUrlSlugs() .WhereNotEquals("UrlSlugNodeID", UrlSlug.UrlSlugNodeID) .WhereEquals("UrlSlug", UrlSlug.UrlSlug) .Where($"UrlSlugNodeID in (Select NodeID from CMS_Tree where NodeSiteID = {Node.NodeSiteID})") .Columns("UrlSlugNodeID") .FirstOrDefault(); if (ExistingMatchingSlug != null) { TreeNode ConflictNode = new DocumentQuery() .WhereEquals("NodeID", ExistingMatchingSlug.UrlSlugNodeID) .Columns("NodeSiteID, NodeAliasPath") .FirstOrDefault(); var Error = new NotSupportedException($"This custom URL Slug '{UrlSlug.UrlSlug}' on {Node.NodeAliasPath} is already the pattern of an existing document ({ConflictNode.NodeAliasPath}). Operation aborted."); EventLogProvider.LogException("DynamicRouting", "CustomUrlSlugConflict", Error, Node.NodeSiteID); throw Error; } } // This prevents the recursive url slug updates from the first update from removing the "Ignore" on this item. RecursionControl AlreadyDeterminedIfShouldIgnore = new RecursionControl("AlreadyDeterminedIfShouldIgnore_" + UrlSlug.UrlSlugGuid); if (CMSActionContext.CurrentLogSynchronization && AlreadyDeterminedIfShouldIgnore.Continue) { // Delete existing ignore records DynamicRouteInternalHelper.RemoveIgnoreStagingTaskOfUrlSlug(UrlSlug.UrlSlugID); // If the staging task Should be created if ( (UrlSlug.UrlSlugIsCustom && !ValidationHelper.GetBoolean(UrlSlug.GetOriginalValue("UrlSlugIsCustom"), true)) || (!UrlSlug.UrlSlugIsCustom && ValidationHelper.GetBoolean(UrlSlug.GetOriginalValue("UrlSlugIsCustom"), false)) || (UrlSlug.UrlSlugIsCustom && ValidationHelper.GetBoolean(UrlSlug.GetOriginalValue("UrlSlugIsCustom"), false) && UrlSlug.UrlSlug != ValidationHelper.GetString(UrlSlug.GetOriginalValue("UrlSlug"), UrlSlug.UrlSlug)) ) { // Staging task should be created, so proceed as normal } else { // Staging task should not be created, add entry so this task won't be generated UrlSlugStagingTaskIgnoreInfoProvider.SetUrlSlugStagingTaskIgnoreInfo(new UrlSlugStagingTaskIgnoreInfo() { UrlSlugStagingTaskIgnoreUrlSlugID = UrlSlug.UrlSlugID }); } } // If the Url Slug is custom or was custom, then need to rebuild after. if (UrlSlug.UrlSlugIsCustom || ValidationHelper.GetBoolean(UrlSlug.GetOriginalValue("UrlSlugIsCustom"), UrlSlug.UrlSlugIsCustom)) { // Add hook so the Url Slug will be re-rendered after it's updated RecursionControl Trigger = new RecursionControl("UrlSlugNoLongerCustom_" + UrlSlug.UrlSlugGuid); var Triggered = Trigger.Continue; } }