list, char seperator) {
string retVal = "";
foreach (string str in list) {
retVal += str + seperator.ToString();
diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/developer/Packages/installer.aspx.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/developer/Packages/installer.aspx.cs
index c64f125608..54a6ecb348 100644
--- a/src/Umbraco.Web/umbraco.presentation/umbraco/developer/Packages/installer.aspx.cs
+++ b/src/Umbraco.Web/umbraco.presentation/umbraco/developer/Packages/installer.aspx.cs
@@ -22,11 +22,10 @@ namespace umbraco.presentation.developer.packages
///
public partial class Installer : BasePages.UmbracoEnsuredPage
{
- private Control configControl;
- private cms.businesslogic.packager.repositories.Repository repo;
-
- private cms.businesslogic.packager.Installer p = new cms.businesslogic.packager.Installer();
- private string tempFileName = "";
+ private Control _configControl;
+ private cms.businesslogic.packager.repositories.Repository _repo;
+ private readonly cms.businesslogic.packager.Installer _installer = new cms.businesslogic.packager.Installer();
+ private string _tempFileName = "";
protected void Page_Load(object sender, System.EventArgs e)
{
@@ -47,34 +46,34 @@ namespace umbraco.presentation.developer.packages
//if we are actually in the middle of installing something...
if (!String.IsNullOrEmpty(helper.Request("installing")))
{
- hideAllPanes();
+ HideAllPanes();
pane_installing.Visible = true;
- processInstall(helper.Request("installing"));
+ ProcessInstall(helper.Request("installing"));
}
else if (!String.IsNullOrEmpty(helper.Request("guid")) && !String.IsNullOrEmpty(helper.Request("repoGuid")))
{
//we'll fetch the local information we have about our repo, to find out what webservice to query.
- repo = cms.businesslogic.packager.repositories.Repository.getByGuid(helper.Request("repoGuid"));
+ _repo = cms.businesslogic.packager.repositories.Repository.getByGuid(helper.Request("repoGuid"));
- if (repo.HasConnection())
+ if (_repo.HasConnection())
{
//from the webservice we'll fetch some info about the package.
- cms.businesslogic.packager.repositories.Package pack = repo.Webservice.PackageByGuid(helper.Request("guid"));
+ cms.businesslogic.packager.repositories.Package pack = _repo.Webservice.PackageByGuid(helper.Request("guid"));
//if the package is protected we will ask for the users credentials. (this happens every time they try to fetch anything)
if (!pack.Protected)
{
//if it isn't then go straigt to the accept licens screen
- tempFile.Value = p.Import(repo.fetch(helper.Request("guid")));
- updateSettings();
+ tempFile.Value = _installer.Import(_repo.fetch(helper.Request("guid")));
+ UpdateSettings();
}
else if (!IsPostBack)
{
//Authenticate against the repo
- hideAllPanes();
+ HideAllPanes();
pane_authenticate.Visible = true;
}
@@ -83,7 +82,7 @@ namespace umbraco.presentation.developer.packages
{
fb.Style.Add("margin-top", "7px");
fb.type = global::umbraco.uicontrols.Feedback.feedbacktype.error;
- fb.Text = "No connection to repository. Runway could not be installed as there was no connection to: '" + repo.RepositoryUrl + "'";
+ fb.Text = "No connection to repository. Runway could not be installed as there was no connection to: '" + _repo.RepositoryUrl + "'";
pane_upload.Visible = false;
}
}
@@ -99,11 +98,11 @@ namespace umbraco.presentation.developer.packages
{
try
{
- tempFileName = Guid.NewGuid().ToString() + ".umb";
- string fileName = SystemDirectories.Data + System.IO.Path.DirectorySeparatorChar + tempFileName;
+ _tempFileName = Guid.NewGuid().ToString() + ".umb";
+ string fileName = SystemDirectories.Data + System.IO.Path.DirectorySeparatorChar + _tempFileName;
file1.PostedFile.SaveAs(IOHelper.MapPath(fileName));
- tempFile.Value = p.Import(tempFileName);
- updateSettings();
+ tempFile.Value = _installer.Import(_tempFileName);
+ UpdateSettings();
}
catch (Exception ex)
{
@@ -116,75 +115,75 @@ namespace umbraco.presentation.developer.packages
protected void fetchProtectedPackage(object sender, EventArgs e)
{
//we auth against the webservice. This key will be used to fetch the protected package.
- string memberGuid = repo.Webservice.authenticate(tb_email.Text, library.md5(tb_password.Text));
+ string memberGuid = _repo.Webservice.authenticate(tb_email.Text, library.md5(tb_password.Text));
//if we auth correctly and get a valid key back, we will fetch the file from the repo webservice.
if (!string.IsNullOrEmpty(memberGuid))
{
- tempFile.Value = p.Import(repo.fetch(helper.Request("guid"), memberGuid));
- updateSettings();
+ tempFile.Value = _installer.Import(_repo.fetch(helper.Request("guid"), memberGuid));
+ UpdateSettings();
}
}
//this loads the accept license screen
- private void updateSettings()
+ private void UpdateSettings()
{
- hideAllPanes();
+ HideAllPanes();
pane_acceptLicense.Visible = true;
- pane_acceptLicenseInner.Text = "Installing the package: " + p.Name;
- Panel1.Text = "Installing the package: " + p.Name;
+ pane_acceptLicenseInner.Text = "Installing the package: " + _installer.Name;
+ Panel1.Text = "Installing the package: " + _installer.Name;
- if (p.ContainsUnsecureFiles && repo == null)
+ if (_installer.ContainsUnsecureFiles && _repo == null)
{
pp_unsecureFiles.Visible = true;
- foreach (string str in p.UnsecureFiles)
+ foreach (string str in _installer.UnsecureFiles)
{
lt_files.Text += "" + str + "";
}
}
- if (p.ContainsMacroConflict)
+ if (_installer.ContainsMacroConflict)
{
pp_macroConflicts.Visible = true;
- foreach (var item in p.ConflictingMacroAliases)
+ foreach (var item in _installer.ConflictingMacroAliases)
{
ltrMacroAlias.Text += "" + item.Key + " (Alias: " + item.Value + ")";
}
}
- if (p.ContainsTemplateConflicts)
+ if (_installer.ContainsTemplateConflicts)
{
pp_templateConflicts.Visible = true;
- foreach (var item in p.ConflictingTemplateAliases)
+ foreach (var item in _installer.ConflictingTemplateAliases)
{
ltrTemplateAlias.Text += "" + item.Key + " (Alias: " + item.Value + ")";
}
}
- if (p.ContainsStyleSheeConflicts)
+ if (_installer.ContainsStyleSheeConflicts)
{
pp_stylesheetConflicts.Visible = true;
- foreach (var item in p.ConflictingStyleSheetNames)
+ foreach (var item in _installer.ConflictingStyleSheetNames)
{
ltrStylesheetNames.Text += "" + item.Key + " (Alias: " + item.Value + ")";
}
}
- LabelName.Text = p.Name + " Version: " + p.Version;
- LabelMore.Text = "" + p.Url + "";
- LabelAuthor.Text = "" + p.Author + "";
- LabelLicense.Text = "" + p.License + "";
+ LabelName.Text = _installer.Name + " Version: " + _installer.Version;
+ LabelMore.Text = "" + _installer.Url + "";
+ LabelAuthor.Text = "" + _installer.Author + "";
+ LabelLicense.Text = "" + _installer.License + "";
- if (p.ReadMe != "")
- readme.Text = "" + library.ReplaceLineBreaks(library.StripHtml(p.ReadMe)) + "
";
+ if (_installer.ReadMe != "")
+ readme.Text = "" + library.ReplaceLineBreaks(library.StripHtml(_installer.ReadMe)) + "
";
else
readme.Text = "No information
";
}
- private void processInstall(string currentStep)
+ private void ProcessInstall(string currentStep)
{
string dir = helper.Request("dir");
int packageId = 0;
@@ -193,20 +192,20 @@ namespace umbraco.presentation.developer.packages
//first load in the config from the temporary directory
//this will ensure that the installer have access to all the new files and the package manifest
- p.LoadConfig(dir);
+ _installer.LoadConfig(dir);
switch (currentStep)
{
case "businesslogic":
- p.InstallBusinessLogic(packageId, dir);
+ _installer.InstallBusinessLogic(packageId, dir);
//making sure that publishing actions performed from the cms layer gets pushed to the presentation
library.RefreshContent();
- if (p.Control != null && p.Control != "")
+ if (_installer.Control != null && _installer.Control != "")
{
Response.Redirect("installer.aspx?installing=customInstaller&dir=" + dir + "&pId=" + packageId.ToString());
}
@@ -216,26 +215,26 @@ namespace umbraco.presentation.developer.packages
}
break;
case "customInstaller":
- if (p.Control != null && p.Control != "")
+ if (_installer.Control != null && _installer.Control != "")
{
- hideAllPanes();
+ HideAllPanes();
- configControl = new System.Web.UI.UserControl().LoadControl(SystemDirectories.Root + p.Control);
- configControl.ID = "packagerConfigControl";
+ _configControl = new System.Web.UI.UserControl().LoadControl(SystemDirectories.Root + _installer.Control);
+ _configControl.ID = "packagerConfigControl";
- pane_optional.Controls.Add(configControl);
+ pane_optional.Controls.Add(_configControl);
pane_optional.Visible = true;
}
else
{
- hideAllPanes();
+ HideAllPanes();
pane_success.Visible = true;
BasePage.Current.ClientTools.ReloadActionNode(true, true);
}
break;
case "finished":
- hideAllPanes();
- string url = p.Url;
+ HideAllPanes();
+ string url = _installer.Url;
string packageViewUrl = "installedPackage.aspx?id=" + packageId.ToString();
bt_viewInstalledPackage.OnClientClick = "document.location = '" + packageViewUrl + "'; return false;";
@@ -247,7 +246,7 @@ namespace umbraco.presentation.developer.packages
pane_success.Visible = true;
BasePage.Current.ClientTools.ReloadActionNode(true, true);
- p.InstallCleanUp(packageId, dir);
+ _installer.InstallCleanUp(packageId, dir);
//clear the tree cache
ClientTools.ClearClientTreeCache()
@@ -269,30 +268,30 @@ namespace umbraco.presentation.developer.packages
//we will now create the installer manifest, which means that umbraco can register everything that gets added to the system
//this returns an id of the manifest.
- p.LoadConfig(tempFile.Value);
+ _installer.LoadConfig(tempFile.Value);
- int pId = p.CreateManifest(tempFile.Value, helper.Request("guid"), helper.Request("repoGuid"));
+ int pId = _installer.CreateManifest(tempFile.Value, helper.Request("guid"), helper.Request("repoGuid"));
//and then copy over the files. This will take some time if it contains .dlls that will reboot the system..
- p.InstallFiles(pId, tempFile.Value);
+ _installer.InstallFiles(pId, tempFile.Value);
Response.Redirect("installer.aspx?installing=businesslogic&dir=" + tempFile.Value + "&pId=" + pId.ToString());
}
- private void drawConfig()
+ private void DrawConfig()
{
- hideAllPanes();
+ HideAllPanes();
- configControl = new System.Web.UI.UserControl().LoadControl(SystemDirectories.Root + helper.Request("config"));
- configControl.ID = "packagerConfigControl";
+ _configControl = new System.Web.UI.UserControl().LoadControl(SystemDirectories.Root + helper.Request("config"));
+ _configControl.ID = "packagerConfigControl";
- pane_optional.Controls.Add(configControl);
+ pane_optional.Controls.Add(_configControl);
pane_optional.Visible = true;
}
- private void hideAllPanes()
+ private void HideAllPanes()
{
pane_authenticate.Visible = false;
pane_acceptLicense.Visible = false;
diff --git a/src/umbraco.businesslogic/ApplicationRegistrar.cs b/src/umbraco.businesslogic/ApplicationRegistrar.cs
index d29d50d90f..2432ad783c 100644
--- a/src/umbraco.businesslogic/ApplicationRegistrar.cs
+++ b/src/umbraco.businesslogic/ApplicationRegistrar.cs
@@ -1,4 +1,6 @@
-using System.Linq;
+using System;
+using System.Data.SqlClient;
+using System.Linq;
using System.Xml.Linq;
using Umbraco.Core;
using umbraco.BusinessLogic.Utils;
@@ -29,6 +31,11 @@ namespace umbraco.BusinessLogic
public ApplicationRegistrar()
{
+
+ //don't do anything if the application is not configured!
+ if (!ApplicationContext.Current.IsConfigured)
+ return;
+
// Load all Applications by attribute and add them to the XML config
var types = PluginManager.Current.ResolveApplications();
@@ -40,7 +47,7 @@ namespace umbraco.BusinessLogic
var allAliases = Application.getAll().Select(x => x.alias).Concat(attrs.Select(x => x.Alias));
var inString = "'" + string.Join("','", allAliases) + "'";
-
+
Application.LoadXml(doc =>
{
foreach (var attr in attrs)
@@ -51,16 +58,17 @@ namespace umbraco.BusinessLogic
new XAttribute("icon", attr.Icon),
new XAttribute("sortOrder", attr.SortOrder)));
}
-
- var dbApps = SqlHelper.ExecuteReader("SELECT * FROM umbracoApp WHERE appAlias NOT IN ("+ inString +")");
- while (dbApps.Read())
- {
- doc.Root.Add(new XElement("add",
- new XAttribute("alias", dbApps.GetString("appAlias")),
- new XAttribute("name", dbApps.GetString("appName")),
- new XAttribute("icon", dbApps.GetString("appIcon")),
- new XAttribute("sortOrder", dbApps.GetByte("sortOrder"))));
- }
+
+ var dbApps = SqlHelper.ExecuteReader("SELECT * FROM umbracoApp WHERE appAlias NOT IN (" + inString + ")");
+ while (dbApps.Read())
+ {
+ doc.Root.Add(new XElement("add",
+ new XAttribute("alias", dbApps.GetString("appAlias")),
+ new XAttribute("name", dbApps.GetString("appName")),
+ new XAttribute("icon", dbApps.GetString("appIcon")),
+ new XAttribute("sortOrder", dbApps.GetByte("sortOrder"))));
+ }
+
}, true);
diff --git a/src/umbraco.businesslogic/ApplicationTreeRegistrar.cs b/src/umbraco.businesslogic/ApplicationTreeRegistrar.cs
index 70f709c84f..97628bbacd 100644
--- a/src/umbraco.businesslogic/ApplicationTreeRegistrar.cs
+++ b/src/umbraco.businesslogic/ApplicationTreeRegistrar.cs
@@ -30,6 +30,10 @@ namespace umbraco.BusinessLogic
public ApplicationTreeRegistrar()
{
+ //don't do anything if the application is not configured!
+ if (!ApplicationContext.Current.IsConfigured)
+ return;
+
// Load all Trees by attribute and add them to the XML config
var types = PluginManager.Current.ResolveAttributedTrees();
diff --git a/src/umbraco.businesslogic/IO/IOHelper.cs b/src/umbraco.businesslogic/IO/IOHelper.cs
index eb99389fcc..8a7e10d9eb 100644
--- a/src/umbraco.businesslogic/IO/IOHelper.cs
+++ b/src/umbraco.businesslogic/IO/IOHelper.cs
@@ -53,12 +53,13 @@ namespace umbraco.IO
}
//use a tilde character instead of the complete path
+ [Obsolete("This method is no longer in use and will be removed in future versions")]
public static string returnPath(string settingsKey, string standardPath, bool useTilde)
{
return Umbraco.Core.IO.IOHelper.ReturnPath(settingsKey, standardPath, useTilde);
}
-
+ [Obsolete("This method is no longer in use and will be removed in future versions")]
public static string returnPath(string settingsKey, string standardPath)
{
return Umbraco.Core.IO.IOHelper.ReturnPath(settingsKey, standardPath);
diff --git a/src/umbraco.cms/businesslogic/Content.cs b/src/umbraco.cms/businesslogic/Content.cs
index 05b22daec3..90b4c35caa 100644
--- a/src/umbraco.cms/businesslogic/Content.cs
+++ b/src/umbraco.cms/businesslogic/Content.cs
@@ -508,8 +508,13 @@ namespace umbraco.cms.businesslogic
///
///
/// The new version Id
- protected Guid createNewVersion(DateTime versionDate)
+ protected Guid createNewVersion(DateTime versionDate = default(DateTime))
{
+ if (versionDate == default (DateTime))
+ {
+ versionDate = DateTime.Now;
+ }
+
ClearLoadedProperties();
Guid newVersion = Guid.NewGuid();
diff --git a/src/umbraco.cms/businesslogic/ContentType.cs b/src/umbraco.cms/businesslogic/ContentType.cs
index 6534972360..8367e8335b 100644
--- a/src/umbraco.cms/businesslogic/ContentType.cs
+++ b/src/umbraco.cms/businesslogic/ContentType.cs
@@ -658,7 +658,7 @@ namespace umbraco.cms.businesslogic
SqlHelper.CreateParameter("@parentContentTypeId", this.Id)) > 0;
}
- public List GetChildTypes()
+ public IEnumerable GetChildTypes()
{
var cts = new List();
using (IRecordsReader dr =
@@ -694,7 +694,7 @@ namespace umbraco.cms.businesslogic
// has a nodetype of this id
var contentTypeToRemove = new ContentType(parentContentTypeId);
- removeMasterPropertyTypeData(contentTypeToRemove, this);
+ RemoveMasterPropertyTypeData(contentTypeToRemove, this);
SqlHelper.ExecuteNonQuery(
"DELETE FROM [cmsContentType2ContentType] WHERE parentContentTypeId = @parentContentTypeId AND childContentTypeId = @childContentTypeId",
@@ -704,7 +704,7 @@ namespace umbraco.cms.businesslogic
}
}
- private void removeMasterPropertyTypeData(ContentType contentTypeToRemove, ContentType currentContentType)
+ private void RemoveMasterPropertyTypeData(ContentType contentTypeToRemove, ContentType currentContentType)
{
foreach (var pt in contentTypeToRemove.PropertyTypes)
{
@@ -723,10 +723,10 @@ namespace umbraco.cms.businesslogic
}
// remove sub data too
foreach(var ct in currentContentType.GetChildTypes())
- removeMasterPropertyTypeData(contentTypeToRemove, ct);
+ RemoveMasterPropertyTypeData(contentTypeToRemove, ct);
}
- public List PropertyTypeGroups
+ public IEnumerable PropertyTypeGroups
{
get { return PropertyTypeGroup.GetPropertyTypeGroupsFromContentType(Id); }
}
@@ -1170,7 +1170,7 @@ namespace umbraco.cms.businesslogic
private void InitializeVirtualTabs()
{
m_VirtualTabs = new List();
- foreach (PropertyTypeGroup ptg in PropertyTypeGroups.FindAll(x => x.ParentId == 0 && x.ContentTypeId == this.Id))
+ foreach (PropertyTypeGroup ptg in PropertyTypeGroups.Where(x => x.ParentId == 0 && x.ContentTypeId == this.Id))
m_VirtualTabs.Add(new Tab(ptg.Id, ptg.Name, ptg.SortOrder, this));
// Master Content Type
@@ -1335,19 +1335,24 @@ namespace umbraco.cms.businesslogic
{
// NH, temp fix for 4.9 to use the new PropertyTypeGroup API
- List pts = PropertyTypeGroup.GetPropertyTypeGroup(this.Id).GetPropertyTypes();
+ var pts = PropertyTypeGroup.GetPropertyTypeGroup(this.Id).GetPropertyTypes();
if (includeInheritedProperties)
{
// we need to
cms.businesslogic.ContentType ct = cms.businesslogic.ContentType.GetContentType(contentTypeId);
return
- pts.FindAll(
+ pts.Where(
x =>
ct.MasterContentTypes.Contains(
x.ContentTypeId) || x.ContentTypeId == contentTypeId).ToArray();
}
- return pts.FindAll(x => x.ContentTypeId == contentTypeId).ToArray();
+ return pts.Where(x => x.ContentTypeId == contentTypeId).ToArray();
+
+ //TODO: Why is this code still here?? revision: 1bd01ec17bf9
+ // shouldn't this code be removed/commented out or something?????
+ // the below code is completely unreachable.
+
// zb-00040 #29889 : fix cache key issues!
// now maintaining a cache of local properties per contentTypeId, then merging when required
@@ -1388,7 +1393,7 @@ namespace umbraco.cms.businesslogic
// while (dr.Read())
// tmp1.Add(PropertyType.GetPropertyType(dr.GetInt("id")));
// }
- return tmp1;
+ return tmp1.ToList();
});
tmp.AddRange(ptypes);
diff --git a/src/umbraco.cms/businesslogic/Packager/Installer.cs b/src/umbraco.cms/businesslogic/Packager/Installer.cs
index 8b51588f54..b55ea4715d 100644
--- a/src/umbraco.cms/businesslogic/Packager/Installer.cs
+++ b/src/umbraco.cms/businesslogic/Packager/Installer.cs
@@ -332,7 +332,10 @@ namespace umbraco.cms.businesslogic.packager
if (saveNeeded) { insPack.Save(); saveNeeded = false; }
- // Add master templates
+ //NOTE: SD: I'm pretty sure the only thing the below script does is ensure that the Master template Id is set
+ // in the database, but this is also duplicating the saving of the design content since the above Template.Import
+ // already does this. I've left this for now because I'm not sure the reprocussions of removing it but seems there
+ // is a lot of excess database calls happening here.
foreach (XmlNode n in _packageConfig.DocumentElement.SelectNodes("Templates/Template")) {
string master = xmlHelper.GetNodeValue(n.SelectSingleNode("Master"));
template.Template t = template.Template.GetByAlias(xmlHelper.GetNodeValue(n.SelectSingleNode("Alias")));
diff --git a/src/umbraco.cms/businesslogic/Packager/data.cs b/src/umbraco.cms/businesslogic/Packager/data.cs
index 8e0c5ea366..9c0241c31f 100644
--- a/src/umbraco.cms/businesslogic/Packager/data.cs
+++ b/src/umbraco.cms/businesslogic/Packager/data.cs
@@ -3,6 +3,7 @@ using System.Xml;
using System.Xml.XPath;
using System.Collections.Generic;
using System.IO;
+using Umbraco.Core;
namespace umbraco.cms.businesslogic.packager
{
@@ -46,6 +47,24 @@ namespace umbraco.cms.businesslogic.packager
{
_source = new XmlDocument();
}
+
+ //error checking here
+ if (File.Exists(dataSource))
+ {
+ var isEmpty = false;
+ using (var sr = new StreamReader(dataSource))
+ {
+ if (sr.ReadToEnd().IsNullOrWhiteSpace())
+ {
+ isEmpty = true;
+ }
+ }
+ if (isEmpty)
+ {
+ File.WriteAllText(dataSource, @"");
+ }
+ }
+
_source.Load(dataSource);
}
diff --git a/src/umbraco.cms/businesslogic/propertytype/PropertyTypeGroup.cs b/src/umbraco.cms/businesslogic/propertytype/PropertyTypeGroup.cs
index c2a3c138fe..5f322abdef 100644
--- a/src/umbraco.cms/businesslogic/propertytype/PropertyTypeGroup.cs
+++ b/src/umbraco.cms/businesslogic/propertytype/PropertyTypeGroup.cs
@@ -37,20 +37,20 @@ namespace umbraco.cms.businesslogic.propertytype
SortOrder = -1; // we set this to -1 so in the save method we can get the current highest sortorder in case it's not sat after init (ie. if you want to force a sortOrder)
}
- public List GetPropertyTypes(List contentTypeIds)
+ public IEnumerable GetPropertyTypes(List contentTypeIds)
{
return PropertyType.GetPropertyTypesByGroup(Id, contentTypeIds);
}
- public List GetPropertyTypes()
+ public IEnumerable GetPropertyTypes()
{
return PropertyType.GetPropertyTypesByGroup(Id);
}
//TODO: Verify support for master doctypes / mixins!
- public List GetPropertyTypeGroups()
+ public IEnumerable GetPropertyTypeGroups()
{
- List ptgs = new List();
+ var ptgs = new List();
using (IRecordsReader dr =
SqlHelper.ExecuteReader(@"
SELECT
@@ -86,7 +86,7 @@ namespace umbraco.cms.businesslogic.propertytype
id = @id
",
SqlHelper.CreateParameter("@id", Id),
- SqlHelper.CreateParameter("@parentGroupId", convertParentId(ParentId)),
+ SqlHelper.CreateParameter("@parentGroupId", ConvertParentId(ParentId)),
SqlHelper.CreateParameter("@contentTypeId", ContentTypeId),
SqlHelper.CreateParameter("@sortOrder", SortOrder),
SqlHelper.CreateParameter("@name", Name)
@@ -106,7 +106,7 @@ namespace umbraco.cms.businesslogic.propertytype
VALUES
(@parentGroupId, @contentTypeId, @sortOrder, @name)
",
- SqlHelper.CreateParameter("@parentGroupId", convertParentId(ParentId)),
+ SqlHelper.CreateParameter("@parentGroupId", ConvertParentId(ParentId)),
SqlHelper.CreateParameter("@contentTypeId", ContentTypeId),
SqlHelper.CreateParameter("@sortOrder", SortOrder),
SqlHelper.CreateParameter("@name", Name)
@@ -133,7 +133,7 @@ namespace umbraco.cms.businesslogic.propertytype
SqlHelper.CreateParameter("@id", Id));
}
- public void Load()
+ internal void Load()
{
using (IRecordsReader dr =
SqlHelper.ExecuteReader(@"
@@ -164,9 +164,9 @@ namespace umbraco.cms.businesslogic.propertytype
return ptg;
}
- public static List GetPropertyTypeGroupsFromContentType(int contentTypeId)
+ public static IEnumerable GetPropertyTypeGroupsFromContentType(int contentTypeId)
{
- List ptgs = new List();
+ var ptgs = new List();
using (IRecordsReader dr =
SqlHelper.ExecuteReader(@"
SELECT
@@ -185,7 +185,7 @@ namespace umbraco.cms.businesslogic.propertytype
return ptgs;
}
- private object convertParentId(int parentId)
+ private object ConvertParentId(int parentId)
{
if (parentId == 0)
return DBNull.Value;
diff --git a/src/umbraco.cms/businesslogic/propertytype/propertytype.cs b/src/umbraco.cms/businesslogic/propertytype/propertytype.cs
index 365529f8ab..8d3fcd09c7 100644
--- a/src/umbraco.cms/businesslogic/propertytype/propertytype.cs
+++ b/src/umbraco.cms/businesslogic/propertytype/propertytype.cs
@@ -311,11 +311,11 @@ namespace umbraco.cms.businesslogic.propertytype
public static PropertyType[] GetAll()
{
- List result = GetPropertyTypes();
+ var result = GetPropertyTypes();
return result.ToArray();
}
- public static List GetPropertyTypes()
+ public static IEnumerable GetPropertyTypes()
{
var result = new List();
using (IRecordsReader dr =
@@ -331,12 +331,12 @@ namespace umbraco.cms.businesslogic.propertytype
return result;
}
- public static List GetPropertyTypesByGroup(int groupId, List contentTypeIds)
+ public static IEnumerable GetPropertyTypesByGroup(int groupId, List contentTypeIds)
{
- return GetPropertyTypesByGroup(groupId).FindAll(x => contentTypeIds.Contains(x.ContentTypeId));
+ return GetPropertyTypesByGroup(groupId).Where(x => contentTypeIds.Contains(x.ContentTypeId));
}
- public static List GetPropertyTypesByGroup(int groupId)
+ public static IEnumerable GetPropertyTypesByGroup(int groupId)
{
var result = new List();
using (IRecordsReader dr =
@@ -382,11 +382,11 @@ namespace umbraco.cms.businesslogic.propertytype
FlushCache();
// clean all properties on inherited document types (if this propertytype is removed from a master)
- cleanPropertiesOnDeletion(_contenttypeid);
+ CleanPropertiesOnDeletion(_contenttypeid);
// DocumentType.GetAllAsList().FindAll(dt => dt.MasterContentType == _contenttypeid).ForEach(dt => cleanPropertiesOnDeletion(dt.Id));
// Delete all properties of propertytype
- cleanPropertiesOnDeletion(_contenttypeid);
+ CleanPropertiesOnDeletion(_contenttypeid);
// Delete PropertyType ..
SqlHelper.ExecuteNonQuery("Delete from cmsPropertyType where id = " + Id);
@@ -409,12 +409,12 @@ namespace umbraco.cms.businesslogic.propertytype
}
}
- private void cleanPropertiesOnDeletion(int contentTypeId)
+ private void CleanPropertiesOnDeletion(int contentTypeId)
{
// first delete from all master document types
//TODO: Verify no endless loops with mixins
DocumentType.GetAllAsList().FindAll(dt => dt.MasterContentTypes.Contains(contentTypeId)).ForEach(
- dt => cleanPropertiesOnDeletion(dt.Id));
+ dt => CleanPropertiesOnDeletion(dt.Id));
// then remove from the current doc type
Content[] objs = Content.getContentOfContentType(new ContentType(contentTypeId));
diff --git a/src/umbraco.cms/businesslogic/template/MasterpageHelper.cs b/src/umbraco.cms/businesslogic/template/MasterpageHelper.cs
index 700d8b4165..33375dda77 100644
--- a/src/umbraco.cms/businesslogic/template/MasterpageHelper.cs
+++ b/src/umbraco.cms/businesslogic/template/MasterpageHelper.cs
@@ -5,22 +5,34 @@ using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
+using Umbraco.Core;
using Umbraco.Core.IO;
namespace umbraco.cms.businesslogic.template
{
- internal class MasterpageHelper
+ internal class MasterPageHelper
{
internal static readonly string DefaultMasterTemplate = SystemDirectories.Umbraco + "/masterpages/default.master";
- internal static string CreateMasterpageFile(Template t, bool overWrite = false)
+
+ internal static bool MasterPageExists(Template t)
+ {
+ return File.Exists(GetFilePath(t));
+ }
+
+ internal static string GetFilePath(Template t)
+ {
+ return IOHelper.MapPath(SystemDirectories.Masterpages + "/" + t.Alias.Replace(" ", "") + ".master");
+ }
+
+ internal static string CreateMasterPage(Template t, bool overWrite = false)
{
string masterpageContent = "";
- if (!File.Exists(t.MasterPageFile) || overWrite)
+ if (!File.Exists(GetFilePath(t)) || overWrite)
masterpageContent = SaveTemplateToFile(t, t.Alias);
else
{
- System.IO.TextReader tr = new StreamReader(t.MasterPageFile);
+ System.IO.TextReader tr = new StreamReader(GetFilePath(t));
masterpageContent = tr.ReadToEnd();
tr.Close();
}
@@ -28,11 +40,12 @@ namespace umbraco.cms.businesslogic.template
return masterpageContent;
}
- internal static string GetMasterpageFile(Template t)
+ internal static string GetFileContents(Template t)
{
string masterpageContent = "";
- if (File.Exists(t.MasterPageFile)){
- System.IO.TextReader tr = new StreamReader(t.MasterPageFile);
+ if (File.Exists(GetFilePath(t)))
+ {
+ System.IO.TextReader tr = new StreamReader(GetFilePath(t));
masterpageContent = tr.ReadToEnd();
tr.Close();
}
@@ -40,7 +53,7 @@ namespace umbraco.cms.businesslogic.template
return masterpageContent;
}
- internal static string UpdateMasterpageFile(Template t, string currentAlias)
+ internal static string UpdateMasterPageFile(Template t, string currentAlias)
{
return SaveTemplateToFile(t, currentAlias);
}
@@ -98,10 +111,9 @@ namespace umbraco.cms.businesslogic.template
//Ensure that child templates have the right master masterpage file name
if (template.HasChildren)
{
- //store children array here because iterating over an Array property object is very inneficient.
var c = template.Children;
foreach (CMSNode cmn in c)
- UpdateMasterpageFile(new Template(cmn.Id), null);
+ UpdateMasterPageFile(new Template(cmn.Id), null);
}
//then kill the old file..
@@ -111,7 +123,7 @@ namespace umbraco.cms.businesslogic.template
}
// save the file in UTF-8
- System.IO.File.WriteAllText(template.MasterPageFile, masterPageContent, System.Text.Encoding.UTF8);
+ System.IO.File.WriteAllText(GetFilePath(template), masterPageContent, System.Text.Encoding.UTF8);
return masterPageContent;
}
@@ -131,9 +143,10 @@ namespace umbraco.cms.businesslogic.template
return masterPageContent;
}
- private static bool IsMasterPageSyntax(string code)
+ internal static bool IsMasterPageSyntax(string code)
{
- return code.Contains("<%@ Master") || code.Contains("
+ /// Returns the file path for the current template
+ ///
+ public string TemplateFilePath
+ {
+ get
+ {
+ switch (DetermineRenderingEngine(this))
+ {
+ case RenderingEngine.Mvc:
+ return ViewHelper.GetFilePath(this);
+ case RenderingEngine.WebForms:
+ return MasterPageHelper.GetFilePath(this);
+ default:
+ throw new ArgumentOutOfRangeException();
+ }
+ }
+ }
+
public static Hashtable TemplateAliases
{
get { return _templateAliases; }
@@ -134,18 +154,13 @@ namespace umbraco.cms.businesslogic.template
}
dr.Close();
- if (Umbraco.Core.Configuration.UmbracoSettings.DefaultRenderingEngine == RenderingEngine.Mvc && Template.HasView(this))
- _design = ViewHelper.GetViewFile(this);
+ if (Umbraco.Core.Configuration.UmbracoSettings.DefaultRenderingEngine == RenderingEngine.Mvc && ViewHelper.ViewExists(this))
+ _design = ViewHelper.GetFileContents(this);
else
- _design = MasterpageHelper.GetMasterpageFile(this);
+ _design = MasterPageHelper.GetFileContents(this);
}
-
- private bool isMasterPageSyntax(string code)
- {
- return code.Contains("<%@ Master") || code.Contains(" x.allowedTemplates.Select(t => t.Id).Contains(this.Id));
}
- public static Template MakeNew(string Name, BusinessLogic.User u, Template master)
- {
- Template t = MakeNew(Name, u);
- t.MasterTemplate = master.Id;
+ ///
+ /// This checks what the default rendering engine is set in config but then also ensures that there isn't already
+ /// a template that exists in the opposite rendering engine's template folder, then returns the appropriate
+ /// rendering engine to use.
+ ///
+ ///
+ /// If a template body is specified we'll check if it contains master page markup, if it does we'll auto assume its webforms
+ ///
+ ///
+ /// The reason this is required is because for example, if you have a master page file already existing under ~/masterpages/Blah.aspx
+ /// and then you go to create a template in the tree called Blah and the default rendering engine is MVC, it will create a Blah.cshtml
+ /// empty template in ~/Views. This means every page that is using Blah will go to MVC and render an empty page.
+ /// This is mostly related to installing packages since packages install file templates to the file system and then create the
+ /// templates in business logic. Without this, it could cause the wrong rendering engine to be used for a package.
+ ///
+ private static RenderingEngine DetermineRenderingEngine(Template t, string design = null)
+ {
+ var engine = Umbraco.Core.Configuration.UmbracoSettings.DefaultRenderingEngine;
- if (Umbraco.Core.Configuration.UmbracoSettings.DefaultRenderingEngine == RenderingEngine.Mvc)
- ViewHelper.CreateViewFile(t, true);
- else
- MasterpageHelper.CreateMasterpageFile(t, true);
-
-
+ if (!design.IsNullOrWhiteSpace() && MasterPageHelper.IsMasterPageSyntax(design))
+ {
+ //there is a design but its definitely a webforms design
+ return RenderingEngine.WebForms;
+ }
+
+ switch (engine)
+ {
+ case RenderingEngine.Mvc:
+ //check if there's a view in ~/masterpages
+ if (MasterPageHelper.MasterPageExists(t) && !ViewHelper.ViewExists(t))
+ {
+ //change this to webforms since there's already a file there for this template alias
+ engine = RenderingEngine.WebForms;
+ }
+ break;
+ case RenderingEngine.WebForms:
+ //check if there's a view in ~/views
+ if (ViewHelper.ViewExists(t) && !MasterPageHelper.MasterPageExists(t))
+ {
+ //change this to mvc since there's already a file there for this template alias
+ engine = RenderingEngine.Mvc;
+ }
+ break;
+ }
+ return engine;
+ }
+
+ public static Template MakeNew(string Name, BusinessLogic.User u, Template master, string design = null)
+ {
+ Template t = MakeNew(Name, u, design);
+ t.MasterTemplate = master.Id;
/*
if (UmbracoSettings.UseAspNetMasterPages)
@@ -346,7 +401,7 @@ namespace umbraco.cms.businesslogic.template
return t;
}
- public static Template MakeNew(string name, BusinessLogic.User u)
+ public static Template MakeNew(string name, BusinessLogic.User u, string design = null)
{
// CMSNode MakeNew(int parentId, Guid objectType, int userId, int level, string text, Guid uniqueID)
@@ -374,11 +429,21 @@ namespace umbraco.cms.businesslogic.template
NewEventArgs e = new NewEventArgs();
t.OnNew(e);
- if (Umbraco.Core.Configuration.UmbracoSettings.DefaultRenderingEngine == RenderingEngine.Mvc)
- t._design = ViewHelper.CreateViewFile(t);
- else
- t._design = MasterpageHelper.CreateMasterpageFile(t);
+ switch (DetermineRenderingEngine(t, design))
+ {
+ case RenderingEngine.Mvc:
+ ViewHelper.CreateViewFile(t, true);
+ break;
+ case RenderingEngine.WebForms:
+ MasterPageHelper.CreateMasterPage(t, true);
+ break;
+ }
+ //if a design is supplied ensure it is updated.
+ if (!design.IsNullOrWhiteSpace())
+ {
+ t.ImportDesign(design);
+ }
return t;
}
@@ -506,8 +571,8 @@ namespace umbraco.cms.businesslogic.template
if (System.IO.File.Exists(MasterPageFile))
System.IO.File.Delete(MasterPageFile);
- if (System.IO.File.Exists(Umbraco.Core.IO.IOHelper.MapPath(ViewHelper.ViewPath(this))))
- System.IO.File.Delete(Umbraco.Core.IO.IOHelper.MapPath(ViewHelper.ViewPath(this)));
+ if (System.IO.File.Exists(Umbraco.Core.IO.IOHelper.MapPath(ViewHelper.ViewPath(this.Alias))))
+ System.IO.File.Delete(Umbraco.Core.IO.IOHelper.MapPath(ViewHelper.ViewPath(this.Alias)));
FireAfterDelete(e);
}
@@ -578,17 +643,17 @@ namespace umbraco.cms.businesslogic.template
public string EnsureMasterPageSyntax(string masterPageContent)
{
- replaceElement(ref masterPageContent, "?UMBRACO_GETITEM", "umbraco:Item", true);
- replaceElement(ref masterPageContent, "?UMBRACO_GETITEM", "umbraco:Item", false);
+ ReplaceElement(ref masterPageContent, "?UMBRACO_GETITEM", "umbraco:Item", true);
+ ReplaceElement(ref masterPageContent, "?UMBRACO_GETITEM", "umbraco:Item", false);
// Parse the design for macros
- replaceElement(ref masterPageContent, "?UMBRACO_MACRO", "umbraco:Macro", true);
- replaceElement(ref masterPageContent, "?UMBRACO_MACRO", "umbraco:Macro", false);
+ ReplaceElement(ref masterPageContent, "?UMBRACO_MACRO", "umbraco:Macro", true);
+ ReplaceElement(ref masterPageContent, "?UMBRACO_MACRO", "umbraco:Macro", false);
// Parse the design for load childs
- masterPageContent = masterPageContent.Replace("", getAspNetMasterPageContentContainer()).Replace("", getAspNetMasterPageContentContainer());
+ masterPageContent = masterPageContent.Replace("", GetAspNetMasterPageContentContainer()).Replace("", GetAspNetMasterPageContentContainer());
// Parse the design for aspnet forms
- getAspNetMasterPageForm(ref masterPageContent);
+ GetAspNetMasterPageForm(ref masterPageContent);
masterPageContent = masterPageContent.Replace("?ASPNET_FORM>", "");
// Parse the design for aspnet heads
masterPageContent = masterPageContent.Replace("", String.Format("", Alias.Replace(" ", "")));
@@ -683,15 +748,9 @@ namespace umbraco.cms.businesslogic.template
File.WriteAllText(MasterPageFile, masterPageContent, System.Text.Encoding.UTF8);
* */
- }
+ }
- private string getMasterPageHeader()
- {
- return String.Format("<%@ Master Language=\"C#\" MasterPageFile=\"{0}\" AutoEventWireup=\"true\" %>",
- currentMasterTemplateFileName()) + Environment.NewLine;
- }
-
- private string currentMasterTemplateFileName()
+ private string CurrentMasterTemplateFileName()
{
if (MasterTemplate != 0)
return SystemDirectories.Masterpages + "/" + new Template(MasterTemplate).Alias.Replace(" ", "") + ".master";
@@ -699,9 +758,9 @@ namespace umbraco.cms.businesslogic.template
return UmbracoMasterTemplate;
}
- private void getAspNetMasterPageForm(ref string design)
+ private void GetAspNetMasterPageForm(ref string design)
{
- Match formElement = Regex.Match(design, getElementRegExp("?ASPNET_FORM", false), RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace);
+ Match formElement = Regex.Match(design, GetElementRegExp("?ASPNET_FORM", false), RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace);
if (formElement != null && formElement.Value != "")
{
string formReplace = String.Format("