Ensures that all property data is deleted for a doc type when it is being deleted, updates the ChangeDocType to not use the legacy EnsuredPage, updates the non-legacy EnsuredPage.ClientTools to support the legacy logic.

This commit is contained in:
Shannon
2016-01-26 12:13:53 +01:00
parent c33ad3eed7
commit 7d616cf937
5 changed files with 77 additions and 27 deletions

View File

@@ -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<PropertyDataDto>(SqlSyntax)
.InnerJoin<PropertyTypeDto>(SqlSyntax)
.On<PropertyDataDto, PropertyTypeDto>(SqlSyntax, dto => dto.PropertyTypeId, dto => dto.Id)
.InnerJoin<ContentTypeDto>(SqlSyntax)
.On<ContentTypeDto, PropertyTypeDto>(SqlSyntax, dto => dto.NodeId, dto => dto.ContentTypeId)
.Where<ContentTypeDto>(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);
}

View File

@@ -115,7 +115,7 @@
<asp:Button ID="ValidateAndSave" runat="server" OnClick="ValidateAndSave_Click" />
<em> <%= umbraco.ui.Text("or") %> </em>
</asp:PlaceHolder>
<a href="#" style="color: blue" onclick="UmbClientMgr.closeModalWindow()"><%=umbraco.ui.Text("general", "cancel", this.getUser())%></a>
<a href="#" style="color: blue" onclick="UmbClientMgr.closeModalWindow()"><%=umbraco.ui.Text("general", "cancel", Security.CurrentUser)%></a>
</p>
</asp:PlaceHolder>

View File

@@ -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<PropertyType> 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);

View File

@@ -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;
}
/// <summary>
/// Shows the dashboard for the given application
/// </summary>
/// <param name="app"></param>
/// <returns></returns>
public ClientTools ShowDashboard(string app)
/// <summary>
/// Reloads the content in the content frame if the specified URL is currently loaded
/// </summary>
/// <param name="url"></param>
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;
}
/// <summary>
/// Shows the dashboard for the given application
/// </summary>
/// <param name="app"></param>
/// <returns></returns>
public ClientTools ShowDashboard(string app)
{
return ChangeContentFrameUrl(SystemDirectories.Umbraco + string.Format("/dashboard.aspx?app={0}", app));
}

View File

@@ -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;
}