From 0fda528b9488868bbc079883eb5d4bd7bfea2b5b Mon Sep 17 00:00:00 2001 From: Shannon Date: Thu, 6 Mar 2014 19:47:23 +1100 Subject: [PATCH] Fixes: U4-1550 Publish notifications on a load balanced environment --- .../LegacyActionHandlerEventHandler.cs | 43 +++++++++++++++++++ src/Umbraco.Web/Umbraco.Web.csproj | 1 + .../umbraco.presentation/content.cs | 16 +------ 3 files changed, 46 insertions(+), 14 deletions(-) create mode 100644 src/Umbraco.Web/Strategies/LegacyActionHandlerEventHandler.cs diff --git a/src/Umbraco.Web/Strategies/LegacyActionHandlerEventHandler.cs b/src/Umbraco.Web/Strategies/LegacyActionHandlerEventHandler.cs new file mode 100644 index 0000000000..4ab8b25849 --- /dev/null +++ b/src/Umbraco.Web/Strategies/LegacyActionHandlerEventHandler.cs @@ -0,0 +1,43 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using umbraco.BusinessLogic.Actions; +using umbraco.cms.businesslogic.web; +using Umbraco.Core; +using Umbraco.Core.Events; +using Umbraco.Core.Models; +using Umbraco.Core.Publishing; +using Umbraco.Core.Services; + +namespace Umbraco.Web.Strategies +{ + + /// + /// This is used to trigger the legacy ActionHandlers based on events + /// + public sealed class LegacyActionHandlerEventHandler : ApplicationEventHandler + { + //NOTE: this is to fix this currently: http://issues.umbraco.org/issue/U4-1550 + + protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext) + { + ContentService.Published += ContentService_Published; + ContentService.UnPublished += ContentService_UnPublished; + } + + static void ContentService_UnPublished(IPublishingStrategy sender, PublishEventArgs e) + { + e.PublishedEntities.ForEach(x => + global::umbraco.BusinessLogic.Actions.Action.RunActionHandlers( + new Document(x), ActionUnPublish.Instance)); + } + + static void ContentService_Published(IPublishingStrategy sender, PublishEventArgs e) + { + e.PublishedEntities.ForEach(x => + global::umbraco.BusinessLogic.Actions.Action.RunActionHandlers( + new Document(x), ActionPublish.Instance)); + } + } +} diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj index 86c7437ba3..11d70c41b8 100644 --- a/src/Umbraco.Web/Umbraco.Web.csproj +++ b/src/Umbraco.Web/Umbraco.Web.csproj @@ -401,6 +401,7 @@ + diff --git a/src/Umbraco.Web/umbraco.presentation/content.cs b/src/Umbraco.Web/umbraco.presentation/content.cs index 9270e57cc0..ab611bda87 100644 --- a/src/Umbraco.Web/umbraco.presentation/content.cs +++ b/src/Umbraco.Web/umbraco.presentation/content.cs @@ -521,9 +521,7 @@ namespace umbraco var cachedFieldKeyStart = string.Format("{0}{1}_", CacheKeys.ContentItemCacheKey, d.Id); ApplicationContext.Current.ApplicationCache.ClearCacheByKeySearch(cachedFieldKeyStart); - - Action.RunActionHandlers(d, ActionPublish.Instance); - + FireAfterUpdateDocumentCache(d, e); } } @@ -532,6 +530,7 @@ namespace umbraco /// Updates the document cache for multiple documents /// /// The documents. + [Obsolete("This is not used and will be removed from the codebase in future versions")] public virtual void UpdateDocumentCache(List Documents) { // We need to lock content cache here, because we cannot allow other threads @@ -550,11 +549,6 @@ namespace umbraco XmlContentInternal = xmlContentCopy; ClearContextCache(); } - - foreach (Document d in Documents) - { - Action.RunActionHandlers(d, ActionPublish.Instance); - } } /// @@ -635,12 +629,6 @@ namespace umbraco } } - if (x != null) - { - // Run Handler - Action.RunActionHandlers(doc, ActionUnPublish.Instance); - } - //SD: changed to fire event BEFORE running the sitemap!! argh. FireAfterClearDocumentCache(doc, e);