From d826f04b548ce9e10ac34662fd478eb8e382234f Mon Sep 17 00:00:00 2001 From: Shannon Date: Tue, 17 May 2016 12:17:05 +0200 Subject: [PATCH] Ensures sort order is accurate to what is in the database --- src/Umbraco.Web/umbraco.presentation/content.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Umbraco.Web/umbraco.presentation/content.cs b/src/Umbraco.Web/umbraco.presentation/content.cs index bdd8c91f18..dc303c809d 100644 --- a/src/Umbraco.Web/umbraco.presentation/content.cs +++ b/src/Umbraco.Web/umbraco.presentation/content.cs @@ -528,12 +528,14 @@ where umbracoNode.id in (select cmsDocument.nodeId from cmsDocument where cmsDoc order by umbracoNode.level, umbracoNode.parentID, umbracoNode.sortOrder"; XmlElement last = null; + var db = ApplicationContext.Current.DatabaseContext.Database; //NOTE: Query creates a reader - does not load all into memory foreach (var row in db.Query(sql, new { type = new Guid(Constants.ObjectTypes.Document)})) { string parentId = ((int)row.parentID).ToInvariantString(); string xml = row.xml; + int sortOrder = row.sortOrder; //if the parentid is changing if (last != null && last.GetAttribute("parentID") != parentId) @@ -544,8 +546,11 @@ order by umbracoNode.level, umbracoNode.parentID, umbracoNode.sortOrder"; var xmlDocFragment = xmlDoc.CreateDocumentFragment(); xmlDocFragment.InnerXml = xml; - + last = (XmlElement)parent.AppendChild(xmlDocFragment); + + // fix sortOrder - see notes in UpdateSortOrder + last.Attributes["sortOrder"].Value = sortOrder.ToInvariantString(); } LogHelper.Debug("Done republishing Xml Index");