From cf689735d0fbf5cf925f0fe2ab244f7da6a7e334 Mon Sep 17 00:00:00 2001 From: Bjarne Fyrstenborg Date: Sun, 13 Nov 2022 16:09:54 +0100 Subject: [PATCH 1/3] Delete references for custom relation types as well --- .../Repositories/Implement/ContentRepositoryBase.cs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/ContentRepositoryBase.cs b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/ContentRepositoryBase.cs index 0162ba8d5239..733cb7601534 100644 --- a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/ContentRepositoryBase.cs +++ b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/ContentRepositoryBase.cs @@ -1042,8 +1042,13 @@ protected void PersistRelations(TEntity entity) var trackedRelations = new List(); trackedRelations.AddRange(_dataValueReferenceFactories.GetAllReferences(entity.Properties, PropertyEditors)); + var relationTypeAliases = trackedRelations + .Select(x => x.RelationTypeAlias) + .Distinct() + .ToArray(); + // First delete all auto-relations for this entity - RelationRepository.DeleteByParent(entity.Id, Constants.Conventions.RelationTypes.AutomaticRelationTypes); + RelationRepository.DeleteByParent(entity.Id, relationTypeAliases); //Constants.Conventions.RelationTypes.AutomaticRelationTypes); if (trackedRelations.Count == 0) { @@ -1055,7 +1060,10 @@ protected void PersistRelations(TEntity entity) .ToDictionary(x => (Udi)x!, x => x!.Guid); // lookup in the DB all INT ids for the GUIDs and chuck into a dictionary - var keyToIds = Database.Fetch(Sql().Select(x => x.NodeId, x => x.UniqueId).From().WhereIn(x => x.UniqueId, udiToGuids.Values)) + var keyToIds = Database.Fetch(Sql() + .Select(x => x.NodeId, x => x.UniqueId) + .From() + .WhereIn(x => x.UniqueId, udiToGuids.Values)) .ToDictionary(x => x.UniqueId, x => x.NodeId); var allRelationTypes = RelationTypeRepository.GetMany(Array.Empty())? From 2e1b6635bdb12f2c03f95d5ed47cb080a97dce93 Mon Sep 17 00:00:00 2001 From: Bjarne Fyrstenborg Date: Sun, 13 Nov 2022 16:13:21 +0100 Subject: [PATCH 2/3] Remove use of constant --- src/Umbraco.Core/Constants-Conventions.cs | 4 ++-- .../Repositories/Implement/ContentRepositoryBase.cs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Umbraco.Core/Constants-Conventions.cs b/src/Umbraco.Core/Constants-Conventions.cs index 03240db872d0..7047e1643717 100644 --- a/src/Umbraco.Core/Constants-Conventions.cs +++ b/src/Umbraco.Core/Constants-Conventions.cs @@ -276,7 +276,7 @@ public static class RelationTypes public const string RelateParentMediaFolderOnDeleteAlias = "relateParentMediaFolderOnDelete"; /// - /// Returns the types of relations that are automatically tracked + /// 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 @@ -284,7 +284,7 @@ public static class RelationTypes /// 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 + // TODO: return a list of built in types so we can use that to prevent deletion in the UI } public static class Udi diff --git a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/ContentRepositoryBase.cs b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/ContentRepositoryBase.cs index 733cb7601534..ded99bf8bfd1 100644 --- a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/ContentRepositoryBase.cs +++ b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/ContentRepositoryBase.cs @@ -1048,7 +1048,7 @@ protected void PersistRelations(TEntity entity) .ToArray(); // First delete all auto-relations for this entity - RelationRepository.DeleteByParent(entity.Id, relationTypeAliases); //Constants.Conventions.RelationTypes.AutomaticRelationTypes); + RelationRepository.DeleteByParent(entity.Id, relationTypeAliases); if (trackedRelations.Count == 0) { From 664081dbec46fdefee7a538f6ef2bbde32f4ccb2 Mon Sep 17 00:00:00 2001 From: Nikolaj Date: Wed, 23 Nov 2022 14:52:43 +0100 Subject: [PATCH 3/3] Obsolete AutomaticRelationTypes --- src/Umbraco.Core/Constants-Conventions.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Umbraco.Core/Constants-Conventions.cs b/src/Umbraco.Core/Constants-Conventions.cs index 7047e1643717..09942ff49534 100644 --- a/src/Umbraco.Core/Constants-Conventions.cs +++ b/src/Umbraco.Core/Constants-Conventions.cs @@ -282,6 +282,7 @@ public static class RelationTypes /// 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. /// + [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