From 9321082d44ebd3c6ca6dd0feed811b383c20ee85 Mon Sep 17 00:00:00 2001 From: MarcoViglione-Laser Date: Thu, 10 Jan 2019 21:06:51 +0100 Subject: [PATCH] Alias removal is now executed on the published version of a content (#8100) (#8150) --- .../Handlers/AutoroutePartHandler.cs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/Orchard.Web/Modules/Orchard.Autoroute/Handlers/AutoroutePartHandler.cs b/src/Orchard.Web/Modules/Orchard.Autoroute/Handlers/AutoroutePartHandler.cs index 1038e93ab..3894e4a1e 100644 --- a/src/Orchard.Web/Modules/Orchard.Autoroute/Handlers/AutoroutePartHandler.cs +++ b/src/Orchard.Web/Modules/Orchard.Autoroute/Handlers/AutoroutePartHandler.cs @@ -11,6 +11,7 @@ namespace Orchard.Autoroute.Handlers { public class AutoroutePartHandler : ContentHandler { private readonly Lazy _autorouteService; + private readonly IContentManager _contentManager; private readonly IOrchardServices _orchardServices; private readonly IHomeAliasService _homeAliasService; @@ -19,11 +20,13 @@ namespace Orchard.Autoroute.Handlers { public AutoroutePartHandler( IRepository autoroutePartRepository, Lazy autorouteService, + IContentManager contentManager, IOrchardServices orchardServices, IHomeAliasService homeAliasService) { Filters.Add(StorageFilter.For(autoroutePartRepository)); _autorouteService = autorouteService; + _contentManager = contentManager; _orchardServices = orchardServices; _homeAliasService = homeAliasService; @@ -40,8 +43,8 @@ namespace Orchard.Autoroute.Handlers { // Remove alias if destroyed, removed or unpublished OnRemoving((ctx, part) => RemoveAlias(part)); - OnDestroyed((ctx, part) => RemoveAlias(part)); - OnUnpublished((ctx, part) => RemoveAlias(part)); + OnDestroying((ctx, part) => RemoveAlias(part)); + OnUnpublishing((ctx, part) => RemoveAlias(part)); // Register alias as identity OnGetContentItemMetadata((ctx, part) => { @@ -106,7 +109,9 @@ namespace Orchard.Autoroute.Handlers { if (part.ContentItem.Id == homePageId) { _orchardServices.Notifier.Warning(T("You removed the content item that served as the site's home page. \nMost possibly this means that instead of the home page a \"404 Not Found\" page will be displayed. \n\nTo prevent this you can e.g. publish a content item that has the \"Set as home page\" checkbox ticked.")); } - _autorouteService.Value.RemoveAliases(part); + + var publishedPart = _contentManager.Get(part.ContentItem.Id, VersionOptions.Published); + _autorouteService.Value.RemoveAliases(publishedPart); } } }