From d444dfd4416bafdb3db546a8fa041417bcdec49d Mon Sep 17 00:00:00 2001 From: Shannon Date: Wed, 20 May 2020 11:33:10 +1000 Subject: [PATCH] Moves ContentTypeBase, Member, ContentTypeComposition, etc... removes the casting --- .../Models/ContentTypeBase.cs | 0 .../Models/ContentTypeCompositionBase.cs | 20 +++---- .../Models/IContentTypeComposition.cs | 13 +++++ src/Umbraco.Core/Models/IMember.cs | 53 ++++++++++++++++- .../Models/Member.cs | 58 ++++++++++++++++--- .../Implement/ContentTypeRepositoryBase.cs | 8 +-- .../Services/Implement/MemberService.cs | 4 +- 7 files changed, 127 insertions(+), 29 deletions(-) rename src/{Umbraco.Infrastructure => Umbraco.Core}/Models/ContentTypeBase.cs (100%) rename src/{Umbraco.Infrastructure => Umbraco.Core}/Models/ContentTypeCompositionBase.cs (95%) rename src/{Umbraco.Infrastructure => Umbraco.Core}/Models/Member.cs (89%) diff --git a/src/Umbraco.Infrastructure/Models/ContentTypeBase.cs b/src/Umbraco.Core/Models/ContentTypeBase.cs similarity index 100% rename from src/Umbraco.Infrastructure/Models/ContentTypeBase.cs rename to src/Umbraco.Core/Models/ContentTypeBase.cs diff --git a/src/Umbraco.Infrastructure/Models/ContentTypeCompositionBase.cs b/src/Umbraco.Core/Models/ContentTypeCompositionBase.cs similarity index 95% rename from src/Umbraco.Infrastructure/Models/ContentTypeCompositionBase.cs rename to src/Umbraco.Core/Models/ContentTypeCompositionBase.cs index 1467ee9b92..0f37b2ecab 100644 --- a/src/Umbraco.Infrastructure/Models/ContentTypeCompositionBase.cs +++ b/src/Umbraco.Core/Models/ContentTypeCompositionBase.cs @@ -15,7 +15,7 @@ namespace Umbraco.Core.Models public abstract class ContentTypeCompositionBase : ContentTypeBase, IContentTypeComposition { private List _contentTypeComposition = new List(); - internal List RemovedContentTypeKeyTracker = new List(); + private List _removedContentTypeKeyTracker = new List(); protected ContentTypeCompositionBase(IShortStringHelper shortStringHelper, int parentId) : base(shortStringHelper, parentId) { } @@ -30,6 +30,8 @@ namespace Umbraco.Core.Models AddContentType(parent); } + public IEnumerable RemovedContentTypes => _removedContentTypeKeyTracker; + /// /// Gets or sets the content types that compose this content type. /// @@ -101,14 +103,8 @@ namespace Umbraco.Core.Models } } - /// - /// Gets the property types obtained via composition. - /// - /// - /// Gets them raw, ie with their original variation. - /// - [IgnoreDataMember] - internal IEnumerable RawComposedPropertyTypes => GetRawComposedPropertyTypes(); + /// + public IEnumerable GetOriginalComposedPropertyTypes() => GetRawComposedPropertyTypes(); private IEnumerable 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(); + clonedEntity._removedContentTypeKeyTracker = new List(); clonedEntity._contentTypeComposition = ContentTypeComposition.Select(x => (IContentTypeComposition)x.DeepClone()).ToList(); } } diff --git a/src/Umbraco.Core/Models/IContentTypeComposition.cs b/src/Umbraco.Core/Models/IContentTypeComposition.cs index 17b6881487..cf60b121af 100644 --- a/src/Umbraco.Core/Models/IContentTypeComposition.cs +++ b/src/Umbraco.Core/Models/IContentTypeComposition.cs @@ -55,5 +55,18 @@ namespace Umbraco.Core.Models /// /// An enumerable list of integer ids IEnumerable CompositionIds(); + + /// + /// Returns a list of content type ids that have been removed from this instance's composition + /// + IEnumerable RemovedContentTypes { get; } + + /// + /// Gets the property types obtained via composition. + /// + /// + /// Gets them raw, ie with their original variation. + /// + IEnumerable GetOriginalComposedPropertyTypes(); } } diff --git a/src/Umbraco.Core/Models/IMember.cs b/src/Umbraco.Core/Models/IMember.cs index 199d53b174..c46eb512c5 100644 --- a/src/Umbraco.Core/Models/IMember.cs +++ b/src/Umbraco.Core/Models/IMember.cs @@ -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 /// string ContentTypeAlias { get; } + + /// + /// Internal/Experimental - only used for mapping queries. + /// + /// + /// Adding these to have first level properties instead of the Properties collection. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + string LongStringPropertyValue { get; set; } + /// + /// Internal/Experimental - only used for mapping queries. + /// + /// + /// Adding these to have first level properties instead of the Properties collection. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + string ShortStringPropertyValue { get; set; } + /// + /// Internal/Experimental - only used for mapping queries. + /// + /// + /// Adding these to have first level properties instead of the Properties collection. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + int IntegerPropertyValue { get; set; } + /// + /// Internal/Experimental - only used for mapping queries. + /// + /// + /// Adding these to have first level properties instead of the Properties collection. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + bool BoolPropertyValue { get; set; } + /// + /// Internal/Experimental - only used for mapping queries. + /// + /// + /// Adding these to have first level properties instead of the Properties collection. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + DateTime DateTimePropertyValue { get; set; } + /// + /// Internal/Experimental - only used for mapping queries. + /// + /// + /// Adding these to have first level properties instead of the Properties collection. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + string PropertyTypeAlias { get; set; } } } diff --git a/src/Umbraco.Infrastructure/Models/Member.cs b/src/Umbraco.Core/Models/Member.cs similarity index 89% rename from src/Umbraco.Infrastructure/Models/Member.cs rename to src/Umbraco.Core/Models/Member.cs index ed2cce3068..640bd36214 100644 --- a/src/Umbraco.Infrastructure/Models/Member.cs +++ b/src/Umbraco.Core/Models/Member.cs @@ -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. - */ + /// + /// Internal/Experimental - only used for mapping queries. + /// + /// + /// Adding these to have first level properties instead of the Properties collection. + /// [IgnoreDataMember] - internal string LongStringPropertyValue { get; set; } + [EditorBrowsable(EditorBrowsableState.Never)] + public string LongStringPropertyValue { get; set; } + /// + /// Internal/Experimental - only used for mapping queries. + /// + /// + /// Adding these to have first level properties instead of the Properties collection. + /// [IgnoreDataMember] - internal string ShortStringPropertyValue { get; set; } + [EditorBrowsable(EditorBrowsableState.Never)] + public string ShortStringPropertyValue { get; set; } + /// + /// Internal/Experimental - only used for mapping queries. + /// + /// + /// Adding these to have first level properties instead of the Properties collection. + /// [IgnoreDataMember] - internal int IntegerPropertyValue { get; set; } + [EditorBrowsable(EditorBrowsableState.Never)] + public int IntegerPropertyValue { get; set; } + /// + /// Internal/Experimental - only used for mapping queries. + /// + /// + /// Adding these to have first level properties instead of the Properties collection. + /// [IgnoreDataMember] - internal bool BoolPropertyValue { get; set; } + [EditorBrowsable(EditorBrowsableState.Never)] + public bool BoolPropertyValue { get; set; } + /// + /// Internal/Experimental - only used for mapping queries. + /// + /// + /// Adding these to have first level properties instead of the Properties collection. + /// [IgnoreDataMember] - internal DateTime DateTimePropertyValue { get; set; } + [EditorBrowsable(EditorBrowsableState.Never)] + public DateTime DateTimePropertyValue { get; set; } + /// + /// Internal/Experimental - only used for mapping queries. + /// + /// + /// Adding these to have first level properties instead of the Properties collection. + /// [IgnoreDataMember] - internal string PropertyTypeAlias { get; set; } + [EditorBrowsable(EditorBrowsableState.Never)] + public string PropertyTypeAlias { get; set; } private Attempt WarnIfPropertyTypeNotFoundOnGet(string propertyAlias, string propertyName, T defaultVal) { diff --git a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/ContentTypeRepositoryBase.cs b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/ContentTypeRepositoryBase.cs index 16b9d852fd..b2a83e83fd 100644 --- a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/ContentTypeRepositoryBase.cs +++ b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/ContentTypeRepositoryBase.cs @@ -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(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("WHERE contentTypeId = @Id", new { Id = key }); @@ -442,7 +440,7 @@ AND umbracoNode.id <> @id", propertyTypeVariationChanges = propertyTypeVariationChanges ?? new Dictionary(); - foreach (var composedPropertyType in ((ContentTypeCompositionBase)entity).RawComposedPropertyTypes) + foreach (var composedPropertyType in entity.GetOriginalComposedPropertyTypes()) { if (composedPropertyType.Variations == ContentVariation.Nothing) continue; diff --git a/src/Umbraco.Infrastructure/Services/Implement/MemberService.cs b/src/Umbraco.Infrastructure/Services/Implement/MemberService.cs index 7ee6065210..5143cd6203 100644 --- a/src/Umbraco.Infrastructure/Services/Implement/MemberService.cs +++ b/src/Umbraco.Infrastructure/Services/Implement/MemberService.cs @@ -67,10 +67,10 @@ namespace Umbraco.Core.Services.Implement query = Query(); break; case MemberCountType.LockedOut: - query = Query().Where(x => ((Member) x).PropertyTypeAlias == Constants.Conventions.Member.IsLockedOut && ((Member) x).BoolPropertyValue); + query = Query().Where(x => x.PropertyTypeAlias == Constants.Conventions.Member.IsLockedOut && ((Member) x).BoolPropertyValue); break; case MemberCountType.Approved: - query = Query().Where(x => ((Member) x).PropertyTypeAlias == Constants.Conventions.Member.IsApproved && ((Member) x).BoolPropertyValue); + query = Query().Where(x => x.PropertyTypeAlias == Constants.Conventions.Member.IsApproved && ((Member) x).BoolPropertyValue); break; default: throw new ArgumentOutOfRangeException(nameof(countType));