From 2f00fa079129fa5ef72391fdaf93bdbeeee905db Mon Sep 17 00:00:00 2001 From: Shannon Deminick Date: Mon, 28 Jan 2013 19:36:06 +0600 Subject: [PATCH] Fixes: #U4-1547 - duplicate trees on upgrade in rare cases. --- src/Umbraco.Web.UI/config/trees.config | 1 + src/umbraco.businesslogic/ApplicationTree.cs | 19 +++++++++++++++++-- .../ApplicationTreeRegistrar.cs | 6 ++++-- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/Umbraco.Web.UI/config/trees.config b/src/Umbraco.Web.UI/config/trees.config index 6834440077..34558bbdaf 100644 --- a/src/Umbraco.Web.UI/config/trees.config +++ b/src/Umbraco.Web.UI/config/trees.config @@ -20,6 +20,7 @@ + diff --git a/src/umbraco.businesslogic/ApplicationTree.cs b/src/umbraco.businesslogic/ApplicationTree.cs index fdebf70488..da9e5f3d69 100644 --- a/src/umbraco.businesslogic/ApplicationTree.cs +++ b/src/umbraco.businesslogic/ApplicationTree.cs @@ -4,6 +4,7 @@ using System.IO; using System.Linq; using System.Web; using System.Xml.Linq; +using Umbraco.Core; using umbraco.DataLayer; using umbraco.IO; @@ -395,7 +396,18 @@ namespace umbraco.BusinessLogic return sortOrderAttr != null ? Convert.ToInt32(sortOrderAttr.Value) : 0; })) { - list.Add(new ApplicationTree( + + var applicationAlias = (string)addElement.Attribute("application"); + var type = (string)addElement.Attribute("type"); + var assembly = (string)addElement.Attribute("assembly"); + + //check if the tree definition (applicationAlias + type + assembly) is already in the list + + if (!list.Any(tree => tree.ApplicationAlias.InvariantEquals(applicationAlias) + && tree.Type.InvariantEquals(type) + && tree.AssemblyName.InvariantEquals(assembly))) + { + list.Add(new ApplicationTree( addElement.Attribute("silent") != null ? Convert.ToBoolean(addElement.Attribute("silent").Value) : false, addElement.Attribute("initialize") != null ? Convert.ToBoolean(addElement.Attribute("initialize").Value) : true, addElement.Attribute("sortOrder") != null ? Convert.ToByte(addElement.Attribute("sortOrder").Value) : (byte)0, @@ -404,9 +416,12 @@ namespace umbraco.BusinessLogic addElement.Attribute("title").Value, addElement.Attribute("iconClosed").Value, addElement.Attribute("iconOpen").Value, - (string)addElement.Attribute("assembly"), //this could be empty: http://issues.umbraco.org/issue/U4-1360 + (string)addElement.Attribute("assembly"), //this could be empty: http://issues.umbraco.org/issue/U4-1360 addElement.Attribute("type").Value, addElement.Attribute("action") != null ? addElement.Attribute("action").Value : "")); + } + + } }, false); diff --git a/src/umbraco.businesslogic/ApplicationTreeRegistrar.cs b/src/umbraco.businesslogic/ApplicationTreeRegistrar.cs index 67c07ff025..e12eb2f21b 100644 --- a/src/umbraco.businesslogic/ApplicationTreeRegistrar.cs +++ b/src/umbraco.businesslogic/ApplicationTreeRegistrar.cs @@ -13,8 +13,10 @@ namespace umbraco.BusinessLogic { public ApplicationTreeRegistrar() { - //don't do anything if the application is not configured! - if (ApplicationContext.Current == null || !ApplicationContext.Current.IsConfigured) + //don't do anything if the application or database is not configured! + if (ApplicationContext.Current == null + || !ApplicationContext.Current.IsConfigured + || !ApplicationContext.Current.DatabaseContext.IsDatabaseConfigured) return; // Load all Trees by attribute and add them to the XML config