Merge branch 'temp8' of https://github.com/umbraco/Umbraco-CMS into temp8
This commit is contained in:
@@ -38,16 +38,24 @@ namespace Umbraco.Web.Routing
|
||||
{
|
||||
get
|
||||
{
|
||||
var oldRoutes =
|
||||
(Dictionary<ContentIdAndCulture, ContentKeyAndOldRoute>) UmbracoContext.Current.HttpContext.Items[
|
||||
ContextKey3];
|
||||
var oldRoutes = (Dictionary<ContentIdAndCulture, ContentKeyAndOldRoute>) UmbracoContext.Current.HttpContext.Items[ContextKey3];
|
||||
if (oldRoutes == null)
|
||||
UmbracoContext.Current.HttpContext.Items[ContextKey3] =
|
||||
oldRoutes = new Dictionary<ContentIdAndCulture, ContentKeyAndOldRoute>();
|
||||
UmbracoContext.Current.HttpContext.Items[ContextKey3] = oldRoutes = new Dictionary<ContentIdAndCulture, ContentKeyAndOldRoute>();
|
||||
return oldRoutes;
|
||||
}
|
||||
}
|
||||
|
||||
private static bool HasOldRoutes
|
||||
{
|
||||
get
|
||||
{
|
||||
if (Current.UmbracoContext == null) return false;
|
||||
if (Current.UmbracoContext.HttpContext == null) return false;
|
||||
if (Current.UmbracoContext.HttpContext.Items[ContextKey3] == null) return false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
private static bool LockedEvents
|
||||
{
|
||||
get => Moving && UmbracoContext.Current.HttpContext.Items[ContextKey2] != null;
|
||||
@@ -97,8 +105,8 @@ namespace Umbraco.Web.Routing
|
||||
ContentService.Published += ContentService_Published;
|
||||
ContentService.Moving += ContentService_Moving;
|
||||
ContentService.Moved += ContentService_Moved;
|
||||
ContentCacheRefresher.CacheUpdated += ContentCacheRefresher_CacheUpdated;
|
||||
|
||||
ContentCacheRefresher.CacheUpdated += ContentCacheRefresher_CacheUpdated;
|
||||
|
||||
// kill all redirects once a content is deleted
|
||||
//ContentService.Deleted += ContentService_Deleted;
|
||||
@@ -111,21 +119,26 @@ namespace Umbraco.Web.Routing
|
||||
public void Terminate()
|
||||
{ }
|
||||
|
||||
private static void ContentCacheRefresher_CacheUpdated(ContentCacheRefresher sender,
|
||||
CacheRefresherEventArgs args)
|
||||
private static void ContentCacheRefresher_CacheUpdated(ContentCacheRefresher sender, CacheRefresherEventArgs args)
|
||||
{
|
||||
// that event is a distributed even that triggers on all nodes
|
||||
// BUT it should totally NOT run on nodes other that the one that handled the other events
|
||||
// and besides, it cannot run on a background thread!
|
||||
if (!HasOldRoutes)
|
||||
return;
|
||||
|
||||
// sanity checks
|
||||
if (args.MessageType != MessageType.RefreshByPayload)
|
||||
{
|
||||
throw new InvalidOperationException("ContentCacheRefresher MessageType should be ByPayload.");
|
||||
}
|
||||
|
||||
if (args.MessageObject == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var payloads = args.MessageObject as ContentCacheRefresher.JsonPayload[];
|
||||
if (payloads == null)
|
||||
if (!(args.MessageObject is ContentCacheRefresher.JsonPayload[]))
|
||||
{
|
||||
throw new InvalidOperationException("ContentCacheRefresher MessageObject should be JsonPayload[].");
|
||||
}
|
||||
@@ -137,8 +150,7 @@ namespace Umbraco.Web.Routing
|
||||
{
|
||||
// assuming we cannot have 'CacheUpdated' for only part of the infos else we'd need
|
||||
// to set a flag in 'Published' to indicate which entities have been refreshed ok
|
||||
CreateRedirect(oldRoute.Key.ContentId, oldRoute.Key.Culture, oldRoute.Value.ContentKey,
|
||||
oldRoute.Value.OldRoute);
|
||||
CreateRedirect(oldRoute.Key.ContentId, oldRoute.Key.Culture, oldRoute.Value.ContentKey, oldRoute.Value.OldRoute);
|
||||
removeKeys.Add(oldRoute.Key);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user