From f4706fcfb75121b5307bbec4ed45b9f6447b99f8 Mon Sep 17 00:00:00 2001 From: Morten Christensen Date: Sun, 30 Dec 2012 18:26:08 -0100 Subject: [PATCH] Fixes U4-1370 for ContentTypes thats loading using new api meaning that the fix only applies to Content and Media, but currently not Members. For Members there is still an issue with MasterContentTypes, as the full structure is not loaded. Need to make the sql lookup recursive- --- .../Models/ContentTypeCompositionBase.cs | 14 +++++++++++++- .../Models/IContentTypeComposition.cs | 8 +++++++- .../umbraco/controls/ContentControl.cs | 3 ++- src/umbraco.cms/businesslogic/ContentType.cs | 19 +++++++++++++++---- 4 files changed, 37 insertions(+), 7 deletions(-) diff --git a/src/Umbraco.Core/Models/ContentTypeCompositionBase.cs b/src/Umbraco.Core/Models/ContentTypeCompositionBase.cs index 9681e2164e..93a77d5cac 100644 --- a/src/Umbraco.Core/Models/ContentTypeCompositionBase.cs +++ b/src/Umbraco.Core/Models/ContentTypeCompositionBase.cs @@ -116,7 +116,7 @@ namespace Umbraco.Core.Models /// /// Gets a list of ContentType aliases from the current composition /// - /// + /// An enumerable list of string aliases /// Does not contain the alias of the Current ContentType public IEnumerable CompositionAliases() { @@ -124,5 +124,17 @@ namespace Umbraco.Core.Models .Select(x => x.Alias) .Union(ContentTypeComposition.SelectMany(x => x.CompositionAliases())); } + + /// + /// Gets a list of ContentType Ids from the current composition + /// + /// An enumerable list of integer ids + /// Does not contain the Id of the Current ContentType + public IEnumerable CompositionIds() + { + return ContentTypeComposition + .Select(x => x.Id) + .Union(ContentTypeComposition.SelectMany(x => x.CompositionIds())); + } } } \ No newline at end of file diff --git a/src/Umbraco.Core/Models/IContentTypeComposition.cs b/src/Umbraco.Core/Models/IContentTypeComposition.cs index 6da7f2e9c9..8b5049f236 100644 --- a/src/Umbraco.Core/Models/IContentTypeComposition.cs +++ b/src/Umbraco.Core/Models/IContentTypeComposition.cs @@ -46,7 +46,13 @@ namespace Umbraco.Core.Models /// /// Gets a list of ContentType aliases from the current composition /// - /// + /// An enumerable list of string aliases IEnumerable CompositionAliases(); + + /// + /// Gets a list of ContentType Ids from the current composition + /// + /// An enumerable list of integer ids + IEnumerable CompositionIds(); } } \ No newline at end of file diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/controls/ContentControl.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/controls/ContentControl.cs index bd24324bcf..a8a549383d 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/controls/ContentControl.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/controls/ContentControl.cs @@ -130,7 +130,8 @@ namespace umbraco.controls // Iterate through the property types and add them to the tab // zb-00036 #29889 : fix property types getter to get the right set of properties // ge : had a bit of a corrupt db and got weird NRE errors so rewrote this to catch the error and rethrow with detail - foreach (PropertyType propertyType in tab.GetPropertyTypes(_content.ContentType.Id)) + var propertyTypes = tab.GetPropertyTypes(_content.ContentType.Id); + foreach (PropertyType propertyType in propertyTypes) { var property = _content.getProperty(propertyType); if (property != null && tabPage != null) diff --git a/src/umbraco.cms/businesslogic/ContentType.cs b/src/umbraco.cms/businesslogic/ContentType.cs index 55f224c783..3db18b7762 100644 --- a/src/umbraco.cms/businesslogic/ContentType.cs +++ b/src/umbraco.cms/businesslogic/ContentType.cs @@ -582,14 +582,25 @@ namespace umbraco.cms.businesslogic if (m_masterContentTypes == null) { m_masterContentTypes = new List(); - using (var dr = SqlHelper.ExecuteReader(@"SELECT parentContentTypeId FROM cmsContentType2ContentType WHERE childContentTypeId = @id", SqlHelper.CreateParameter("@id", Id))) + if (_contentType == null) { - while (dr.Read()) + //TODO Make this recursive, so it looks up Masters of the Master ContentType + using ( + var dr = + SqlHelper.ExecuteReader( + @"SELECT parentContentTypeId FROM cmsContentType2ContentType WHERE childContentTypeId = @id", + SqlHelper.CreateParameter("@id", Id))) { - m_masterContentTypes.Add(dr.GetInt("parentContentTypeId")); + while (dr.Read()) + { + m_masterContentTypes.Add(dr.GetInt("parentContentTypeId")); + } } } - + else + { + m_masterContentTypes = _contentType.CompositionIds().ToList(); + } } return m_masterContentTypes;