Moves ContentTypeBase, Member, ContentTypeComposition, etc... removes the casting

This commit is contained in:
Shannon
2020-05-20 11:33:10 +10:00
parent 9e8bfd039e
commit d444dfd441
7 changed files with 127 additions and 29 deletions

View File

@@ -15,7 +15,7 @@ namespace Umbraco.Core.Models
public abstract class ContentTypeCompositionBase : ContentTypeBase, IContentTypeComposition
{
private List<IContentTypeComposition> _contentTypeComposition = new List<IContentTypeComposition>();
internal List<int> RemovedContentTypeKeyTracker = new List<int>();
private List<int> _removedContentTypeKeyTracker = new List<int>();
protected ContentTypeCompositionBase(IShortStringHelper shortStringHelper, int parentId) : base(shortStringHelper, parentId)
{ }
@@ -30,6 +30,8 @@ namespace Umbraco.Core.Models
AddContentType(parent);
}
public IEnumerable<int> RemovedContentTypes => _removedContentTypeKeyTracker;
/// <summary>
/// Gets or sets the content types that compose this content type.
/// </summary>
@@ -101,14 +103,8 @@ namespace Umbraco.Core.Models
}
}
/// <summary>
/// Gets the property types obtained via composition.
/// </summary>
/// <remarks>
/// <para>Gets them raw, ie with their original variation.</para>
/// </remarks>
[IgnoreDataMember]
internal IEnumerable<IPropertyType> RawComposedPropertyTypes => GetRawComposedPropertyTypes();
/// <inheritdoc />
public IEnumerable<IPropertyType> GetOriginalComposedPropertyTypes() => GetRawComposedPropertyTypes();
private IEnumerable<IPropertyType> GetRawComposedPropertyTypes(bool start = true)
{
@@ -167,12 +163,12 @@ namespace Umbraco.Core.Models
if (contentTypeComposition == null)//You can't remove a composition from another composition
return false;
RemovedContentTypeKeyTracker.Add(contentTypeComposition.Id);
_removedContentTypeKeyTracker.Add(contentTypeComposition.Id);
//If the ContentType we are removing has Compositions of its own these needs to be removed as well
var compositionIdsToRemove = contentTypeComposition.CompositionIds().ToList();
if (compositionIdsToRemove.Any())
RemovedContentTypeKeyTracker.AddRange(compositionIdsToRemove);
_removedContentTypeKeyTracker.AddRange(compositionIdsToRemove);
OnPropertyChanged(nameof(ContentTypeComposition));
return _contentTypeComposition.Remove(contentTypeComposition);
@@ -305,7 +301,7 @@ namespace Umbraco.Core.Models
var clonedEntity = (ContentTypeCompositionBase)clone;
//need to manually assign since this is an internal field and will not be automatically mapped
clonedEntity.RemovedContentTypeKeyTracker = new List<int>();
clonedEntity._removedContentTypeKeyTracker = new List<int>();
clonedEntity._contentTypeComposition = ContentTypeComposition.Select(x => (IContentTypeComposition)x.DeepClone()).ToList();
}
}

View File

@@ -55,5 +55,18 @@ namespace Umbraco.Core.Models
/// </summary>
/// <returns>An enumerable list of integer ids</returns>
IEnumerable<int> CompositionIds();
/// <summary>
/// Returns a list of content type ids that have been removed from this instance's composition
/// </summary>
IEnumerable<int> RemovedContentTypes { get; }
/// <summary>
/// Gets the property types obtained via composition.
/// </summary>
/// <remarks>
/// <para>Gets them raw, ie with their original variation.</para>
/// </remarks>
IEnumerable<IPropertyType> GetOriginalComposedPropertyTypes();
}
}

View File

@@ -1,4 +1,6 @@
using Umbraco.Core.Models.Entities;
using System;
using System.ComponentModel;
using Umbraco.Core.Models.Entities;
using Umbraco.Core.Models.Membership;
namespace Umbraco.Core.Models
@@ -9,5 +11,54 @@ namespace Umbraco.Core.Models
/// String alias of the default ContentType
/// </summary>
string ContentTypeAlias { get; }
/// <summary>
/// Internal/Experimental - only used for mapping queries.
/// </summary>
/// <remarks>
/// Adding these to have first level properties instead of the Properties collection.
/// </remarks>
[EditorBrowsable(EditorBrowsableState.Never)]
string LongStringPropertyValue { get; set; }
/// <summary>
/// Internal/Experimental - only used for mapping queries.
/// </summary>
/// <remarks>
/// Adding these to have first level properties instead of the Properties collection.
/// </remarks>
[EditorBrowsable(EditorBrowsableState.Never)]
string ShortStringPropertyValue { get; set; }
/// <summary>
/// Internal/Experimental - only used for mapping queries.
/// </summary>
/// <remarks>
/// Adding these to have first level properties instead of the Properties collection.
/// </remarks>
[EditorBrowsable(EditorBrowsableState.Never)]
int IntegerPropertyValue { get; set; }
/// <summary>
/// Internal/Experimental - only used for mapping queries.
/// </summary>
/// <remarks>
/// Adding these to have first level properties instead of the Properties collection.
/// </remarks>
[EditorBrowsable(EditorBrowsableState.Never)]
bool BoolPropertyValue { get; set; }
/// <summary>
/// Internal/Experimental - only used for mapping queries.
/// </summary>
/// <remarks>
/// Adding these to have first level properties instead of the Properties collection.
/// </remarks>
[EditorBrowsable(EditorBrowsableState.Never)]
DateTime DateTimePropertyValue { get; set; }
/// <summary>
/// Internal/Experimental - only used for mapping queries.
/// </summary>
/// <remarks>
/// Adding these to have first level properties instead of the Properties collection.
/// </remarks>
[EditorBrowsable(EditorBrowsableState.Never)]
string PropertyTypeAlias { get; set; }
}
}

View File

@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Runtime.Serialization;
using Umbraco.Composing;
using Umbraco.Core.Logging;
@@ -404,21 +405,60 @@ namespace Umbraco.Core.Models
[DataMember]
public virtual string ContentTypeAlias => ContentType.Alias;
/* Internal experiment - only used for mapping queries.
* Adding these to have first level properties instead of the Properties collection.
*/
/// <summary>
/// Internal/Experimental - only used for mapping queries.
/// </summary>
/// <remarks>
/// Adding these to have first level properties instead of the Properties collection.
/// </remarks>
[IgnoreDataMember]
internal string LongStringPropertyValue { get; set; }
[EditorBrowsable(EditorBrowsableState.Never)]
public string LongStringPropertyValue { get; set; }
/// <summary>
/// Internal/Experimental - only used for mapping queries.
/// </summary>
/// <remarks>
/// Adding these to have first level properties instead of the Properties collection.
/// </remarks>
[IgnoreDataMember]
internal string ShortStringPropertyValue { get; set; }
[EditorBrowsable(EditorBrowsableState.Never)]
public string ShortStringPropertyValue { get; set; }
/// <summary>
/// Internal/Experimental - only used for mapping queries.
/// </summary>
/// <remarks>
/// Adding these to have first level properties instead of the Properties collection.
/// </remarks>
[IgnoreDataMember]
internal int IntegerPropertyValue { get; set; }
[EditorBrowsable(EditorBrowsableState.Never)]
public int IntegerPropertyValue { get; set; }
/// <summary>
/// Internal/Experimental - only used for mapping queries.
/// </summary>
/// <remarks>
/// Adding these to have first level properties instead of the Properties collection.
/// </remarks>
[IgnoreDataMember]
internal bool BoolPropertyValue { get; set; }
[EditorBrowsable(EditorBrowsableState.Never)]
public bool BoolPropertyValue { get; set; }
/// <summary>
/// Internal/Experimental - only used for mapping queries.
/// </summary>
/// <remarks>
/// Adding these to have first level properties instead of the Properties collection.
/// </remarks>
[IgnoreDataMember]
internal DateTime DateTimePropertyValue { get; set; }
[EditorBrowsable(EditorBrowsableState.Never)]
public DateTime DateTimePropertyValue { get; set; }
/// <summary>
/// Internal/Experimental - only used for mapping queries.
/// </summary>
/// <remarks>
/// Adding these to have first level properties instead of the Properties collection.
/// </remarks>
[IgnoreDataMember]
internal string PropertyTypeAlias { get; set; }
[EditorBrowsable(EditorBrowsableState.Never)]
public string PropertyTypeAlias { get; set; }
private Attempt<T> WarnIfPropertyTypeNotFoundOnGet<T>(string propertyAlias, string propertyName, T defaultVal)
{

View File

@@ -259,9 +259,7 @@ AND umbracoNode.id <> @id",
// 1. Find content based on the current ContentType: entity.Id
// 2. Find all PropertyTypes on the ContentType that was removed - tracked id (key)
// 3. Remove properties based on property types from the removed content type where the content ids correspond to those found in step one
if (entity is ContentTypeCompositionBase compositionBase &&
compositionBase.RemovedContentTypeKeyTracker != null &&
compositionBase.RemovedContentTypeKeyTracker.Any())
if (entity.RemovedContentTypes.Any())
{
// TODO: Could we do the below with bulk SQL statements instead of looking everything up and then manipulating?
@@ -275,7 +273,7 @@ AND umbracoNode.id <> @id",
var contentDtos = Database.Fetch<ContentDto>(sql);
// loop through all tracked keys, which corresponds to the ContentTypes that has been removed from the composition
foreach (var key in compositionBase.RemovedContentTypeKeyTracker)
foreach (var key in entity.RemovedContentTypes)
{
// find PropertyTypes for the removed ContentType
var propertyTypes = Database.Fetch<PropertyTypeDto>("WHERE contentTypeId = @Id", new { Id = key });
@@ -442,7 +440,7 @@ AND umbracoNode.id <> @id",
propertyTypeVariationChanges = propertyTypeVariationChanges ?? new Dictionary<int, (ContentVariation, ContentVariation)>();
foreach (var composedPropertyType in ((ContentTypeCompositionBase)entity).RawComposedPropertyTypes)
foreach (var composedPropertyType in entity.GetOriginalComposedPropertyTypes())
{
if (composedPropertyType.Variations == ContentVariation.Nothing) continue;

View File

@@ -67,10 +67,10 @@ namespace Umbraco.Core.Services.Implement
query = Query<IMember>();
break;
case MemberCountType.LockedOut:
query = Query<IMember>().Where(x => ((Member) x).PropertyTypeAlias == Constants.Conventions.Member.IsLockedOut && ((Member) x).BoolPropertyValue);
query = Query<IMember>().Where(x => x.PropertyTypeAlias == Constants.Conventions.Member.IsLockedOut && ((Member) x).BoolPropertyValue);
break;
case MemberCountType.Approved:
query = Query<IMember>().Where(x => ((Member) x).PropertyTypeAlias == Constants.Conventions.Member.IsApproved && ((Member) x).BoolPropertyValue);
query = Query<IMember>().Where(x => x.PropertyTypeAlias == Constants.Conventions.Member.IsApproved && ((Member) x).BoolPropertyValue);
break;
default:
throw new ArgumentOutOfRangeException(nameof(countType));