Ensure that all automatic relation types are updated (#13470)
This commit is contained in:
@@ -282,7 +282,6 @@ public static partial class Constants
|
||||
/// 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>
|
||||
[Obsolete("This is no longer used, and will be removed in v12")]
|
||||
public static string[] AutomaticRelationTypes { get; } = { RelatedMediaAlias, RelatedDocumentAlias };
|
||||
|
||||
// TODO: return a list of built in types so we can use that to prevent deletion in the UI
|
||||
|
||||
@@ -14,4 +14,10 @@ public interface IDataValueReference
|
||||
/// <param name="value"></param>
|
||||
/// <returns></returns>
|
||||
IEnumerable<UmbracoEntityReference> GetReferences(object? value);
|
||||
|
||||
/// <summary>
|
||||
/// Returns all reference types that are automatically tracked.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
IEnumerable<string> GetAutomaticRelationTypesAliases() => Enumerable.Empty<string>();
|
||||
}
|
||||
|
||||
@@ -1042,10 +1042,7 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement
|
||||
var trackedRelations = new List<UmbracoEntityReference>();
|
||||
trackedRelations.AddRange(_dataValueReferenceFactories.GetAllReferences(entity.Properties, PropertyEditors));
|
||||
|
||||
var relationTypeAliases = trackedRelations
|
||||
.Select(x => x.RelationTypeAlias)
|
||||
.Distinct()
|
||||
.ToArray();
|
||||
var relationTypeAliases = GetAutomaticRelationTypesAliases(entity.Properties, PropertyEditors).ToArray();
|
||||
|
||||
// First delete all auto-relations for this entity
|
||||
RelationRepository.DeleteByParent(entity.Id, relationTypeAliases);
|
||||
@@ -1093,6 +1090,31 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement
|
||||
RelationRepository.SaveBulk(toSave);
|
||||
}
|
||||
|
||||
private IEnumerable<string> GetAutomaticRelationTypesAliases(
|
||||
IPropertyCollection properties,
|
||||
PropertyEditorCollection propertyEditors)
|
||||
{
|
||||
var automaticRelationTypesAliases = new HashSet<string>(Constants.Conventions.RelationTypes.AutomaticRelationTypes);
|
||||
|
||||
foreach (IProperty property in properties)
|
||||
{
|
||||
if (propertyEditors.TryGet(property.PropertyType.PropertyEditorAlias, out IDataEditor? editor) is false )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (editor.GetValueEditor() is IDataValueReference reference)
|
||||
{
|
||||
foreach (var alias in reference.GetAutomaticRelationTypesAliases())
|
||||
{
|
||||
automaticRelationTypesAliases.Add(alias);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return automaticRelationTypesAliases;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Inserts property values for the content entity
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user