Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/Umbraco.Core/Models/ContentTypeCompositionBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public abstract class ContentTypeCompositionBase : ContentTypeBase, IContentType
{
private List<IContentTypeComposition> _contentTypeComposition = new();
private List<int> _removedContentTypeKeyTracker = new();
private bool _hasCompositionBeenRemoved;

/// <summary>
/// Initializes a new instance of the <see cref="ContentTypeCompositionBase" /> class with the specified parent ID.
Expand Down Expand Up @@ -123,6 +124,23 @@ IPropertyType AcquireProperty(IPropertyType propertyType)
}
}

/// <summary>
/// A boolean flag indicating if a composition has been removed from this instance.
/// </summary>
/// <remarks>
/// This is currently (specifically) used in order to know that we need to refresh the content cache which
/// needs to occur when a composition has been removed from a content type
/// </remarks>
[IgnoreDataMember]
internal bool HasCompositionTypeBeenRemoved
{
get => _hasCompositionBeenRemoved;
private set
{
_hasCompositionBeenRemoved = value;
OnPropertyChanged(nameof(HasCompositionTypeBeenRemoved));
}
}

/// <inheritdoc />
public IEnumerable<IPropertyType> GetOriginalComposedPropertyTypes() => GetRawComposedPropertyTypes();
Expand Down Expand Up @@ -212,6 +230,7 @@ public bool RemoveContentType(string alias)
_removedContentTypeKeyTracker.AddRange(compositionIdsToRemove);
}

HasCompositionTypeBeenRemoved = true;
OnPropertyChanged(nameof(ContentTypeComposition));

return _contentTypeComposition.Remove(contentTypeComposition);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,18 @@
// This ensures we correctly handle property types that may have been filtered out from groups.
var existingPropertyTypes = contentType.PropertyTypes.ToList();

// To ensure correct change tracking, we must explicitly inform the content type of any
// existing properties that have been removed.
var removedPropertyTypeAliases = existingPropertyTypes
.Select(pt => pt.Alias)
.Except(model.Properties.Select(p => p.Alias))
.ToArray();

foreach (var removedPropertyTypeAlias in removedPropertyTypeAliases)
{
contentType.RemovePropertyType(removedPropertyTypeAlias);
}

Check warning on line 702 in src/Umbraco.Core/Services/ContentTypeEditing/ContentTypeEditingServiceBase.cs

View check run for this annotation

CodeScene Delta Analysis / CodeScene Code Health Review (main)

❌ Getting worse: Complex Method

UpdatePropertiesAsync increases in cyclomatic complexity from 9 to 10, threshold = 9. This function has many conditional statements (e.g. if, for, while), leading to lower code health. Avoid adding more conditionals and code to it without refactoring.
// handle properties in groups
PropertyGroup[] propertyGroups = model.Containers.Select(container =>
{
Expand Down Expand Up @@ -781,11 +793,14 @@
}

// get the current property type (if it exists)
IPropertyType propertyType = existingPropertyTypes.FirstOrDefault(pt => pt.Key == property.Key)
?? new PropertyType(_shortStringHelper, dataType);
IPropertyType propertyType = existingPropertyTypes.FirstOrDefault(pt => pt.Alias == property.Alias)
?? new PropertyType(_shortStringHelper, dataType)
{
// We are demanding a property type key in the model, so we should probably
// ensure that it's the on that's actually used.
Comment thread
kjac marked this conversation as resolved.
Outdated
Key = property.Key
};

// We are demanding a property type key in the model, so we should probably ensure that it's the on that's actually used.
propertyType.Key = property.Key;
propertyType.Name = property.Name;
propertyType.DataTypeId = dataType.Id;
propertyType.DataTypeKey = dataType.Key;
Expand Down
Loading
Loading