From 4e1634754ba46dd571fb8dae9cf8dd096c634fed Mon Sep 17 00:00:00 2001 From: Nathan Woulfe Date: Sat, 23 Mar 2019 19:29:46 +1000 Subject: [PATCH] fix URL redirection creation - was failing when save and save+publish as save creates new URL, which is compared to itself in save+publish (#5036) --- .../Routing/RedirectTrackingEventHandler.cs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Umbraco.Web/Routing/RedirectTrackingEventHandler.cs b/src/Umbraco.Web/Routing/RedirectTrackingEventHandler.cs index 75cce71f73..d032be2795 100644 --- a/src/Umbraco.Web/Routing/RedirectTrackingEventHandler.cs +++ b/src/Umbraco.Web/Routing/RedirectTrackingEventHandler.cs @@ -177,11 +177,13 @@ namespace Umbraco.Web.Routing // change the IUrlSegmentProvider to support being able to determine if a // segment is going to change for an entity. See notes in IUrlSegmentProvider. - var oldEntity = ApplicationContext.Current.Services.ContentService.GetById(entity.Id); - if (oldEntity == null) continue; - var oldSegment = oldEntity.GetUrlSegment(); + // we want the last published version, not the last saved + // otherwise redirects aren't created if content is saved, with save+publish happening later + var publishedEntity = ApplicationContext.Current.Services.ContentService.GetPublishedVersion(entity.Id); + if (publishedEntity == null) continue; + var publishedSegment = publishedEntity.GetUrlSegment(); var newSegment = entity.GetUrlSegment(); - process = oldSegment != newSegment; + process = publishedSegment != newSegment; } // skip if no segment change