Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
21 changes: 18 additions & 3 deletions src/Umbraco.Core/Services/Changes/ContentTypeChangeTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,29 @@ public enum ContentTypeChangeTypes : byte
Create = 1,

/// <summary>
/// Content type changes impact only the Content type being saved
/// Content type changes directly impact existing content of this content type.
/// </summary>
/// <remarks>
/// These changes are "destructive" of nature. They include:
/// - Changing the content type alias.
/// - Removing a property type or a composition.
/// - Changing the alias of a property type (this effectively corresponds to removing a property type).
/// - Changing variance, either at property or content type level.
/// </remarks>
RefreshMain = 2,

/// <summary>
/// Content type changes impacts the content type being saved and others used that are composed of it
/// Content type changes that do not directly impact existing content of this content type.
/// </summary>
RefreshOther = 4, // changed, other change
/// <remarks>
/// These changes are "constructive" of nature, and include all changes not included in
/// <see cref="RefreshMain"/> - for example:
/// - Adding a property type or a composition.
/// - Rearranging property types or groups.
/// - Changes to name, description, icon etc.
/// - Changes to other content type settings, i.e. allowed child types and version cleanup.
/// </remarks>
RefreshOther = 4,

/// <summary>
/// Content type was removed
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 one that's actually used.
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