Ensures the right type is tracked for links ensures relations are removed.

This commit is contained in:
Shannon
2019-10-25 14:33:40 +11:00
parent 15865d566b
commit 25c2eed888
3 changed files with 13 additions and 5 deletions

View File

@@ -358,6 +358,15 @@ namespace Umbraco.Core
/// </summary>
public const string RelateParentMediaFolderOnDeleteAlias = "relateParentMediaFolderOnDelete";
/// <summary>
/// Returns the types of relations that are automatically tracked
/// </summary>
/// <remarks>
/// 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.
/// </remarks>
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
}
}

View File

@@ -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);

View File

@@ -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
}