From 25c2eed8883813101da1b2371a7d899eae808b9c Mon Sep 17 00:00:00 2001 From: Shannon Date: Fri, 25 Oct 2019 14:33:40 +1100 Subject: [PATCH] Ensures the right type is tracked for links ensures relations are removed. --- src/Umbraco.Core/Constants-Conventions.cs | 9 +++++++++ .../Repositories/Implement/ContentRepositoryBase.cs | 7 +++---- .../PropertyEditors/RichTextPropertyEditor.cs | 2 +- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/Umbraco.Core/Constants-Conventions.cs b/src/Umbraco.Core/Constants-Conventions.cs index e01f0eb0f5..e2e0f30874 100644 --- a/src/Umbraco.Core/Constants-Conventions.cs +++ b/src/Umbraco.Core/Constants-Conventions.cs @@ -358,6 +358,15 @@ namespace Umbraco.Core /// public const string RelateParentMediaFolderOnDeleteAlias = "relateParentMediaFolderOnDelete"; + /// + /// Returns the types of relations that are automatically tracked + /// + /// + /// Developers should not manually use these relation types since they will all be cleared whenever an entity + /// (content, media or member) is saved since they are auto-populated based on property values. + /// + public static string[] AutomaticRelationTypes = new[] { RelatedMediaAlias, RelatedDocumentAlias }; + //TODO: return a list of built in types so we can use that to prevent deletion in the uI } } diff --git a/src/Umbraco.Core/Persistence/Repositories/Implement/ContentRepositoryBase.cs b/src/Umbraco.Core/Persistence/Repositories/Implement/ContentRepositoryBase.cs index 8010d60267..aaa3946494 100644 --- a/src/Umbraco.Core/Persistence/Repositories/Implement/ContentRepositoryBase.cs +++ b/src/Umbraco.Core/Persistence/Repositories/Implement/ContentRepositoryBase.cs @@ -837,11 +837,10 @@ namespace Umbraco.Core.Persistence.Repositories.Implement trackedRelations.AddRange(refs); } - if (trackedRelations.Count == 0) return; + //First delete all auto-relations for this entity + RelationRepository.DeleteByParent(entity.Id, Constants.Conventions.RelationTypes.AutomaticRelationTypes); - //First delete all relations for this entity - var relationTypes = trackedRelations.Select(x => x.RelationTypeAlias).ToArray(); - RelationRepository.DeleteByParent(entity.Id, relationTypes); + if (trackedRelations.Count == 0) return; var udiToGuids = trackedRelations.Select(x => x.Udi as GuidUdi) .ToDictionary(x => (Udi)x, x => x.Guid); diff --git a/src/Umbraco.Web/PropertyEditors/RichTextPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/RichTextPropertyEditor.cs index ed3f484a4e..77617f7779 100644 --- a/src/Umbraco.Web/PropertyEditors/RichTextPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/RichTextPropertyEditor.cs @@ -144,7 +144,7 @@ namespace Umbraco.Web.PropertyEditors yield return new UmbracoEntityReference(udi, Constants.Conventions.RelationTypes.RelatedMediaAlias); foreach (var udi in _localLinkParser.FindUdisFromLocalLinks(asString)) - yield return new UmbracoEntityReference(udi, Constants.Conventions.RelationTypes.RelatedMediaAlias); + yield return new UmbracoEntityReference(udi, Constants.Conventions.RelationTypes.RelatedDocumentAlias); //TODO: Detect Macros too ... but we can save that for a later date, right now need to do media refs }