From c3bfa268ddae72c8be07e4c0cc70057a4b6213a7 Mon Sep 17 00:00:00 2001 From: Dave Reed Date: Thu, 24 Mar 2011 13:54:15 -0700 Subject: [PATCH] Fix an items route after changing containers via the new MoveList and RemoveFromList bulk actions. --HG-- branch : dev --- .../Controllers/AdminController.cs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/Orchard.Web/Modules/Orchard.Lists/Controllers/AdminController.cs b/src/Orchard.Web/Modules/Orchard.Lists/Controllers/AdminController.cs index 08f9a1f70..6e6646178 100644 --- a/src/Orchard.Web/Modules/Orchard.Lists/Controllers/AdminController.cs +++ b/src/Orchard.Web/Modules/Orchard.Lists/Controllers/AdminController.cs @@ -11,6 +11,7 @@ using Orchard.Core.Containers.Models; using Orchard.Core.Contents; using Orchard.Core.Contents.Controllers; using Orchard.Core.Contents.Settings; +using Orchard.Core.Routable.Models; using Orchard.Data; using Orchard.DisplayManagement; using Orchard.DisplayManagement.Shapes; @@ -294,6 +295,20 @@ namespace Lists.Controllers { return RedirectToAction("Choose", routeValues); } + private void FixItemPath(ContentItem item) { + // Fixes an Item's path when its container changes. + + // force a publish/unpublish event so RoutePart fixes the content items path + // and the paths of any child objects if it is also a container. + if (item.VersionRecord.Published) { + item.VersionRecord.Published = false; + _contentManager.Publish(item); + } + else { + item.VersionRecord.Published = true; + _contentManager.Unpublish(item); + } + } private bool BulkMoveToList(IEnumerable itemIds, int? targetContainerId) { if (!targetContainerId.HasValue) { @@ -321,6 +336,7 @@ namespace Lists.Controllers { } item.As().Record.Container = targetContainer.ContentItem.Record; + FixItemPath(item); } Services.Notifier.Information(T("Content successfully moved to {1}.", Url.Action("List", new { containerId = targetContainerId }), _contentManager.GetItemMetadata(targetContainer).DisplayText)); @@ -334,6 +350,7 @@ namespace Lists.Controllers { return false; } item.As().Record.Container = null; + FixItemPath(item); } Services.Notifier.Information(T("Content successfully removed from the list.")); return true;