diff --git a/src/Umbraco.Web/umbraco.presentation/content.cs b/src/Umbraco.Web/umbraco.presentation/content.cs index 23e44896f4..2d80eb0481 100644 --- a/src/Umbraco.Web/umbraco.presentation/content.cs +++ b/src/Umbraco.Web/umbraco.presentation/content.cs @@ -191,7 +191,7 @@ namespace umbraco // check if document *is* published, it could be unpublished by an event if (d.Published) { - var parentId = d.Level == 1 ? -1 : d.Parent.Id; + var parentId = d.Level == 1 ? -1 : d.ParentId; // fix sortOrder - see note in UpdateSortOrder var node = GetPreviewOrPublishedNode(d, xmlContentCopy, false); diff --git a/src/Umbraco.Web/umbraco.presentation/page.cs b/src/Umbraco.Web/umbraco.presentation/page.cs index ce2b55152b..e71a290754 100644 --- a/src/Umbraco.Web/umbraco.presentation/page.cs +++ b/src/Umbraco.Web/umbraco.presentation/page.cs @@ -70,7 +70,7 @@ namespace umbraco var docParentId = -1; try { - docParentId = document.Parent.Id; + docParentId = document.ParentId; } catch (ArgumentException) { diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/channels/api.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/channels/api.cs index 49296884fa..ace78f6803 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/channels/api.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/channels/api.cs @@ -93,7 +93,7 @@ namespace umbraco.presentation.channels p.dateCreated = d.CreateDateTime; p.page_title = d.Text; p.page_id = d.Id; - p.page_parent_id = d.Parent.Id; + p.page_parent_id = d.ParentId; blogPostsObjects.Add(p); } @@ -150,7 +150,7 @@ namespace umbraco.presentation.channels p.dateCreated = d.CreateDateTime; p.title = d.Text; p.page_id = d.Id; - p.wp_page_parent_id = d.Parent.Id; + p.wp_page_parent_id = d.ParentId; p.wp_page_parent_title = d.Parent.Text; p.permalink = library.NiceUrl(d.Id); p.description = d.getProperty(userChannel.FieldDescriptionAlias).Value.ToString(); diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/preview/PreviewContent.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/preview/PreviewContent.cs index b8d37fbb65..2499c1c817 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/preview/PreviewContent.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/preview/PreviewContent.cs @@ -83,7 +83,7 @@ namespace umbraco.presentation.preview var previewNodes = new List(); - var parentId = documentObject.Level == 1 ? -1 : documentObject.Parent.Id; + var parentId = documentObject.Level == 1 ? -1 : documentObject.ParentId; while (parentId > 0 && XmlContent.GetElementById(parentId.ToString(CultureInfo.InvariantCulture)) == null) { @@ -97,7 +97,7 @@ namespace umbraco.presentation.preview foreach (var document in previewNodes) { //Inject preview xml - parentId = document.Level == 1 ? -1 : document.Parent.Id; + parentId = document.Level == 1 ? -1 : document.ParentId; var previewXml = document.ToPreviewXml(XmlContent); if (document.ContentEntity.Published == false && ApplicationContext.Current.Services.ContentService.HasPublishedVersion(document.Id)) diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/uQuery/MediaExtensions.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/uQuery/MediaExtensions.cs index 42b9cd757b..411734ae99 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/uQuery/MediaExtensions.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/uQuery/MediaExtensions.cs @@ -19,13 +19,13 @@ namespace umbraco /// Media nodes as IEnumerable public static IEnumerable GetAncestorMedia(this Media media) { - var ancestor = new Media(media.Parent.Id); + var ancestor = new Media(media.ParentId); while (ancestor != null && ancestor.Id != -1) { yield return ancestor; - ancestor = new Media(ancestor.Parent.Id); + ancestor = new Media(ancestor.ParentId); } } @@ -53,7 +53,7 @@ namespace umbraco { if (media.Parent != null) { - var parentMedia = new Media(media.Parent.Id); + var parentMedia = new Media(media.ParentId); foreach (var siblingMedia in parentMedia.GetChildMedia().Where(childMedia => childMedia.Id != media.Id)) { diff --git a/src/umbraco.cms/businesslogic/CMSNode.cs b/src/umbraco.cms/businesslogic/CMSNode.cs index 661e620056..3b4e9c9b31 100644 --- a/src/umbraco.cms/businesslogic/CMSNode.cs +++ b/src/umbraco.cms/businesslogic/CMSNode.cs @@ -617,6 +617,7 @@ order by level,sortOrder"; /// /// Target CMSNode id [Obsolete("Obsolete, Use Umbraco.Core.Services.ContentService.Move() or Umbraco.Core.Services.MediaService.Move()", false)] + [EditorBrowsable(EditorBrowsableState.Never)] public virtual void Move(int newParentId) { CMSNode parent = new CMSNode(newParentId); @@ -796,6 +797,7 @@ order by level,sortOrder"; internal set { _parentid = value; } } + private IUmbracoEntity _parent; /// /// Given the hierarchical tree structure a CMSNode has only one newParent but can have many children /// @@ -805,15 +807,21 @@ order by level,sortOrder"; get { if (Level == 1) throw new ArgumentException("No newParent node"); - return new CMSNode(_parentid); + if (_parent == null) + { + _parent = ApplicationContext.Current.Services.EntityService.Get(Entity.ParentId); + } + return new CMSNode(_parent); } set { _parentid = value.Id; - SqlHelper.ExecuteNonQuery("update umbracoNode set parentId = " + value.Id.ToString() + " where id = " + this.Id.ToString()); + SqlHelper.ExecuteNonQuery("update umbracoNode set parentId = " + value.Id + " where id = " + this.Id.ToString()); if (Entity != null) Entity.ParentId = value.Id; + + _parent = value.Entity; } } @@ -1183,7 +1191,7 @@ order by level,sortOrder"; x.Attributes.Append(xmlHelper.addAttribute(xd, "id", this.Id.ToString())); x.Attributes.Append(xmlHelper.addAttribute(xd, "key", this.UniqueId.ToString())); if (this.Level > 1) - x.Attributes.Append(xmlHelper.addAttribute(xd, "parentID", this.Parent.Id.ToString())); + x.Attributes.Append(xmlHelper.addAttribute(xd, "parentID", this.ParentId.ToString())); else x.Attributes.Append(xmlHelper.addAttribute(xd, "parentID", "-1")); x.Attributes.Append(xmlHelper.addAttribute(xd, "level", this.Level.ToString())); diff --git a/src/umbraco.cms/businesslogic/Content.cs b/src/umbraco.cms/businesslogic/Content.cs index 36eafb91a2..f014ddae93 100644 --- a/src/umbraco.cms/businesslogic/Content.cs +++ b/src/umbraco.cms/businesslogic/Content.cs @@ -115,6 +115,14 @@ namespace umbraco.cms.businesslogic #region Public Properties + /// + /// Get the newParent id of the node + /// + public override int ParentId + { + get { return ContentBase == null ? base.ParentId : ContentBase.ParentId; } + } + /// /// The current Content objects ContentType, which defines the Properties of the Content (data) /// @@ -411,7 +419,7 @@ namespace umbraco.cms.businesslogic x.Attributes.Append(XmlHelper.AddAttribute(xd, "key", this.UniqueId.ToString())); x.Attributes.Append(XmlHelper.AddAttribute(xd, "version", this.Version.ToString())); if (this.Level > 1) - x.Attributes.Append(XmlHelper.AddAttribute(xd, "parentID", this.Parent.Id.ToString())); + x.Attributes.Append(XmlHelper.AddAttribute(xd, "parentID", this.ParentId.ToString())); else x.Attributes.Append(XmlHelper.AddAttribute(xd, "parentID", "-1")); x.Attributes.Append(XmlHelper.AddAttribute(xd, "level", this.Level.ToString())); diff --git a/src/umbraco.cms/businesslogic/web/Document.cs b/src/umbraco.cms/businesslogic/web/Document.cs index 0c5f2c3025..f5332cb68c 100644 --- a/src/umbraco.cms/businesslogic/web/Document.cs +++ b/src/umbraco.cms/businesslogic/web/Document.cs @@ -473,7 +473,7 @@ namespace umbraco.cms.businesslogic.web #endregion #region Public Properties - + public override int sortOrder { get @@ -514,10 +514,7 @@ namespace umbraco.cms.businesslogic.web public override int ParentId { - get - { - return ContentEntity == null ? base.ParentId : ContentEntity.ParentId; - } + get { return ContentEntity == null ? base.ParentId : ContentEntity.ParentId; } } public override string Path @@ -1291,7 +1288,7 @@ namespace umbraco.cms.businesslogic.web x.Attributes.Append(addAttribute(xd, "key", UniqueId.ToString())); // x.Attributes.Append(addAttribute(xd, "version", Version.ToString())); if (Level > 1) - x.Attributes.Append(addAttribute(xd, "parentID", Parent.Id.ToString())); + x.Attributes.Append(addAttribute(xd, "parentID", ParentId.ToString())); else x.Attributes.Append(addAttribute(xd, "parentID", "-1")); x.Attributes.Append(addAttribute(xd, "level", Level.ToString()));