Merge pull request #506 from sitereactor/7.2.0-compositions-fix

Fixes U4-5077 doc types with compositions
This commit is contained in:
Sebastiaan Janssen
2014-10-07 14:11:09 +02:00
6 changed files with 74 additions and 40 deletions

View 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);
}
}
}
}

View File

@@ -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;

View File

@@ -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" />