Merge branch '7.4.0' into temp-U4-7634

Conflicts:
	src/Umbraco.Web/Editors/ContentTypeControllerBase.cs
This commit is contained in:
Claus
2016-01-11 13:46:20 +01:00
parent 05c8e10ef8
commit ffa7a1457a
2 changed files with 12 additions and 83 deletions

View File

@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Umbraco.Core.Configuration;
using Umbraco.Core.Models;
namespace Umbraco.Core.Services
@@ -15,8 +16,6 @@ namespace Umbraco.Core.Services
IContentTypeComposition source,
IContentTypeComposition[] allContentTypes)
{
if (source == null) throw new ArgumentNullException("source");
//below is all ported from the old doc type editor and comes with the same weaknesses /insanity / magic
// note: there are many sanity checks missing here and there ;-((
@@ -25,11 +24,14 @@ namespace Umbraco.Core.Services
// throw new Exception("A parent does not belong to a composition.");
// find out if any content type uses this content type
var isUsing = allContentTypes.Where(x => x.ContentTypeComposition.Any(y => y.Id == source.Id)).ToArray();
if (isUsing.Length > 0)
if (source != null)
{
//if already in use a composition, do not allow any composited types
return new List<IContentTypeComposition>();
var isUsing = allContentTypes.Where(x => x.ContentTypeComposition.Any(y => y.Id == source.Id)).ToArray();
if (isUsing.Length > 0)
{
//if already in use a composition, do not allow any composited types
return new List<IContentTypeComposition>();
}
}
// if it is not used then composition is possible
@@ -59,9 +61,9 @@ namespace Umbraco.Core.Services
// .Where(x => x != source.ParentId) // but not the parent
// .Distinct()
// .ToArray();
return list
.Where(x => x.Id != source.Id)
.Where(x => x.Id != (source != null ? source.Id : 0))
.OrderBy(x => x.Name)
.ToList();
}

View File

@@ -92,56 +92,9 @@ namespace Umbraco.Web.Editors
throw new ArgumentOutOfRangeException("The entity type was not a content type");
}
// note: there are many sanity checks missing here and there ;-((
// make sure once and for all
//if (allContentTypes.Any(x => x.ParentId > 0 && x.ContentTypeComposition.Any(y => y.Id == x.ParentId) == false))
// throw new Exception("A parent does not belong to a composition.");
var filtered = Services.ContentTypeService.GetAvailableCompositeContentTypes(source, allContentTypes);
// find out if any content type uses this content type
var isUsing = allContentTypes.Where(x => x.ContentTypeComposition.Any(y => y.Id == contentTypeId)).ToArray();
if (isUsing.Length > 0)
{
//if already in use a composition, do not allow any composited types
return new List<EntityBasic>();
}
// if it is not used then composition is possible
// hashset guarantees unicity on Id
var list = new HashSet<IContentTypeComposition>(new DelegateEqualityComparer<IContentTypeComposition>(
(x, y) => x.Id == y.Id,
x => x.Id));
// usable types are those that are top-level
var usableContentTypes = allContentTypes
.Where(x => x.ContentTypeComposition.Any() == false).ToArray();
foreach (var x in usableContentTypes)
list.Add(x);
// indirect types are those that we use, directly or indirectly
var indirectContentTypes = GetIndirect(source).ToArray();
foreach (var x in indirectContentTypes)
list.Add(x);
if (UmbracoConfig.For.UmbracoSettings().Content.EnableInheritedDocumentTypes)
{
// get the ancestorIds via the parent
var ancestorIds = new int[0];
if (parentId > 0)
{
var parent = allContentTypes.FirstOrDefault(x => x.Id == parentId);
if (parent != null)
ancestorIds = parent.Path.Split(',').Select(int.Parse).ToArray();
}
// add all ancestors as compositions (since they are implicitly "compositions" by inheritance and should
// be in the list even though they can't be deselected)
foreach (var x in allContentTypes)
if (ancestorIds.Contains(x.Id))
list.Add(x);
}
return list
.Where(x => x.Id != contentTypeId)
.OrderBy(x => x.Name)
return filtered
.Select(Mapper.Map<IContentTypeComposition, EntityBasic>)
.Select(x =>
{
@@ -151,32 +104,6 @@ namespace Umbraco.Web.Editors
.ToList();
}
private static IEnumerable<IContentTypeComposition> GetIndirect(IContentTypeComposition ctype)
{
// hashset guarantees unicity on Id
var all = new HashSet<IContentTypeComposition>(new DelegateEqualityComparer<IContentTypeComposition>(
(x, y) => x.Id == y.Id,
x => x.Id));
var stack = new Stack<IContentTypeComposition>();
if (ctype != null)
{
foreach (var x in ctype.ContentTypeComposition)
stack.Push(x);
}
while (stack.Count > 0)
{
var x = stack.Pop();
all.Add(x);
foreach (var y in x.ContentTypeComposition)
stack.Push(y);
}
return all;
}
/// <summary>
/// Validates the composition and adds errors to the model state if any are found then throws an error response if there are errors
/// </summary>