diff --git a/src/Umbraco.Core/Persistence/Repositories/ContentTypeRepository.cs b/src/Umbraco.Core/Persistence/Repositories/ContentTypeRepository.cs
index af2c1778c4..da6b0a6efb 100644
--- a/src/Umbraco.Core/Persistence/Repositories/ContentTypeRepository.cs
+++ b/src/Umbraco.Core/Persistence/Repositories/ContentTypeRepository.cs
@@ -182,6 +182,22 @@ namespace Umbraco.Core.Persistence.Repositories
PersistDeletedItem((IEntity)child);
}
+ //Before we call the base class methods to run all delete clauses, we need to first
+ // delete all of the property data associated with this document type. Normally this will
+ // be done in the ContentTypeService by deleting all associated content first, but in some cases
+ // like when we switch a document type, there is property data left over that is linked
+ // to the previous document type. So we need to ensure it's removed.
+ var sql = new Sql().Select("DISTINCT cmsPropertyData.propertytypeid")
+ .From(SqlSyntax)
+ .InnerJoin(SqlSyntax)
+ .On(SqlSyntax, dto => dto.PropertyTypeId, dto => dto.Id)
+ .InnerJoin(SqlSyntax)
+ .On(SqlSyntax, dto => dto.NodeId, dto => dto.ContentTypeId)
+ .Where(dto => dto.NodeId == entity.Id);
+
+ //Delete all cmsPropertyData where propertytypeid EXISTS in the subquery above
+ Database.Execute(SqlSyntax.GetDeleteSubquery("cmsPropertyData", "propertytypeid", sql));
+
base.PersistDeletedItem(entity);
}
diff --git a/src/Umbraco.Web.UI/umbraco/dialogs/ChangeDocType.aspx b/src/Umbraco.Web.UI/umbraco/dialogs/ChangeDocType.aspx
index d119637384..683299e5be 100644
--- a/src/Umbraco.Web.UI/umbraco/dialogs/ChangeDocType.aspx
+++ b/src/Umbraco.Web.UI/umbraco/dialogs/ChangeDocType.aspx
@@ -115,7 +115,7 @@
<%= umbraco.ui.Text("or") %>
- <%=umbraco.ui.Text("general", "cancel", this.getUser())%>
+ <%=umbraco.ui.Text("general", "cancel", Security.CurrentUser)%>
diff --git a/src/Umbraco.Web.UI/umbraco/dialogs/ChangeDocType.aspx.cs b/src/Umbraco.Web.UI/umbraco/dialogs/ChangeDocType.aspx.cs
index dc9e9b5ebc..f3769fbe1f 100644
--- a/src/Umbraco.Web.UI/umbraco/dialogs/ChangeDocType.aspx.cs
+++ b/src/Umbraco.Web.UI/umbraco/dialogs/ChangeDocType.aspx.cs
@@ -4,9 +4,9 @@ using System.Linq;
using System.Text;
using System.Web.UI;
using System.Web.UI.WebControls;
-using umbraco.BasePages;
using Umbraco.Core;
using Umbraco.Core.Models;
+using Umbraco.Web.UI.Pages;
namespace Umbraco.Web.UI.Umbraco.Dialogs
{
@@ -25,7 +25,7 @@ namespace Umbraco.Web.UI.Umbraco.Dialogs
protected void Page_Load(object sender, EventArgs e)
{
var contentNodeId = int.Parse(Request.QueryString["id"]);
- _content = ApplicationContext.Current.Services.ContentService.GetById(contentNodeId);
+ _content = Services.ContentService.GetById(contentNodeId);
LocalizeTexts();
@@ -65,12 +65,12 @@ namespace Umbraco.Web.UI.Umbraco.Dialogs
private bool PopulateListOfValidAlternateDocumentTypes()
{
// Start with all content types
- var documentTypes = ApplicationContext.Current.Services.ContentTypeService.GetAllContentTypes();
+ var documentTypes = Services.ContentTypeService.GetAllContentTypes().ToArray();
// Remove invalid ones from list of potential alternatives
- documentTypes = RemoveCurrentDocumentTypeFromAlternatives(documentTypes);
- documentTypes = RemoveInvalidByParentDocumentTypesFromAlternatives(documentTypes);
- documentTypes = RemoveInvalidByChildrenDocumentTypesFromAlternatives(documentTypes);
+ documentTypes = RemoveCurrentDocumentTypeFromAlternatives(documentTypes).ToArray();
+ documentTypes = RemoveInvalidByParentDocumentTypesFromAlternatives(documentTypes).ToArray();
+ documentTypes = RemoveInvalidByChildrenDocumentTypesFromAlternatives(documentTypes).ToArray();
// If we have at least one, bind to list and return true
if (documentTypes.Any())
@@ -102,7 +102,7 @@ namespace Umbraco.Web.UI.Umbraco.Dialogs
else
{
// Below root, so only include those allowed as sub-nodes for the parent
- var parentNode = ApplicationContext.Current.Services.ContentService.GetById(_content.ParentId);
+ var parentNode = Services.ContentService.GetById(_content.ParentId);
return documentTypes
.Where(x => parentNode.ContentType.AllowedContentTypes
.Select(y => y.Id.Value)
@@ -188,7 +188,7 @@ namespace Umbraco.Web.UI.Umbraco.Dialogs
private IContentType GetSelectedDocumentType()
{
- return ApplicationContext.Current.Services.ContentTypeService.GetContentType(int.Parse(NewDocumentTypeList.SelectedItem.Value));
+ return Services.ContentTypeService.GetContentType(int.Parse(NewDocumentTypeList.SelectedItem.Value));
}
private IEnumerable GetPropertiesOfContentType(IContentType contentType)
@@ -196,7 +196,7 @@ namespace Umbraco.Web.UI.Umbraco.Dialogs
var properties = contentType.PropertyTypes.ToList();
while (contentType.ParentId > -1 && contentType.CompositionAliases().Any())
{
- contentType = ApplicationContext.Current.Services.ContentTypeService.GetContentType(contentType.ParentId);
+ contentType = Services.ContentTypeService.GetContentType(contentType.ParentId);
properties.AddRange(contentType.PropertyTypes);
}
@@ -236,7 +236,7 @@ namespace Umbraco.Web.UI.Umbraco.Dialogs
if (NewTemplateList.SelectedItem != null)
{
var templateId = int.Parse(NewTemplateList.SelectedItem.Value);
- _content.Template = templateId > 0 ? ApplicationContext.Current.Services.FileService.GetTemplate(templateId) : null;
+ _content.Template = templateId > 0 ? Services.FileService.GetTemplate(templateId) : null;
}
// Set the property values
@@ -251,17 +251,17 @@ namespace Umbraco.Web.UI.Umbraco.Dialogs
// Save
var user = global::umbraco.BusinessLogic.User.GetCurrent();
- ApplicationContext.Current.Services.ContentService.Save(_content, user.Id);
+ Services.ContentService.Save(_content, user.Id);
// Publish if the content was already published
if (wasPublished)
{
- ApplicationContext.Current.Services.ContentService.Publish(_content, user.Id);
+ Services.ContentService.Publish(_content, user.Id);
}
// Sync the tree
ClientTools.SyncTree(_content.Path, true);
-
+
// Reload the page if the content was already being viewed
ClientTools.ReloadContentFrameUrlIfPathLoaded("/editContent.aspx?id=" + _content.Id);
diff --git a/src/Umbraco.Web/UI/Pages/ClientTools.cs b/src/Umbraco.Web/UI/Pages/ClientTools.cs
index fe7205451f..ebb778183d 100644
--- a/src/Umbraco.Web/UI/Pages/ClientTools.cs
+++ b/src/Umbraco.Web/UI/Pages/ClientTools.cs
@@ -6,6 +6,7 @@ using Umbraco.Core.IO;
using umbraco.BasePages;
using System.Web.UI;
using umbraco.BusinessLogic;
+using Umbraco.Core;
namespace Umbraco.Web.UI.Pages
{
@@ -47,7 +48,11 @@ namespace Umbraco.Web.UI.Pages
public static string ChangeContentFrameUrl(string url) {
return string.Format(ClientMgrScript + ".contentFrame('{0}');", url);
}
- public static string ChildNodeCreated = GetMainTree + ".childNodeCreated();";
+ public static string ReloadContentFrameUrlIfPathLoaded(string url)
+ {
+ return string.Format(ClientMgrScript + ".reloadContentFrameUrlIfPathLoaded('{0}');", url);
+ }
+ public static string ChildNodeCreated = GetMainTree + ".childNodeCreated();";
public static string SyncTree { get { return GetMainTree + ".syncTree('{0}', {1});"; } }
public static string ClearTreeCache { get { return GetMainTree + ".clearTreeCache();"; } }
public static string CopyNode { get { return GetMainTree + ".copyNode('{0}', '{1}');"; } }
@@ -146,23 +151,47 @@ namespace Umbraco.Web.UI.Pages
//don't load if there is no url
if (string.IsNullOrEmpty(url)) return this;
- if (url.StartsWith("/") && !url.StartsWith(IOHelper.ResolveUrl(SystemDirectories.Umbraco)))
- url = IOHelper.ResolveUrl(SystemDirectories.Umbraco) + "/" + url;
-
- if (url.Trim().StartsWith("~"))
- url = IOHelper.ResolveUrl(url);
+ url = EnsureUmbracoUrl(url);
RegisterClientScript(Scripts.ChangeContentFrameUrl(url));
return this;
}
- ///
- /// Shows the dashboard for the given application
- ///
- ///
- ///
- public ClientTools ShowDashboard(string app)
+ ///
+ /// Reloads the content in the content frame if the specified URL is currently loaded
+ ///
+ ///
+ public ClientTools ReloadContentFrameUrlIfPathLoaded(string url)
+ {
+ if (string.IsNullOrEmpty(url)) return this;
+
+ url = EnsureUmbracoUrl(url);
+
+ RegisterClientScript(Scripts.ReloadContentFrameUrlIfPathLoaded(url));
+
+ return this;
+ }
+
+ private string EnsureUmbracoUrl(string url)
+ {
+ if (url.StartsWith("/") && url.StartsWith(IOHelper.ResolveUrl(SystemDirectories.Umbraco)) == false)
+ {
+ url = IOHelper.ResolveUrl(SystemDirectories.Umbraco).EnsureEndsWith('/') + url;
+ }
+
+ if (url.Trim().StartsWith("~"))
+ url = IOHelper.ResolveUrl(url);
+
+ return url;
+ }
+
+ ///
+ /// Shows the dashboard for the given application
+ ///
+ ///
+ ///
+ public ClientTools ShowDashboard(string app)
{
return ChangeContentFrameUrl(SystemDirectories.Umbraco + string.Format("/dashboard.aspx?app={0}", app));
}
diff --git a/src/umbraco.businesslogic/BasePages/ClientTools.cs b/src/umbraco.businesslogic/BasePages/ClientTools.cs
index c164b086f1..627c4c1efb 100644
--- a/src/umbraco.businesslogic/BasePages/ClientTools.cs
+++ b/src/umbraco.businesslogic/BasePages/ClientTools.cs
@@ -6,6 +6,7 @@ using umbraco.BasePages;
using System.Web.UI;
using Umbraco.Core.IO;
using umbraco.BusinessLogic;
+using Umbraco.Core;
namespace umbraco.BasePages
{
@@ -180,8 +181,12 @@ namespace umbraco.BasePages
{
if (url.StartsWith("/") && !url.StartsWith(IOHelper.ResolveUrl(SystemDirectories.Umbraco)))
{
- url = IOHelper.ResolveUrl(SystemDirectories.Umbraco) + url;
+ url = IOHelper.ResolveUrl(SystemDirectories.Umbraco).EnsureEndsWith('/') + url;
}
+
+ if (url.Trim().StartsWith("~"))
+ url = IOHelper.ResolveUrl(url);
+
return url;
}