From 86ce48ddc860ac8c01e9d87be5dafef70200c77b Mon Sep 17 00:00:00 2001 From: Shannon Date: Thu, 20 Jun 2013 15:34:57 +1000 Subject: [PATCH] Fixes: #U4-2312 - Moving content with the new API (and in the old api when calling library.UpdateDocumentCache(p.Id)) The document is actually moved properly in the content XML structure without republishing it and then rebuilding the entire XML structure, it just does it inline. Have also updated MoveAndCopy.aspx dialog to use the new API which now saves on about 20+ queries that were not needed. Also updated the MoveAndCopy dialog to have the correct code behind structure. --- src/Umbraco.Core/Models/ContentExtensions.cs | 46 +++ src/Umbraco.Core/Umbraco.Core.csproj | 1 - src/Umbraco.Core/Xml/XmlNodeExtensions.cs | 51 ---- src/Umbraco.Core/XmlExtensions.cs | 43 +++ src/Umbraco.Web.UI/Umbraco.Web.UI.csproj | 11 +- .../config/ClientDependency.config | 2 +- src/Umbraco.Web.UI/config/Dashboard.config | 8 + .../umbraco/dialogs/MoveOrCopy.aspx.cs | 11 + .../dialogs/MoveOrCopy.aspx.designer.cs | 15 + .../umbraco/dialogs/moveOrCopy.aspx | 2 +- .../DefaultPublishedContentStore.cs | 1 + src/Umbraco.Web/Umbraco.Web.csproj | 11 +- .../umbraco.presentation/content.cs | 17 ++ .../umbraco/dialogs/moveOrCopy.aspx | 91 ------ .../umbraco/dialogs/moveOrCopy.aspx.cs | 277 +++++++++++++----- .../dialogs/moveOrCopy.aspx.designer.cs | 141 --------- .../BasePages/BasePage.cs | 25 ++ 17 files changed, 386 insertions(+), 367 deletions(-) delete mode 100644 src/Umbraco.Core/Xml/XmlNodeExtensions.cs create mode 100644 src/Umbraco.Web.UI/umbraco/dialogs/MoveOrCopy.aspx.cs create mode 100644 src/Umbraco.Web.UI/umbraco/dialogs/MoveOrCopy.aspx.designer.cs delete mode 100644 src/Umbraco.Web/umbraco.presentation/umbraco/dialogs/moveOrCopy.aspx delete mode 100644 src/Umbraco.Web/umbraco.presentation/umbraco/dialogs/moveOrCopy.aspx.designer.cs diff --git a/src/Umbraco.Core/Models/ContentExtensions.cs b/src/Umbraco.Core/Models/ContentExtensions.cs index dfc4f35967..707fe28b7f 100644 --- a/src/Umbraco.Core/Models/ContentExtensions.cs +++ b/src/Umbraco.Core/Models/ContentExtensions.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Drawing; using System.Drawing.Drawing2D; using System.Drawing.Imaging; @@ -14,11 +15,56 @@ using Umbraco.Core.Media; using Umbraco.Core.Models.Membership; using Umbraco.Core.Persistence; using Umbraco.Core.Persistence.UnitOfWork; +using Umbraco.Core.Services; namespace Umbraco.Core.Models { public static class ContentExtensions { + /// + /// Checks if the IContentBase has children + /// + /// + /// + /// + /// + /// This is a bit of a hack because we need to type check! + /// + internal static bool HasChildren(IContentBase content, ServiceContext services) + { + if (content is IContent) + { + return services.ContentService.HasChildren(content.Id); + } + if (content is IMedia) + { + return services.MediaService.HasChildren(content.Id); + } + return false; + } + + /// + /// Returns the children for the content base item + /// + /// + /// + /// + /// + /// This is a bit of a hack because we need to type check! + /// + internal static IEnumerable Children(IContentBase content, ServiceContext services) + { + if (content is IContent) + { + return services.ContentService.GetChildren(content.Id); + } + if (content is IMedia) + { + return services.MediaService.GetChildren(content.Id); + } + return null; + } + /// /// Set property values by alias with an annonymous object /// diff --git a/src/Umbraco.Core/Umbraco.Core.csproj b/src/Umbraco.Core/Umbraco.Core.csproj index 9d8776e8ba..14405192e5 100644 --- a/src/Umbraco.Core/Umbraco.Core.csproj +++ b/src/Umbraco.Core/Umbraco.Core.csproj @@ -696,7 +696,6 @@ - diff --git a/src/Umbraco.Core/Xml/XmlNodeExtensions.cs b/src/Umbraco.Core/Xml/XmlNodeExtensions.cs deleted file mode 100644 index 53a7ef08db..0000000000 --- a/src/Umbraco.Core/Xml/XmlNodeExtensions.cs +++ /dev/null @@ -1,51 +0,0 @@ -using System.Collections.Generic; -using System.Linq; -using System.Xml; -using System.Xml.XPath; - -// source: mvpxml.codeplex.com - -namespace Umbraco.Core.Xml -{ - internal static class XmlNodeExtensions - { - static XPathNodeIterator Select(string expression, XPathNavigator source, params XPathVariable[] variables) - { - var expr = source.Compile(expression); - var context = new DynamicContext(); - foreach (var variable in variables) - context.AddVariable(variable.Name, variable.Value); - expr.SetContext(context); - return source.Select(expr); - } - - public static XmlNodeList SelectNodes(this XmlNode source, string expression, IEnumerable variables) - { - var av = variables == null ? null : variables.ToArray(); - return SelectNodes(source, expression, av); - } - - public static XmlNodeList SelectNodes(this XmlNode source, string expression, params XPathVariable[] variables) - { - if (variables == null || variables.Length == 0 || variables[0] == null) - return source.SelectNodes(expression); - - var iterator = Select(expression, source.CreateNavigator(), variables); - return XmlNodeListFactory.CreateNodeList(iterator); - } - - public static XmlNode SelectSingleNode(this XmlNode source, string expression, IEnumerable variables) - { - var av = variables == null ? null : variables.ToArray(); - return SelectSingleNode(source, expression, av); - } - - public static XmlNode SelectSingleNode(this XmlNode source, string expression, params XPathVariable[] variables) - { - if (variables == null || variables.Length == 0 || variables[0] == null) - return source.SelectSingleNode(expression); - - return SelectNodes(source, expression, variables).Cast().FirstOrDefault(); - } - } -} diff --git a/src/Umbraco.Core/XmlExtensions.cs b/src/Umbraco.Core/XmlExtensions.cs index fee2aba0e5..ec53f0521a 100644 --- a/src/Umbraco.Core/XmlExtensions.cs +++ b/src/Umbraco.Core/XmlExtensions.cs @@ -1,6 +1,10 @@ using System; +using System.Collections.Generic; +using System.Linq; using System.Xml; using System.Xml.Linq; +using System.Xml.XPath; +using Umbraco.Core.Xml; namespace Umbraco.Core { @@ -9,6 +13,45 @@ namespace Umbraco.Core /// internal static class XmlExtensions { + static XPathNodeIterator Select(string expression, XPathNavigator source, params XPathVariable[] variables) + { + var expr = source.Compile(expression); + var context = new DynamicContext(); + foreach (var variable in variables) + context.AddVariable(variable.Name, variable.Value); + expr.SetContext(context); + return source.Select(expr); + } + + public static XmlNodeList SelectNodes(this XmlNode source, string expression, IEnumerable variables) + { + var av = variables == null ? null : variables.ToArray(); + return SelectNodes(source, expression, av); + } + + public static XmlNodeList SelectNodes(this XmlNode source, string expression, params XPathVariable[] variables) + { + if (variables == null || variables.Length == 0 || variables[0] == null) + return source.SelectNodes(expression); + + var iterator = Select(expression, source.CreateNavigator(), variables); + return XmlNodeListFactory.CreateNodeList(iterator); + } + + public static XmlNode SelectSingleNode(this XmlNode source, string expression, IEnumerable variables) + { + var av = variables == null ? null : variables.ToArray(); + return SelectSingleNode(source, expression, av); + } + + public static XmlNode SelectSingleNode(this XmlNode source, string expression, params XPathVariable[] variables) + { + if (variables == null || variables.Length == 0 || variables[0] == null) + return source.SelectSingleNode(expression); + + return SelectNodes(source, expression, variables).Cast().FirstOrDefault(); + } + /// /// Converts from an XDocument to an XmlDocument /// diff --git a/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj b/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj index b1d094a1b3..de66d4479c 100644 --- a/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj +++ b/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj @@ -334,6 +334,13 @@ EditMacro.aspx ASPXCodeBehind + + moveOrCopy.aspx + ASPXCodeBehind + + + moveOrCopy.aspx + sort.aspx ASPXCodeBehind @@ -2353,7 +2360,9 @@ Designer - + + Designer + Designer diff --git a/src/Umbraco.Web.UI/config/ClientDependency.config b/src/Umbraco.Web.UI/config/ClientDependency.config index 936b7e6332..99957f0fa8 100644 --- a/src/Umbraco.Web.UI/config/ClientDependency.config +++ b/src/Umbraco.Web.UI/config/ClientDependency.config @@ -10,7 +10,7 @@ NOTES: * Compression/Combination/Minification is not enabled unless debug="false" is specified on the 'compiliation' element in the web.config * A new version will invalidate both client and server cache and create new persisted files --> - + diff --git a/src/Umbraco.Web.UI/config/Dashboard.config b/src/Umbraco.Web.UI/config/Dashboard.config index e4c09f3efd..93f2656635 100644 --- a/src/Umbraco.Web.UI/config/Dashboard.config +++ b/src/Umbraco.Web.UI/config/Dashboard.config @@ -100,4 +100,12 @@ /umbraco/plugins/uGoLive/Dashboard.ascx +
+ + developer + + + /UserControls/DashboardTest.ascx + +
\ No newline at end of file diff --git a/src/Umbraco.Web.UI/umbraco/dialogs/MoveOrCopy.aspx.cs b/src/Umbraco.Web.UI/umbraco/dialogs/MoveOrCopy.aspx.cs new file mode 100644 index 0000000000..b5af29be21 --- /dev/null +++ b/src/Umbraco.Web.UI/umbraco/dialogs/MoveOrCopy.aspx.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; + +namespace Umbraco.Web.UI.Umbraco.Dialogs +{ + public partial class MoveOrCopy : global::umbraco.dialogs.moveOrCopy + { + } +} \ No newline at end of file diff --git a/src/Umbraco.Web.UI/umbraco/dialogs/MoveOrCopy.aspx.designer.cs b/src/Umbraco.Web.UI/umbraco/dialogs/MoveOrCopy.aspx.designer.cs new file mode 100644 index 0000000000..7b00ec6d41 --- /dev/null +++ b/src/Umbraco.Web.UI/umbraco/dialogs/MoveOrCopy.aspx.designer.cs @@ -0,0 +1,15 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace Umbraco.Web.UI.Umbraco.Dialogs { + + + public partial class MoveOrCopy { + } +} diff --git a/src/Umbraco.Web.UI/umbraco/dialogs/moveOrCopy.aspx b/src/Umbraco.Web.UI/umbraco/dialogs/moveOrCopy.aspx index 219b46d688..ea5cef2a8a 100644 --- a/src/Umbraco.Web.UI/umbraco/dialogs/moveOrCopy.aspx +++ b/src/Umbraco.Web.UI/umbraco/dialogs/moveOrCopy.aspx @@ -1,4 +1,4 @@ -<%@ Page Language="c#" CodeBehind="moveOrCopy.aspx.cs" MasterPageFile="../masterpages/umbracoDialog.Master" AutoEventWireup="True" Inherits="umbraco.dialogs.moveOrCopy" %> +<%@ Page Language="c#" CodeBehind="moveOrCopy.aspx.cs" MasterPageFile="../masterpages/umbracoDialog.Master" AutoEventWireup="True" Inherits="Umbraco.Web.UI.Umbraco.Dialogs.MoveOrCopy" %> <%@ Register TagPrefix="umb" Namespace="ClientDependency.Core.Controls" Assembly="ClientDependency.Core" %> <%@ Register TagPrefix="cc1" Namespace="umbraco.uicontrols" Assembly="controls" %> <%@ Register Src="../controls/Tree/TreeControl.ascx" TagName="TreeControl" TagPrefix="umbraco" %> diff --git a/src/Umbraco.Web/DefaultPublishedContentStore.cs b/src/Umbraco.Web/DefaultPublishedContentStore.cs index 5a86d3c6c6..d8c7172101 100644 --- a/src/Umbraco.Web/DefaultPublishedContentStore.cs +++ b/src/Umbraco.Web/DefaultPublishedContentStore.cs @@ -5,6 +5,7 @@ using System.Xml; using System.Xml.Linq; using Umbraco.Core.Models; using Umbraco.Core.Xml; +using Umbraco.Core; using Umbraco.Web.Routing; using umbraco; using umbraco.NodeFactory; diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj index ea1c65c1bb..bf55cc31d4 100644 --- a/src/Umbraco.Web/Umbraco.Web.csproj +++ b/src/Umbraco.Web/Umbraco.Web.csproj @@ -367,6 +367,9 @@ ASPXCodeBehind + + ASPXCodeBehind + ASPXCodeBehind @@ -1247,13 +1250,6 @@ insertTable.aspx - - moveOrCopy.aspx - ASPXCodeBehind - - - moveOrCopy.aspx - notifications.aspx ASPXCodeBehind @@ -1920,7 +1916,6 @@ - diff --git a/src/Umbraco.Web/umbraco.presentation/content.cs b/src/Umbraco.Web/umbraco.presentation/content.cs index 429418afef..3e09f83e8b 100644 --- a/src/Umbraco.Web/umbraco.presentation/content.cs +++ b/src/Umbraco.Web/umbraco.presentation/content.cs @@ -415,7 +415,24 @@ namespace umbraco } else { + //check the current parent id + var currParentId = currentNode.AttributeValue("parentID"); + + //update the node with it's new values TransferValuesFromDocumentXmlToPublishedXml(docNode, currentNode); + + //If the node is being moved we also need to ensure that it exists under the new parent! + // http://issues.umbraco.org/issue/U4-2312 + // we were never checking this before and instead simply changing the parentId value but not + // changing the actual parent. + + //check the new parent + if (currParentId != currentNode.AttributeValue("parentID")) + { + //ok, we've actually got to move the node + parentNode.AppendChild(currentNode); + } + } // TODO: Update with new schema! diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/dialogs/moveOrCopy.aspx b/src/Umbraco.Web/umbraco.presentation/umbraco/dialogs/moveOrCopy.aspx deleted file mode 100644 index 219b46d688..0000000000 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/dialogs/moveOrCopy.aspx +++ /dev/null @@ -1,91 +0,0 @@ -<%@ Page Language="c#" CodeBehind="moveOrCopy.aspx.cs" MasterPageFile="../masterpages/umbracoDialog.Master" AutoEventWireup="True" Inherits="umbraco.dialogs.moveOrCopy" %> -<%@ Register TagPrefix="umb" Namespace="ClientDependency.Core.Controls" Assembly="ClientDependency.Core" %> -<%@ Register TagPrefix="cc1" Namespace="umbraco.uicontrols" Assembly="controls" %> -<%@ Register Src="../controls/Tree/TreeControl.ascx" TagName="TreeControl" TagPrefix="umbraco" %> - - - - - - - - - - - - - - - - - - - - - - - -
-

- <%= umbraco.ui.Text("moveOrCopy","noNodeSelected") %>

-
-
- - - - - - * - - - -

- -   - <%=umbraco.ui.Text("general", "or", this.getUser())%>   - <%=umbraco.ui.Text("general", "cancel", this.getUser())%> -

-
-
diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/dialogs/moveOrCopy.aspx.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/dialogs/moveOrCopy.aspx.cs index b27ce9dbaf..2ec600b05a 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/dialogs/moveOrCopy.aspx.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/dialogs/moveOrCopy.aspx.cs @@ -1,17 +1,19 @@ -using System; +using System; using System.Collections; using System.Web.UI; using System.Web.UI.WebControls; using System.Xml; +using Umbraco.Core; using Umbraco.Core.IO; +using Umbraco.Core.Models; using umbraco.BasePages; using umbraco.cms.businesslogic.web; using umbraco.presentation; -using umbraco.cms.businesslogic.media; using System.Linq; using umbraco.cms.businesslogic; using umbraco.cms.presentation.user; using umbraco.interfaces; +using Umbraco.Web; namespace umbraco.dialogs { @@ -22,13 +24,13 @@ namespace umbraco.dialogs { protected override void OnInit(EventArgs e) - { + { CurrentApp = Request["app"]; base.OnInit(e); } - protected void Page_Load(object sender, EventArgs e) + protected void Page_Load(object sender, EventArgs e) { JTree.DataBind(); @@ -48,7 +50,7 @@ namespace umbraco.dialogs ok.Text = ui.Text("general", "ok", this.getUser()); ok.Attributes.Add("style", "width: 60px"); - var documentType = new DocumentType(int.Parse(helper.Request("id"))); + var documentType = new DocumentType(int.Parse(Request.GetItemAsString("id"))); //Load master types... masterType.Attributes.Add("style", "width: 350px;"); @@ -72,81 +74,74 @@ namespace umbraco.dialogs pane_settings.Visible = false; // Caption and properies on BUTTON - ok.Text = ui.Text("general", "ok", this.getUser()); + ok.Text = ui.Text("general", "ok", getUser()); ok.Attributes.Add("style", "width: 60px"); ok.Attributes.Add("disabled", "true"); - var cmsNode = new CMSNode(int.Parse(helper.Request("id"))); + IContentBase currContent; + if (CurrentApp == "content") + { + currContent = Services.ContentService.GetById(Request.GetItemAs("id")); + } + else + { + currContent = Services.MediaService.GetById(Request.GetItemAs("id")); + } var validAction = true; - if (CurrentApp == "content" && cmsNode.HasChildren) - validAction = ValidAction(helper.Request("mode") == "cut" ? 'M' : 'O'); - - - if (helper.Request("mode") == "cut") + if (CurrentApp == "content" && Umbraco.Core.Models.ContentExtensions.HasChildren(currContent, Services)) { - pane_form.Text = ui.Text("moveOrCopy", "moveTo", cmsNode.Text, base.getUser()); + validAction = ValidAction(currContent, Request.GetItemAsString("mode") == "cut" ? 'M' : 'O'); + } + + if (Request.GetItemAsString("mode") == "cut") + { + pane_form.Text = ui.Text("moveOrCopy", "moveTo", currContent.Name, getUser()); pp_relate.Visible = false; } else { - pane_form.Text = ui.Text("moveOrCopy", "copyTo", cmsNode.Text, base.getUser()); + pane_form.Text = ui.Text("moveOrCopy", "copyTo", currContent.Name, getUser()); pp_relate.Visible = true; } if (validAction == false) { - ScriptManager.RegisterStartupScript(this, this.GetType(), "notvalid", "notValid();", true); + ScriptManager.RegisterStartupScript(this, GetType(), "notvalid", "notValid();", true); } } } } - private bool ValidAction(char actionLetter) + private bool ValidAction(IContentBase cmsNode, char actionLetter) { - var cmsNode = new CMSNode(int.Parse(helper.Request("id"))); var currentAction = BusinessLogic.Actions.Action.GetPermissionAssignable().First(a => a.Letter == actionLetter); return CheckPermissions(cmsNode, currentAction); } - private bool CheckPermissions(CMSNode node, IAction currentAction) - { + private bool CheckPermissions(IContentBase node, IAction currentAction) + { var currUserPermissions = new UserPermissions(CurrentUser); var lstCurrUserActions = currUserPermissions.GetExistingNodePermission(node.Id); if (lstCurrUserActions.Contains(currentAction) == false) return false; - if (node.HasChildren) + + if (Umbraco.Core.Models.ContentExtensions.HasChildren(node, Services)) { - foreach (CMSNode child in node.Children) - if (CheckPermissions(child, currentAction) == false) - return false; + return Umbraco.Core.Models.ContentExtensions.Children(node, Services) + .All(child => CheckPermissions(child, currentAction)); } return true; } - //PPH moving multiple nodes and publishing them aswell. - private void handleChildNodes(cms.businesslogic.web.Document document) - { - //store children array here because iterating over an Array object is very inneficient. - var children = document.Children; - foreach (Document child in children.Where(child => child.Published)) - { - child.Publish(new BusinessLogic.User(0)); - - //using library.publish to support load balancing. - library.UpdateDocumentCache(child.Id); - if (child.HasChildren) - handleChildNodes(child); - } - } //PPH Handle doctype copies.. private void HandleDocumentTypeCopy() { - var documentType = new DocumentType(int.Parse(helper.Request("id"))); + var documentType = new DocumentType(int.Parse(Request.GetItemAsString("id"))); //Documentype exists.. create new doc type... var alias = rename.Text; @@ -200,53 +195,66 @@ namespace umbraco.dialogs public void HandleMoveOrCopy(object sender, EventArgs e) { if (CurrentApp == "settings") - HandleDocumentTypeCopy(); - else + HandleDocumentTypeCopy(); + else HandleDocumentMoveOrCopy(); - } + } protected override void OnPreRender(EventArgs e) { - base.OnPreRender(e); - ScriptManager.GetCurrent(Page).Services.Add(new ServiceReference("../webservices/cmsnode.asmx")); - ScriptManager.GetCurrent(Page).Services.Add(new ServiceReference("../webservices/legacyAjaxCalls.asmx")); - } + base.OnPreRender(e); + ScriptManager.GetCurrent(Page).Services.Add(new ServiceReference("../webservices/cmsnode.asmx")); + ScriptManager.GetCurrent(Page).Services.Add(new ServiceReference("../webservices/legacyAjaxCalls.asmx")); + } private void HandleDocumentMoveOrCopy() { - if (helper.Request("copyTo") != "" && helper.Request("id") != "") + if (Request.GetItemAsString("copyTo") != "" && Request.GetItemAsString("id") != "") { // Check if the current node is allowed at new position var nodeAllowed = false; - var currentNode = new cms.businesslogic.Content(int.Parse(helper.Request("id"))); - - var newNode = new cms.businesslogic.Content(int.Parse(helper.Request("copyTo"))); + IContentBase currContent; + IContentBase parentContent; + IContentTypeBase parentContentType; + if (CurrentApp == "content") + { + currContent = Services.ContentService.GetById(Request.GetItemAs("id")); + parentContent = Services.ContentService.GetById(Request.GetItemAs("copyTo")); + parentContentType = Services.ContentTypeService.GetContentType(parentContent.ContentTypeId); + } + else + { + currContent = Services.MediaService.GetById(Request.GetItemAs("id")); + parentContent = Services.MediaService.GetById(Request.GetItemAs("copyTo")); + parentContentType = Services.ContentTypeService.GetMediaType(parentContent.ContentTypeId); + } // Check on contenttypes - if (int.Parse(helper.Request("copyTo")) == -1) + if (Request.GetItemAs("copyTo") == -1) { nodeAllowed = true; } else { - if (newNode.ContentType.AllowedChildContentTypeIDs.Where(c => c == currentNode.ContentType.Id).Any()) + var allowedChildContentTypeIds = parentContentType.AllowedContentTypes.Select(x => x.Id).ToArray(); + if (allowedChildContentTypeIds.Any(x => x.Value == currContent.ContentTypeId)) { nodeAllowed = true; } if (nodeAllowed == false) { - feedback.Text = ui.Text("moveOrCopy", "notAllowedByContentType", base.getUser()); + feedback.Text = ui.Text("moveOrCopy", "notAllowedByContentType", getUser()); feedback.type = uicontrols.Feedback.feedbacktype.error; } else { // Check on paths - if ((string.Format(",{0},", newNode.Path)).IndexOf(string.Format(",{0},", currentNode.Id)) > -1) + if ((string.Format(",{0},", parentContent.Path)).IndexOf(string.Format(",{0},", currContent.Id)) > -1) { nodeAllowed = false; - feedback.Text = ui.Text("moveOrCopy", "notAllowedByPath", base.getUser()); + feedback.Text = ui.Text("moveOrCopy", "notAllowedByPath", getUser()); feedback.type = uicontrols.Feedback.feedbacktype.error; } } @@ -258,46 +266,171 @@ namespace umbraco.dialogs pane_form_notice.Visible = false; panel_buttons.Visible = false; - var newNodeCaption = newNode.Id == -1 ? ui.Text(CurrentApp) : newNode.Text; + var newNodeCaption = Request.GetItemAs("copyTo") == -1 + ? ui.Text(CurrentApp) + : parentContent.Name; - string[] nodes = { currentNode.Text, newNodeCaption }; + string[] nodes = { currContent.Name, newNodeCaption }; if (Request["mode"] == "cut") { if (CurrentApp == "content") { - //PPH changed this to document instead of cmsNode to handle republishing. - var documentId = int.Parse(helper.Request("id")); - var document = new Document(documentId); - document.Move(int.Parse(helper.Request("copyTo"))); - library.RefreshContent(); + Services.ContentService.Move((IContent)currContent, Request.GetItemAs("copyTo"), getUser().Id); } else { - var media = new Media(int.Parse(UmbracoContext.Current.Request["id"])); - media.Move(int.Parse(UmbracoContext.Current.Request["copyTo"])); - media = new Media(int.Parse(UmbracoContext.Current.Request["id"])); - media.XmlGenerate(new XmlDocument()); - library.ClearLibraryCacheForMedia(media.Id); + Services.MediaService.Move((IMedia)currContent, Request.GetItemAs("copyTo"), getUser().Id); + library.ClearLibraryCacheForMedia(currContent.Id); } feedback.Text = ui.Text("moveOrCopy", "moveDone", nodes, getUser()) + "

" + ui.Text("closeThisWindow") + ""; feedback.type = uicontrols.Feedback.feedbacktype.success; // refresh tree - ClientTools.MoveNode(currentNode.Id.ToString(), newNode.Path); + ClientTools.MoveNode(currContent.Id.ToString(), parentContent.Path); } else { - var document = new Document(int.Parse(helper.Request("id"))); - document.Copy(int.Parse(helper.Request("copyTo")), this.getUser(), RelateDocuments.Checked); - feedback.Text = ui.Text("moveOrCopy", "copyDone", nodes, base.getUser()) + "

" + ui.Text("closeThisWindow") + ""; + //NOTE: We ONLY support Copy on content not media for some reason. + + Services.ContentService.Copy((IContent)currContent, Request.GetItemAs("copyTo"), RelateDocuments.Checked, getUser().Id); + + feedback.Text = ui.Text("moveOrCopy", "copyDone", nodes, getUser()) + "

" + ui.Text("closeThisWindow") + ""; feedback.type = uicontrols.Feedback.feedbacktype.success; - ClientTools.CopyNode(currentNode.Id.ToString(), newNode.Path); + + // refresh tree + ClientTools.CopyNode(currContent.Id.ToString(), parentContent.Path); } } } } + ///

+ /// JsInclude1 control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::ClientDependency.Core.Controls.JsInclude JsInclude1; + + /// + /// feedback control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::umbraco.uicontrols.Feedback feedback; + + /// + /// pane_form control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::umbraco.uicontrols.Pane pane_form; + + /// + /// JTree control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::umbraco.controls.Tree.TreeControl JTree; + + /// + /// pp_relate control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::umbraco.uicontrols.PropertyPanel pp_relate; + + /// + /// RelateDocuments control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.WebControls.CheckBox RelateDocuments; + + /// + /// pane_form_notice control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.WebControls.PlaceHolder pane_form_notice; + + /// + /// pane_settings control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::umbraco.uicontrols.Pane pane_settings; + + /// + /// PropertyPanel1 control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::umbraco.uicontrols.PropertyPanel PropertyPanel1; + + /// + /// masterType control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.WebControls.ListBox masterType; + + /// + /// rename control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.WebControls.TextBox rename; + + /// + /// RequiredFieldValidator1 control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator1; + + /// + /// panel_buttons control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.WebControls.Panel panel_buttons; + + /// + /// ok control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.WebControls.Button ok; + } } diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/dialogs/moveOrCopy.aspx.designer.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/dialogs/moveOrCopy.aspx.designer.cs deleted file mode 100644 index f7c669d1ea..0000000000 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/dialogs/moveOrCopy.aspx.designer.cs +++ /dev/null @@ -1,141 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -namespace umbraco.dialogs { - - - public partial class moveOrCopy { - - /// - /// JsInclude1 control. - /// - /// - /// Auto-generated field. - /// To modify move field declaration from designer file to code-behind file. - /// - protected global::ClientDependency.Core.Controls.JsInclude JsInclude1; - - /// - /// feedback control. - /// - /// - /// Auto-generated field. - /// To modify move field declaration from designer file to code-behind file. - /// - protected global::umbraco.uicontrols.Feedback feedback; - - /// - /// pane_form control. - /// - /// - /// Auto-generated field. - /// To modify move field declaration from designer file to code-behind file. - /// - protected global::umbraco.uicontrols.Pane pane_form; - - /// - /// JTree control. - /// - /// - /// Auto-generated field. - /// To modify move field declaration from designer file to code-behind file. - /// - protected global::umbraco.controls.Tree.TreeControl JTree; - - /// - /// pp_relate control. - /// - /// - /// Auto-generated field. - /// To modify move field declaration from designer file to code-behind file. - /// - protected global::umbraco.uicontrols.PropertyPanel pp_relate; - - /// - /// RelateDocuments control. - /// - /// - /// Auto-generated field. - /// To modify move field declaration from designer file to code-behind file. - /// - protected global::System.Web.UI.WebControls.CheckBox RelateDocuments; - - /// - /// pane_form_notice control. - /// - /// - /// Auto-generated field. - /// To modify move field declaration from designer file to code-behind file. - /// - protected global::System.Web.UI.WebControls.PlaceHolder pane_form_notice; - - /// - /// pane_settings control. - /// - /// - /// Auto-generated field. - /// To modify move field declaration from designer file to code-behind file. - /// - protected global::umbraco.uicontrols.Pane pane_settings; - - /// - /// PropertyPanel1 control. - /// - /// - /// Auto-generated field. - /// To modify move field declaration from designer file to code-behind file. - /// - protected global::umbraco.uicontrols.PropertyPanel PropertyPanel1; - - /// - /// masterType control. - /// - /// - /// Auto-generated field. - /// To modify move field declaration from designer file to code-behind file. - /// - protected global::System.Web.UI.WebControls.ListBox masterType; - - /// - /// rename control. - /// - /// - /// Auto-generated field. - /// To modify move field declaration from designer file to code-behind file. - /// - protected global::System.Web.UI.WebControls.TextBox rename; - - /// - /// RequiredFieldValidator1 control. - /// - /// - /// Auto-generated field. - /// To modify move field declaration from designer file to code-behind file. - /// - protected global::System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator1; - - /// - /// panel_buttons control. - /// - /// - /// Auto-generated field. - /// To modify move field declaration from designer file to code-behind file. - /// - protected global::System.Web.UI.WebControls.Panel panel_buttons; - - /// - /// ok control. - /// - /// - /// Auto-generated field. - /// To modify move field declaration from designer file to code-behind file. - /// - protected global::System.Web.UI.WebControls.Button ok; - } -} diff --git a/src/umbraco.businesslogic/BasePages/BasePage.cs b/src/umbraco.businesslogic/BasePages/BasePage.cs index 25a09f9b25..78b321fa46 100644 --- a/src/umbraco.businesslogic/BasePages/BasePage.cs +++ b/src/umbraco.businesslogic/BasePages/BasePage.cs @@ -7,6 +7,7 @@ using System.Web.Routing; using System.Web.Security; using Umbraco.Core.IO; using Umbraco.Core.Logging; +using Umbraco.Core.Services; using umbraco.BusinessLogic; using umbraco.DataLayer; using Umbraco.Core; @@ -53,6 +54,30 @@ namespace umbraco.BasePages get { return umbraco.BusinessLogic.Application.SqlHelper; } } + /// + /// Returns the current ApplicationContext + /// + public ApplicationContext ApplicationContext + { + get { return ApplicationContext.Current; } + } + + /// + /// Returns a ServiceContext + /// + public ServiceContext Services + { + get { return ApplicationContext.Services; } + } + + /// + /// Returns a DatabaseContext + /// + public DatabaseContext DatabaseContext + { + get { return ApplicationContext.DatabaseContext; } + } + /// /// Initializes a new instance of the class. ///