From 654c3b7403fafa9a6f5b3d09941f3082014c93f7 Mon Sep 17 00:00:00 2001 From: Sebastiaan Janssen Date: Fri, 23 Nov 2012 08:02:23 -0100 Subject: [PATCH 1/6] Another temporary fix for trees being unavailable after install, the context is null during upgrades in the installer, so would cause a YSOD --- .../umbraco.presentation/install/steps/theend.ascx.cs | 2 +- src/umbraco.businesslogic/ApplicationTreeRegistrar.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Umbraco.Web/umbraco.presentation/install/steps/theend.ascx.cs b/src/Umbraco.Web/umbraco.presentation/install/steps/theend.ascx.cs index 56a49c13c2..9e05fc88aa 100644 --- a/src/Umbraco.Web/umbraco.presentation/install/steps/theend.ascx.cs +++ b/src/Umbraco.Web/umbraco.presentation/install/steps/theend.ascx.cs @@ -32,7 +32,7 @@ namespace umbraco.presentation.install.steps if (!cms.businesslogic.skinning.Skinning.IsStarterKitInstalled()) customizeSite.Visible = false; - var initTrees = new ApplicationTreeRegistrar(); + new ApplicationTreeRegistrar(); } #region Web Form Designer generated code diff --git a/src/umbraco.businesslogic/ApplicationTreeRegistrar.cs b/src/umbraco.businesslogic/ApplicationTreeRegistrar.cs index 97628bbacd..07175dcc96 100644 --- a/src/umbraco.businesslogic/ApplicationTreeRegistrar.cs +++ b/src/umbraco.businesslogic/ApplicationTreeRegistrar.cs @@ -31,7 +31,7 @@ namespace umbraco.BusinessLogic public ApplicationTreeRegistrar() { //don't do anything if the application is not configured! - if (!ApplicationContext.Current.IsConfigured) + if (ApplicationContext.Current == null || !ApplicationContext.Current.IsConfigured) return; // Load all Trees by attribute and add them to the XML config From 55cb46927e49ea1442d3f2e3ba69f360e86d7332 Mon Sep 17 00:00:00 2001 From: PerPloug Date: Fri, 23 Nov 2012 09:37:35 -0100 Subject: [PATCH 2/6] Changes to template and masterpages helper --- .../template/MasterpageHelper.cs | 158 +++++++++++++++++- .../businesslogic/template/Template.cs | 24 ++- 2 files changed, 164 insertions(+), 18 deletions(-) diff --git a/src/umbraco.cms/businesslogic/template/MasterpageHelper.cs b/src/umbraco.cms/businesslogic/template/MasterpageHelper.cs index 54d8153015..8dc6936d03 100644 --- a/src/umbraco.cms/businesslogic/template/MasterpageHelper.cs +++ b/src/umbraco.cms/businesslogic/template/MasterpageHelper.cs @@ -25,15 +25,18 @@ namespace umbraco.cms.businesslogic.template return IOHelper.MapPath(SystemDirectories.Masterpages + "/" + t.Alias.Replace(" ", "") + ".master"); } - internal static string CreateMasterPage(Template t, bool overWrite = false) + internal static string CreateMasterPage(Template t, bool overWrite = false) { string masterpageContent = ""; - if (!File.Exists(GetFilePath(t)) || overWrite) - masterpageContent = SaveTemplateToFile(t, t.Alias); + if (!File.Exists(GetFilePath(t)) || overWrite) + { + masterpageContent = CreateDefaultMasterPageContent(t, t.Alias); + saveDesignToFile(t, null, masterpageContent); + } else { - System.IO.TextReader tr = new StreamReader(GetFilePath(t)); + System.IO.TextReader tr = new StreamReader(GetFilePath(t)); masterpageContent = tr.ReadToEnd(); tr.Close(); } @@ -56,7 +59,152 @@ namespace umbraco.cms.businesslogic.template internal static string UpdateMasterPageFile(Template t, string currentAlias) { - return SaveTemplateToFile(t, currentAlias); + var template = updateMasterPageContent(t, currentAlias); + updateChildTemplates(t, currentAlias); + saveDesignToFile(t, currentAlias, template); + + return template; + } + + internal static string CreateDefaultMasterPageContent(Template template, string currentAlias) + { + string design = GetMasterPageHeader(template) + "\n"; + + if (template.HasMasterTemplate) + { + var master = new Template(template.MasterTemplate); + + foreach (string cpId in master.contentPlaceholderIds()) + { + design += "\n\t\n\n\n"; + } + } + else + { + design += GetMasterContentElement(template) + "\n"; + design += template.Design; + design += "\n" + Environment.NewLine; + } + + return design; + + + /* + var masterPageContent = template.Design; + + if (!IsMasterPageSyntax(masterPageContent)) + masterPageContent = ConvertToMasterPageSyntax(template); + + // Add header to master page if it doesn't exist + if (!masterPageContent.TrimStart().StartsWith("<%@")) + { + masterPageContent = GetMasterPageHeader(template) + "\n" + masterPageContent; + } + else + { + // verify that the masterpage attribute is the same as the masterpage + string masterHeader = + masterPageContent.Substring(0, masterPageContent.IndexOf("%>") + 2).Trim( + Environment.NewLine.ToCharArray()); + + // find the masterpagefile attribute + MatchCollection m = Regex.Matches(masterHeader, "(?\\S*)=\"(?[^\"]*)\"", + RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace); + + foreach (Match attributeSet in m) + { + if (attributeSet.Groups["attributeName"].Value.ToLower() == "masterpagefile") + { + // validate the masterpagefile + string currentMasterPageFile = attributeSet.Groups["attributeValue"].Value; + string currentMasterTemplateFile = ParentTemplatePath(template); + + if (currentMasterPageFile != currentMasterTemplateFile) + { + masterPageContent = + masterPageContent.Replace( + attributeSet.Groups["attributeName"].Value + "=\"" + currentMasterPageFile + "\"", + attributeSet.Groups["attributeName"].Value + "=\"" + currentMasterTemplateFile + + "\""); + } + } + } + + } + + return masterPageContent; + * */ + } + + internal static string updateMasterPageContent(Template template, string currentAlias) + { + var masterPageContent = template.Design; + + if (!string.IsNullOrEmpty(currentAlias) && currentAlias != template.Alias) + { + string masterHeader = + masterPageContent.Substring(0, masterPageContent.IndexOf("%>") + 2).Trim( + Environment.NewLine.ToCharArray()); + + // find the masterpagefile attribute + MatchCollection m = Regex.Matches(masterHeader, "(?\\S*)=\"(?[^\"]*)\"", + RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace); + + foreach (Match attributeSet in m) + { + if (attributeSet.Groups["attributeName"].Value.ToLower() == "masterpagefile") + { + // validate the masterpagefile + string currentMasterPageFile = attributeSet.Groups["attributeValue"].Value; + string currentMasterTemplateFile = ParentTemplatePath(template); + + if (currentMasterPageFile != currentMasterTemplateFile) + { + masterPageContent = + masterPageContent.Replace( + attributeSet.Groups["attributeName"].Value + "=\"" + currentMasterPageFile + "\"", + attributeSet.Groups["attributeName"].Value + "=\"" + currentMasterTemplateFile + + "\""); + } + } + } + } + + return masterPageContent; + } + + private static void updateChildTemplates(Template t, string currentAlias) + { + //if we have a Old Alias if the alias and therefor the masterpage file name has changed... + //so before we save the new masterfile, we'll clear the old one, so we don't up with + //Unused masterpage files + if (!string.IsNullOrEmpty(currentAlias) && currentAlias != t.Alias) + { + //Ensure that child templates have the right master masterpage file name + if (t.HasChildren) + { + var c = t.Children; + foreach (CMSNode cmn in c) + UpdateMasterPageFile(new Template(cmn.Id), null); + } + } + } + + + private static void saveDesignToFile(Template t, string currentAlias, string design) + { + //kill the old file.. + if (!string.IsNullOrEmpty(currentAlias) && currentAlias != t.Alias) + { + string _oldFile = + IOHelper.MapPath(SystemDirectories.Masterpages + "/" + currentAlias.Replace(" ", "") + ".master"); + if (System.IO.File.Exists(_oldFile)) + System.IO.File.Delete(_oldFile); + } + + // save the file in UTF-8 + System.IO.File.WriteAllText(GetFilePath(t), design, System.Text.Encoding.UTF8); } internal static void RemoveMasterPageFile(string alias) diff --git a/src/umbraco.cms/businesslogic/template/Template.cs b/src/umbraco.cms/businesslogic/template/Template.cs index 9a5e8368bd..f1446d1e63 100644 --- a/src/umbraco.cms/businesslogic/template/Template.cs +++ b/src/umbraco.cms/businesslogic/template/Template.cs @@ -383,18 +383,15 @@ namespace umbraco.cms.businesslogic.template return engine; } - public static Template MakeNew(string Name, BusinessLogic.User u, Template master) - { - return MakeNew(Name, u, master, null); - } - - private static Template MakeNew(string Name, BusinessLogic.User u, Template master, string design) + public static Template MakeNew(string Name, BusinessLogic.User u, Template master) { - Template t = MakeNew(Name, u, design); - t.MasterTemplate = master.Id; + return MakeNew(Name, u, master, null); + } - t.Save(); - return t; + + private static Template MakeNew(string name, BusinessLogic.User u, string design) + { + return MakeNew(name, u, null, design); } public static Template MakeNew(string name, BusinessLogic.User u) @@ -402,7 +399,7 @@ namespace umbraco.cms.businesslogic.template return MakeNew(name, u, design: null); } - private static Template MakeNew(string name, BusinessLogic.User u, string design) + private static Template MakeNew(string name, BusinessLogic.User u, Template master, string design) { // CMSNode MakeNew(int parentId, Guid objectType, int userId, int level, string text, Guid uniqueID) @@ -418,8 +415,6 @@ namespace umbraco.cms.businesslogic.template name = name.Substring(0, 95) + "..."; - - SqlHelper.ExecuteNonQuery("INSERT INTO cmsTemplate (NodeId, Alias, design, master) VALUES (@nodeId, @alias, @design, @master)", SqlHelper.CreateParameter("@nodeId", n.Id), SqlHelper.CreateParameter("@alias", name), @@ -430,6 +425,9 @@ namespace umbraco.cms.businesslogic.template NewEventArgs e = new NewEventArgs(); t.OnNew(e); + if (master != null) + t.MasterTemplate = master.Id; + switch (DetermineRenderingEngine(t, design)) { case RenderingEngine.Mvc: From e23ed30b0cb80ce9b424ee5b669fa8d76c49236d Mon Sep 17 00:00:00 2001 From: Sebastiaan Janssen Date: Fri, 23 Nov 2012 11:45:51 -0100 Subject: [PATCH 3/6] Took out the temporary tree fixes and put another temp fix in (reverts to the 4.10.x code) Also removed dependency on ClientDependency.Mvc for now to make upgrades easier (no requirement to do assembly redirects in web.config) --- src/Umbraco.Web.UI/Umbraco.Web.UI.csproj | 3 --- src/Umbraco.Web.UI/web.Template.config | 6 +----- .../umbraco.presentation/install/steps/theend.ascx.cs | 2 -- .../umbraco/Trees/TreeDefinitionCollection.cs | 8 +++++--- src/umbraco.businesslogic/ApplicationTreeRegistrar.cs | 2 +- 5 files changed, 7 insertions(+), 14 deletions(-) diff --git a/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj b/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj index d0981977cf..bc06fffbb8 100644 --- a/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj +++ b/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj @@ -97,9 +97,6 @@ False ..\packages\ClientDependency.1.5.1.0\lib\ClientDependency.Core.dll - - ..\packages\ClientDependency-Mvc.1.5.1.0\lib\ClientDependency.Core.Mvc.dll - False ..\..\lib\CookComputing.XmlRpcV2.dll diff --git a/src/Umbraco.Web.UI/web.Template.config b/src/Umbraco.Web.UI/web.Template.config index 52fae663cf..27c815253a 100644 --- a/src/Umbraco.Web.UI/web.Template.config +++ b/src/Umbraco.Web.UI/web.Template.config @@ -241,11 +241,7 @@ - - - - - + diff --git a/src/Umbraco.Web/umbraco.presentation/install/steps/theend.ascx.cs b/src/Umbraco.Web/umbraco.presentation/install/steps/theend.ascx.cs index 9e05fc88aa..05c1e4694b 100644 --- a/src/Umbraco.Web/umbraco.presentation/install/steps/theend.ascx.cs +++ b/src/Umbraco.Web/umbraco.presentation/install/steps/theend.ascx.cs @@ -31,8 +31,6 @@ namespace umbraco.presentation.install.steps if (!cms.businesslogic.skinning.Skinning.IsStarterKitInstalled()) customizeSite.Visible = false; - - new ApplicationTreeRegistrar(); } #region Web Form Designer generated code diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/Trees/TreeDefinitionCollection.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/Trees/TreeDefinitionCollection.cs index 5d816ce07f..b48c905777 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/Trees/TreeDefinitionCollection.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/Trees/TreeDefinitionCollection.cs @@ -15,6 +15,7 @@ using umbraco.interfaces; using umbraco.BusinessLogic.Utils; using umbraco.BusinessLogic; using umbraco.BasePages; +using TypeFinder = umbraco.BusinessLogic.Utils.TypeFinder; namespace umbraco.cms.presentation.Trees { @@ -151,11 +152,12 @@ namespace umbraco.cms.presentation.Trees l.UpgradeToWriteLock(); - - var foundITrees = PluginManager.Current.ResolveTrees(); + List foundITrees = TypeFinder.FindClassesOfType(); + //var foundITrees = PluginManager.Current.ResolveTrees(); var objTrees = ApplicationTree.getAll(); - var appTrees = new List(); + List appTrees = new List(); + //var appTrees = new List(); appTrees.AddRange(objTrees); var apps = Application.getAll(); diff --git a/src/umbraco.businesslogic/ApplicationTreeRegistrar.cs b/src/umbraco.businesslogic/ApplicationTreeRegistrar.cs index 07175dcc96..97628bbacd 100644 --- a/src/umbraco.businesslogic/ApplicationTreeRegistrar.cs +++ b/src/umbraco.businesslogic/ApplicationTreeRegistrar.cs @@ -31,7 +31,7 @@ namespace umbraco.BusinessLogic public ApplicationTreeRegistrar() { //don't do anything if the application is not configured! - if (ApplicationContext.Current == null || !ApplicationContext.Current.IsConfigured) + if (!ApplicationContext.Current.IsConfigured) return; // Load all Trees by attribute and add them to the XML config From f1314628d7e51631904b87930a31ff6d41c1d83b Mon Sep 17 00:00:00 2001 From: Sebastiaan Janssen Date: Fri, 23 Nov 2012 12:01:43 -0100 Subject: [PATCH 4/6] One last hack to get the the macroengines to show up after install. --- .../umbraco.presentation/install/steps/theend.ascx.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Umbraco.Web/umbraco.presentation/install/steps/theend.ascx.cs b/src/Umbraco.Web/umbraco.presentation/install/steps/theend.ascx.cs index 05c1e4694b..05230b54e8 100644 --- a/src/Umbraco.Web/umbraco.presentation/install/steps/theend.ascx.cs +++ b/src/Umbraco.Web/umbraco.presentation/install/steps/theend.ascx.cs @@ -1,3 +1,5 @@ +using System.IO; +using Umbraco.Core.IO; using umbraco.BusinessLogic; namespace umbraco.presentation.install.steps @@ -31,6 +33,10 @@ namespace umbraco.presentation.install.steps if (!cms.businesslogic.skinning.Skinning.IsStarterKitInstalled()) customizeSite.Visible = false; + + var tempFolder = IOHelper.MapPath("~/App_Data/TEMP/PluginCache"); + if(Directory.Exists(tempFolder)) + Directory.Delete(tempFolder, true); } #region Web Form Designer generated code From 839dd7315a917629e7c777926ba5076824599d9b Mon Sep 17 00:00:00 2001 From: Sebastiaan Janssen Date: Fri, 23 Nov 2012 13:33:15 -0100 Subject: [PATCH 5/6] Added tag Release-4.11.0 for changeset 20e4dff821d8 --- .hgtags | 1 + 1 file changed, 1 insertion(+) diff --git a/.hgtags b/.hgtags index 8a944ec680..48a3450e6e 100644 --- a/.hgtags +++ b/.hgtags @@ -12,3 +12,4 @@ d03fcffb8834a9583a56813bb44b6abbd9f042cc Release-4.6.0 de73e687ddf6086ed52b6554676c1632865d07f2 Release-4.9.0 8d7d8609e2e4b971da99cd97f72132ce85ce3333 Release-4.9.1 f6da531fbb4c251ff61d314e2a7effb13c71e74a Release-4.10.0 +20e4dff821d8ac2527a5353618fa1a23ea1d8b34 Release-4.11.0 From 68605a75601f39b9ea40e979a85e8001e4094f90 Mon Sep 17 00:00:00 2001 From: Sebastiaan Janssen Date: Fri, 23 Nov 2012 13:36:14 -0100 Subject: [PATCH 6/6] Closed branch 4.11.0