private void HandleDocumentMoveOrCopy() { if (Request.GetItemAsString("copyTo") != "" && Request.GetItemAsString("id") != "") { // Check if the current node is allowed at new position var nodeAllowed = false; IContentBase currContent; IContentBase parentContent = null; IContentTypeBase parentContentType = null; if (CurrentApp == "content") { currContent = Services.ContentService.GetById(Request.GetItemAs <int>("id")); if (Request.GetItemAs <int>("copyTo") != -1) { parentContent = Services.ContentService.GetById(Request.GetItemAs <int>("copyTo")); if (parentContent != null) { parentContentType = Services.ContentTypeService.GetContentType(parentContent.ContentTypeId); } } } else { currContent = Services.MediaService.GetById(Request.GetItemAs <int>("id")); if (Request.GetItemAs <int>("copyTo") != -1) { parentContent = Services.MediaService.GetById(Request.GetItemAs <int>("copyTo")); if (parentContent != null) { parentContentType = Services.ContentTypeService.GetMediaType(parentContent.ContentTypeId); } } } // Check on contenttypes if (parentContentType == null) { //check if this is allowed at root IContentTypeBase currContentType; if (CurrentApp == "content") { currContentType = Services.ContentTypeService.GetContentType(currContent.ContentTypeId); } else { currContentType = Services.ContentTypeService.GetMediaType(currContent.ContentTypeId); } nodeAllowed = currContentType.AllowedAsRoot; if (!nodeAllowed) { feedback.Text = ui.Text("moveOrCopy", "notAllowedAtRoot", UmbracoUser); feedback.type = uicontrols.Feedback.feedbacktype.error; } } else { 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", UmbracoUser); feedback.type = uicontrols.Feedback.feedbacktype.error; } else { // Check on paths if ((string.Format(",{0},", parentContent.Path)).IndexOf(string.Format(",{0},", currContent.Id)) > -1) { nodeAllowed = false; feedback.Text = ui.Text("moveOrCopy", "notAllowedByPath", UmbracoUser); feedback.type = uicontrols.Feedback.feedbacktype.error; } } } if (nodeAllowed) { pane_form.Visible = false; pane_form_notice.Visible = false; panel_buttons.Visible = false; var newNodeCaption = parentContent == null ? ui.Text(CurrentApp) : parentContent.Name; string[] nodes = { currContent.Name, newNodeCaption }; if (Request["mode"] == "cut") { if (CurrentApp == Constants.Applications.Content) { Services.ContentService.Move((IContent)currContent, Request.GetItemAs <int>("copyTo"), getUser().Id); } else { Services.MediaService.Move((IMedia)currContent, Request.GetItemAs <int>("copyTo"), getUser().Id); library.ClearLibraryCacheForMedia(currContent.Id); } feedback.Text = ui.Text("moveOrCopy", "moveDone", nodes, UmbracoUser) + "</p><p><a href='#' onclick='" + ClientTools.Scripts.CloseModalWindow() + "'>" + ui.Text("closeThisWindow") + "</a>"; feedback.type = uicontrols.Feedback.feedbacktype.success; // refresh tree ClientTools.MoveNode(currContent.Id.ToString(), currContent.Path); } else { //NOTE: We ONLY support Copy on content not media for some reason. var newContent = Services.ContentService.Copy((IContent)currContent, Request.GetItemAs <int>("copyTo"), RelateDocuments.Checked, getUser().Id); feedback.Text = ui.Text("moveOrCopy", "copyDone", nodes, getUser()) + "</p><p><a href='#' onclick='" + ClientTools.Scripts.CloseModalWindow() + "'>" + ui.Text("closeThisWindow") + "</a>"; feedback.type = uicontrols.Feedback.feedbacktype.success; // refresh tree ClientTools.CopyNode(currContent.Id.ToString(), newContent.Path); } } } }
private void HandleDocumentMoveOrCopy() { if (helper.Request("copyTo") != "" && helper.Request("id") != "") { // Check if the current node is allowed at new position bool nodeAllowed = false; cms.businesslogic.Content currentNode = new cms.businesslogic.Content(int.Parse(helper.Request("id"))); int oldParent = -1; if (currentNode.Level > 1) { oldParent = currentNode.Parent.Id; } cms.businesslogic.Content newNode = new cms.businesslogic.Content(int.Parse(helper.Request("copyTo"))); // Check on contenttypes if (int.Parse(helper.Request("copyTo")) == -1) { nodeAllowed = true; } else { foreach (int i in newNode.ContentType.AllowedChildContentTypeIDs.ToList()) { if (i == currentNode.ContentType.Id) { nodeAllowed = true; break; } } if (!nodeAllowed) { feedback.Text = ui.Text("moveOrCopy", "notAllowedByContentType", base.getUser()); feedback.type = umbraco.uicontrols.Feedback.feedbacktype.error; } else { // Check on paths if (((string)("," + newNode.Path + ",")).IndexOf("," + currentNode.Id + ",") > -1) { nodeAllowed = false; feedback.Text = ui.Text("moveOrCopy", "notAllowedByPath", base.getUser()); feedback.type = umbraco.uicontrols.Feedback.feedbacktype.error; } } } if (nodeAllowed) { pane_form.Visible = false; pane_form_notice.Visible = false; panel_buttons.Visible = false; string newNodeCaption = newNode.Id == -1 ? ui.Text(helper.Request("app")) : newNode.Text; string[] nodes = { currentNode.Text, newNodeCaption }; if (UmbracoContext.Current.Request["mode"] == "cut") { if (UmbracoContext.Current.Request["app"] == "content") { //PPH changed this to document instead of cmsNode to handle republishing. cms.businesslogic.web.Document d = new umbraco.cms.businesslogic.web.Document(int.Parse(helper.Request("id"))); d.Move(int.Parse(helper.Request("copyTo"))); if (d.Published) { d.Publish(new umbraco.BusinessLogic.User(0)); //using library.publish to support load balancing. //umbraco.library.PublishSingleNode(d.Id); umbraco.library.UpdateDocumentCache(d.Id); //PPH added handling of load balanced moving of multiple nodes... if (d.HasChildren) { handleChildNodes(d); } //Using the general Refresh content method instead as it supports load balancing. //we only need to do this if the node is actually published. library.RefreshContent(); } d.Save(); //stub to save stuff to the db. } else { Media m = new Media(int.Parse(UmbracoContext.Current.Request["id"])); m.Move(int.Parse(UmbracoContext.Current.Request["copyTo"])); m.XmlGenerate(new XmlDocument()); library.ClearLibraryCacheForMedia(m.Id); } feedback.Text = ui.Text("moveOrCopy", "moveDone", nodes, base.getUser()) + "</p><p><a href='#' onclick='" + ClientTools.Scripts.CloseModalWindow() + "'>" + ui.Text("closeThisWindow") + "</a>"; feedback.type = umbraco.uicontrols.Feedback.feedbacktype.success; // refresh tree ClientTools.MoveNode(currentNode.Id.ToString(), newNode.Path); } else { cms.businesslogic.web.Document d = new cms.businesslogic.web.Document(int.Parse(helper.Request("id"))); d.Copy(int.Parse(helper.Request("copyTo")), this.getUser(), RelateDocuments.Checked); feedback.Text = ui.Text("moveOrCopy", "copyDone", nodes, base.getUser()) + "</p><p><a href='#' onclick='" + ClientTools.Scripts.CloseModalWindow() + "'>" + ui.Text("closeThisWindow") + "</a>"; feedback.type = umbraco.uicontrols.Feedback.feedbacktype.success; ClientTools.CopyNode(currentNode.Id.ToString(), newNode.Path); } } } }
private void HandleDocumentMoveOrCopy() { if (helper.Request("copyTo") != "" && helper.Request("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"))); // Check on contenttypes if (int.Parse(helper.Request("copyTo")) == -1) { nodeAllowed = true; } else { if (newNode.ContentType.AllowedChildContentTypeIDs.Where(c => c == currentNode.ContentType.Id).Any()) { nodeAllowed = true; } if (nodeAllowed == false) { feedback.Text = ui.Text("moveOrCopy", "notAllowedByContentType", base.getUser()); feedback.type = uicontrols.Feedback.feedbacktype.error; } else { // Check on paths if ((string.Format(",{0},", newNode.Path)).IndexOf(string.Format(",{0},", currentNode.Id)) > -1) { nodeAllowed = false; feedback.Text = ui.Text("moveOrCopy", "notAllowedByPath", base.getUser()); feedback.type = uicontrols.Feedback.feedbacktype.error; } } } if (nodeAllowed) { pane_form.Visible = false; pane_form_notice.Visible = false; panel_buttons.Visible = false; var newNodeCaption = newNode.Id == -1 ? ui.Text(CurrentApp) : newNode.Text; string[] nodes = { currentNode.Text, 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(); } 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); } feedback.Text = ui.Text("moveOrCopy", "moveDone", nodes, getUser()) + "</p><p><a href='#' onclick='" + ClientTools.Scripts.CloseModalWindow() + "'>" + ui.Text("closeThisWindow") + "</a>"; feedback.type = uicontrols.Feedback.feedbacktype.success; // refresh tree ClientTools.MoveNode(currentNode.Id.ToString(), newNode.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()) + "</p><p><a href='#' onclick='" + ClientTools.Scripts.CloseModalWindow() + "'>" + ui.Text("closeThisWindow") + "</a>"; feedback.type = uicontrols.Feedback.feedbacktype.success; ClientTools.CopyNode(currentNode.Id.ToString(), newNode.Path); } } } }