From 9b498b8471e99062eb8eed810032a170b8660806 Mon Sep 17 00:00:00 2001 From: Matt Cheale Date: Fri, 2 Sep 2016 14:50:54 +0100 Subject: [PATCH 1/2] U4-8937 ContentController.PostSort is not honouring the passed sorted ids. * Updates media to content for comments and logging. * Adds sorting of the retrieved content items to match the passed sort order before persisting. --- src/Umbraco.Web/Editors/ContentController.cs | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/Umbraco.Web/Editors/ContentController.cs b/src/Umbraco.Web/Editors/ContentController.cs index d003636aac..e0f40f7a62 100644 --- a/src/Umbraco.Web/Editors/ContentController.cs +++ b/src/Umbraco.Web/Editors/ContentController.cs @@ -467,7 +467,7 @@ namespace Umbraco.Web.Editors } /// - /// Change the sort order for media + /// Change the sort order for content /// /// /// @@ -485,23 +485,30 @@ namespace Umbraco.Web.Editors return Request.CreateResponse(HttpStatusCode.OK); } - var contentService = Services.ContentService; - var sortedContent = new List(); try { - sortedContent.AddRange(Services.ContentService.GetByIds(sorted.IdSortOrder)); + var contentService = Services.ContentService; + var content = new List(); + content.AddRange(Services.ContentService.GetByIds(sorted.IdSortOrder)); + + var sortedList = new List(sorted.IdSortOrder); + var sortedContent = from o in sortedList + join con in content + on o equals con.Id + orderby sortedList.IndexOf(o) + select con; // Save content with new sort order and update content xml in db accordingly if (contentService.Sort(sortedContent) == false) { - LogHelper.Warn("Content sorting failed, this was probably caused by an event being cancelled"); + LogHelper.Warn("Content sorting failed, this was probably caused by an event being cancelled"); return Request.CreateValidationErrorResponse("Content sorting failed, this was probably caused by an event being cancelled"); } return Request.CreateResponse(HttpStatusCode.OK); } catch (Exception ex) { - LogHelper.Error("Could not update content sort order", ex); + LogHelper.Error("Could not update content sort order", ex); throw; } } From fce0a4b0eb52914594981316472f9ec0a6cffff6 Mon Sep 17 00:00:00 2001 From: Stephan Date: Mon, 5 Sep 2016 12:20:05 +0200 Subject: [PATCH 2/2] U4-8937 - cleanup --- src/Umbraco.Web/Editors/ContentController.cs | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/Umbraco.Web/Editors/ContentController.cs b/src/Umbraco.Web/Editors/ContentController.cs index e0f40f7a62..1a5a68f3f7 100644 --- a/src/Umbraco.Web/Editors/ContentController.cs +++ b/src/Umbraco.Web/Editors/ContentController.cs @@ -488,15 +488,18 @@ namespace Umbraco.Web.Editors try { var contentService = Services.ContentService; - var content = new List(); - content.AddRange(Services.ContentService.GetByIds(sorted.IdSortOrder)); - var sortedList = new List(sorted.IdSortOrder); - var sortedContent = from o in sortedList - join con in content - on o equals con.Id - orderby sortedList.IndexOf(o) - select con; + // content service GetByIds does *not* order the content items + // so we need get them in the proper order here - no need to sort! + var content = contentService + .GetByIds(sorted.IdSortOrder) + .ToDictionary(x => x.Id, x => x); + + var sortedContent = sorted.IdSortOrder.Select(x => + { + IContent c; + return content.TryGetValue(x, out c) ? c : null; + }).WhereNotNull(); // Save content with new sort order and update content xml in db accordingly if (contentService.Sort(sortedContent) == false)