Merge pull request #506 from sitereactor/7.2.0-compositions-fix
Fixes U4-5077 doc types with compositions
This commit is contained in:
25
src/Umbraco.Core/Exceptions/InvalidCompositionException.cs
Normal file
25
src/Umbraco.Core/Exceptions/InvalidCompositionException.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using System;
|
||||
|
||||
namespace Umbraco.Core.Exceptions
|
||||
{
|
||||
public class InvalidCompositionException : Exception
|
||||
{
|
||||
public string ContentTypeAlias { get; set; }
|
||||
|
||||
public string AddedCompositionAlias { get; set; }
|
||||
|
||||
public string PropertyTypeAlias { get; set; }
|
||||
|
||||
public override string Message
|
||||
{
|
||||
get
|
||||
{
|
||||
return string.Format(
|
||||
"InvalidCompositionException - ContentType with alias '{0}' was added as a Compsition to ContentType with alias '{1}', " +
|
||||
"but there was a conflict on the PropertyType alias '{2}'. " +
|
||||
"PropertyTypes must have a unique alias across all Compositions in order to compose a valid ContentType Composition.",
|
||||
AddedCompositionAlias, ContentTypeAlias, PropertyTypeAlias);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Runtime.Serialization;
|
||||
using Umbraco.Core.Exceptions;
|
||||
|
||||
namespace Umbraco.Core.Models
|
||||
{
|
||||
@@ -77,6 +78,22 @@ namespace Umbraco.Core.Models
|
||||
|
||||
if (ContentTypeCompositionExists(contentType.Alias) == false)
|
||||
{
|
||||
//Before we actually go ahead and add the ContentType as a Composition we ensure that we don't
|
||||
//end up with duplicate PropertyType aliases - in which case we throw an exception.
|
||||
var conflictingPropertyTypeAliases = CompositionPropertyTypes.SelectMany(
|
||||
x => contentType.CompositionPropertyTypes
|
||||
.Where(y => y.Alias.Equals(x.Alias, StringComparison.InvariantCultureIgnoreCase))
|
||||
.Select(p => p.Alias)).ToList();
|
||||
|
||||
if (conflictingPropertyTypeAliases.Any())
|
||||
throw new InvalidCompositionException
|
||||
{
|
||||
AddedCompositionAlias = contentType.Alias,
|
||||
ContentTypeAlias = Alias,
|
||||
PropertyTypeAlias =
|
||||
string.Join(", ", conflictingPropertyTypeAliases)
|
||||
};
|
||||
|
||||
_contentTypeComposition.Add(contentType);
|
||||
OnPropertyChanged(ContentTypeCompositionSelector);
|
||||
return true;
|
||||
|
||||
@@ -310,6 +310,7 @@
|
||||
<Compile Include="Events\RollbackEventArgs.cs" />
|
||||
<Compile Include="Events\SaveEventArgs.cs" />
|
||||
<Compile Include="Events\SendToPublishEventArgs.cs" />
|
||||
<Compile Include="Exceptions\InvalidCompositionException.cs" />
|
||||
<Compile Include="HideFromTypeFinderAttribute.cs" />
|
||||
<Compile Include="IApplicationEventHandler.cs" />
|
||||
<Compile Include="IDisposeOnRequestEnd.cs" />
|
||||
|
||||
@@ -669,28 +669,33 @@ namespace umbraco.cms.businesslogic
|
||||
{
|
||||
get
|
||||
{
|
||||
if (MasterContentTypes.Count > 0)
|
||||
return MasterContentTypes[0];
|
||||
if (ContentTypeItem == null)
|
||||
return 0;
|
||||
|
||||
return 0;
|
||||
return ContentTypeItem.ParentId == -1 ? 0 : ContentTypeItem.ParentId;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value != MasterContentType)
|
||||
{
|
||||
//TODO: Add support for multiple masters
|
||||
/*foreach (var mct in MasterContentTypes)
|
||||
{
|
||||
RemoveParentContentType(mct);
|
||||
}*/
|
||||
|
||||
if (MasterContentTypes.Count > 0)
|
||||
if (ContentTypeItem == null)
|
||||
{
|
||||
var masterId = MasterContentTypes[0];
|
||||
RemoveParentContentType(masterId);
|
||||
//Legacy
|
||||
if (MasterContentTypes.Count > 0)
|
||||
{
|
||||
var masterId = MasterContentTypes[0];
|
||||
RemoveParentContentType(masterId);
|
||||
}
|
||||
|
||||
AddParentContentType(value);
|
||||
}
|
||||
else
|
||||
{
|
||||
ContentTypeItem.ParentId = value;
|
||||
var newMaster = ApplicationContext.Current.Services.ContentTypeService.GetContentType(value);
|
||||
var added = ContentTypeItem.AddContentType(newMaster);
|
||||
}
|
||||
|
||||
AddParentContentType(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -703,13 +708,20 @@ namespace umbraco.cms.businesslogic
|
||||
}
|
||||
else
|
||||
{
|
||||
SqlHelper.ExecuteNonQuery(
|
||||
"INSERT INTO [cmsContentType2ContentType] (parentContentTypeId, childContentTypeId) VALUES (@parentContentTypeId, @childContentTypeId)",
|
||||
SqlHelper.CreateParameter("@parentContentTypeId", parentContentTypeId),
|
||||
SqlHelper.CreateParameter("@childContentTypeId", Id));
|
||||
MasterContentTypes.Add(parentContentTypeId);
|
||||
|
||||
if (ContentTypeItem == null)
|
||||
{
|
||||
SqlHelper.ExecuteNonQuery(
|
||||
"INSERT INTO [cmsContentType2ContentType] (parentContentTypeId, childContentTypeId) VALUES (@parentContentTypeId, @childContentTypeId)",
|
||||
SqlHelper.CreateParameter("@parentContentTypeId", parentContentTypeId),
|
||||
SqlHelper.CreateParameter("@childContentTypeId", Id));
|
||||
|
||||
MasterContentTypes.Add(parentContentTypeId);
|
||||
}
|
||||
else
|
||||
{
|
||||
var newMaster = ApplicationContext.Current.Services.ContentTypeService.GetContentType(parentContentTypeId);
|
||||
var added = ContentTypeItem.AddContentType(newMaster);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Persistence.Caching;
|
||||
using System.Linq;
|
||||
using umbraco.BusinessLogic;
|
||||
|
||||
@@ -124,15 +123,6 @@ namespace umbraco.cms.businesslogic.media
|
||||
|
||||
if (!e.Cancel)
|
||||
{
|
||||
if (MasterContentType != 0)
|
||||
MediaTypeItem.ParentId = MasterContentType;
|
||||
|
||||
foreach (var masterContentType in MasterContentTypes)
|
||||
{
|
||||
var contentType = ApplicationContext.Current.Services.ContentTypeService.GetMediaType(masterContentType);
|
||||
MediaTypeItem.AddContentType(contentType);
|
||||
}
|
||||
|
||||
var current = User.GetCurrent();
|
||||
int userId = current == null ? 0 : current.Id;
|
||||
ApplicationContext.Current.Services.ContentTypeService.Save(MediaTypeItem, userId);
|
||||
|
||||
@@ -6,13 +6,11 @@ using System.Linq;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Persistence.Caching;
|
||||
using umbraco.BusinessLogic;
|
||||
using Umbraco.Core.Services;
|
||||
using umbraco.DataLayer;
|
||||
using System.Collections.Generic;
|
||||
using Umbraco.Core;
|
||||
using PropertyType = umbraco.cms.businesslogic.propertytype.PropertyType;
|
||||
|
||||
namespace umbraco.cms.businesslogic.web
|
||||
{
|
||||
@@ -508,15 +506,6 @@ namespace umbraco.cms.businesslogic.web
|
||||
|
||||
if (!e.Cancel)
|
||||
{
|
||||
if (MasterContentType != 0)
|
||||
ContentType.ParentId = MasterContentType;
|
||||
|
||||
/*foreach (var masterContentType in MasterContentTypes)
|
||||
{
|
||||
var contentType = ApplicationContext.Current.Services.ContentTypeService.GetContentType(masterContentType);
|
||||
ContentType.AddContentType(contentType);
|
||||
}*/
|
||||
|
||||
var current = User.GetCurrent();
|
||||
int userId = current == null ? 0 : current.Id;
|
||||
ApplicationContext.Current.Services.ContentTypeService.Save(ContentType, userId);
|
||||
|
||||
Reference in New Issue
Block a user