From 3189ce75ae8a990912729aaa8296670a2bddff77 Mon Sep 17 00:00:00 2001 From: Shannon Date: Mon, 24 Sep 2018 13:50:42 +1000 Subject: [PATCH] throw exception if duplicate content app aliases are found --- .../ContentAppDefinitionCollection.cs | 29 +++++++++++++++++-- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/src/Umbraco.Web/ContentApps/ContentAppDefinitionCollection.cs b/src/Umbraco.Web/ContentApps/ContentAppDefinitionCollection.cs index 8ab13d5604..4fee9aad24 100644 --- a/src/Umbraco.Web/ContentApps/ContentAppDefinitionCollection.cs +++ b/src/Umbraco.Web/ContentApps/ContentAppDefinitionCollection.cs @@ -1,20 +1,43 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Linq; using Umbraco.Core; using Umbraco.Core.Composing; using Umbraco.Core.Models.ContentEditing; +using Umbraco.Core.Logging; namespace Umbraco.Web.ContentApps { public class ContentAppDefinitionCollection : BuilderCollectionBase { + //private readonly ILogger _logger; + public ContentAppDefinitionCollection(IEnumerable items) : base(items) - { } + { + //_logger = logger; + } public IEnumerable GetContentAppsFor(object o) { - return this.Select(x => x.GetContentAppFor(o)).WhereNotNull().OrderBy(x => x.Weight); + var apps = this.Select(x => x.GetContentAppFor(o)).WhereNotNull().OrderBy(x => x.Weight); + //apps must have unique aliases, we will remove any duplicates and log problems + var resultApps = new Dictionary(); + List dups = null; + foreach(var a in apps) + { + if (resultApps.TryGetValue(a.Alias, out var count)) + (dups ?? (dups = new List())).Add(a.Alias); + else + resultApps[a.Alias] = a; + } + if (dups != null) + { + throw new InvalidOperationException($"Duplicate content app aliases found: {string.Join(",", dups)}"); + //_logger.Warn($"Duplicate content app aliases found: {string.Join(",", dups)}"); + } + + return resultApps.Values; } } }