diff --git a/src/Orchard.Web/Core/Common/Handlers/CommonPartHandler.cs b/src/Orchard.Web/Core/Common/Handlers/CommonPartHandler.cs index 0c939952f..c58bbe8f2 100644 --- a/src/Orchard.Web/Core/Common/Handlers/CommonPartHandler.cs +++ b/src/Orchard.Web/Core/Common/Handlers/CommonPartHandler.cs @@ -45,7 +45,9 @@ namespace Orchard.Core.Common.Handlers { OnVersioned>(AssignVersioningDates); OnPublishing(AssignPublishingDates); + OnUnpublishing(AssignPublishingDates); OnPublishing>(AssignPublishingDates); + OnUnpublishing>(AssignPublishingDates); OnIndexing((context, commonPart) => context.DocumentIndex .Add("type", commonPart.ContentItem.ContentType).Store() diff --git a/src/Orchard.Web/Core/Routable/Handlers/RoutePartHandler.cs b/src/Orchard.Web/Core/Routable/Handlers/RoutePartHandler.cs index a5bc9ce3d..8e046874e 100644 --- a/src/Orchard.Web/Core/Routable/Handlers/RoutePartHandler.cs +++ b/src/Orchard.Web/Core/Routable/Handlers/RoutePartHandler.cs @@ -49,14 +49,14 @@ namespace Orchard.Core.Routable.Handlers { OnGetEditorShape(SetModelProperties); OnUpdateEditorShape(SetModelProperties); - OnPublished((context, route) => { + Action handler = (context, route) => { FinalizePath(route, context, processSlug); if (route.Id != 0 && route.PromoteToHomePage && _routableHomePageProvider != null) { var homePageSetting = _workContextAccessor.GetContext().CurrentSite.HomePage; var currentHomePageId = !string.IsNullOrWhiteSpace(homePageSetting) - ? _routableHomePageProvider.GetHomePageId(homePageSetting) - : 0; + ? _routableHomePageProvider.GetHomePageId(homePageSetting) + : 0; if (currentHomePageId != route.Id) { // reset the path on the current home page @@ -73,7 +73,9 @@ namespace Orchard.Core.Routable.Handlers { _routableService.FixContainedPaths(route); _routablePathConstraint.AddPath(route.Path); } - }); + }; + OnPublished(handler); + OnUnpublished(handler); OnRemoved((context, route) => { if (!string.IsNullOrWhiteSpace(route.Path)) diff --git a/src/Orchard.Web/Modules/Orchard.Blogs/Handlers/BlogPartArchiveHandler.cs b/src/Orchard.Web/Modules/Orchard.Blogs/Handlers/BlogPartArchiveHandler.cs index b25c29dd8..530747bc8 100644 --- a/src/Orchard.Web/Modules/Orchard.Blogs/Handlers/BlogPartArchiveHandler.cs +++ b/src/Orchard.Web/Modules/Orchard.Blogs/Handlers/BlogPartArchiveHandler.cs @@ -14,6 +14,7 @@ namespace Orchard.Blogs.Handlers { public class BlogPartArchiveHandler : ContentHandler { public BlogPartArchiveHandler(IRepository blogArchiveRepository, IBlogPostService blogPostService) { OnPublished((context, bp) => RecalculateBlogArchive(blogArchiveRepository, blogPostService, bp)); + OnUnpublished((context, bp) => RecalculateBlogArchive(blogArchiveRepository, blogPostService, bp)); OnRemoved((context, bp) => RecalculateBlogArchive(blogArchiveRepository, blogPostService, bp)); } diff --git a/src/Orchard.Web/Modules/Orchard.Blogs/Handlers/BlogPartHandler.cs b/src/Orchard.Web/Modules/Orchard.Blogs/Handlers/BlogPartHandler.cs index 7f978a8f8..d774be87e 100644 --- a/src/Orchard.Web/Modules/Orchard.Blogs/Handlers/BlogPartHandler.cs +++ b/src/Orchard.Web/Modules/Orchard.Blogs/Handlers/BlogPartHandler.cs @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; using System.Linq; using System.Web.Routing; @@ -24,7 +25,7 @@ namespace Orchard.Blogs.Handlers { _routableHomePageProvider = homePageProviders.SingleOrDefault(p => p.GetProviderName() == RoutableHomePageProvider.Name); Filters.Add(StorageFilter.For(repository)); - OnPublished((context, route) => { + Action publishedHandler = (context, route) => { if (route.Is()) { if (route.ContentItem.Id != 0 && route.PromoteToHomePage) _blogSlugConstraint.AddSlug(""); @@ -32,12 +33,15 @@ namespace Orchard.Blogs.Handlers { else if (route.ContentItem.Id != 0 && route.PromoteToHomePage) { _blogSlugConstraint.RemoveSlug(""); } - }); + }; + + OnPublished(publishedHandler); + OnUnpublished(publishedHandler); OnGetDisplayShape((context, blog) => { - context.Shape.Description = blog.Description; - context.Shape.PostCount = blog.PostCount; - }); + context.Shape.Description = blog.Description; + context.Shape.PostCount = blog.PostCount; + }); } protected override void GetItemMetadata(GetContentItemMetadataContext context) { diff --git a/src/Orchard.Web/Modules/Orchard.Blogs/Handlers/BlogPostPartHandler.cs b/src/Orchard.Web/Modules/Orchard.Blogs/Handlers/BlogPostPartHandler.cs index 874ffc1f6..34878376a 100644 --- a/src/Orchard.Web/Modules/Orchard.Blogs/Handlers/BlogPostPartHandler.cs +++ b/src/Orchard.Web/Modules/Orchard.Blogs/Handlers/BlogPostPartHandler.cs @@ -50,6 +50,7 @@ namespace Orchard.Blogs.Handlers { }); OnCreated((context, bp) => updateBlogPostCount(bp.BlogPart)); OnPublished((context, bp) => updateBlogPostCount(bp.BlogPart)); + OnUnpublished((context, bp) => updateBlogPostCount(bp.BlogPart)); OnVersioned((context, bp1, bp2) => updateBlogPostCount(bp2.BlogPart)); OnRemoved((context, bp) => updateBlogPostCount(bp.BlogPart)); diff --git a/src/Orchard.Web/Modules/Orchard.Indexing/Handlers/CreateIndexingTaskHandler.cs b/src/Orchard.Web/Modules/Orchard.Indexing/Handlers/CreateIndexingTaskHandler.cs index 074842cf5..043d58489 100644 --- a/src/Orchard.Web/Modules/Orchard.Indexing/Handlers/CreateIndexingTaskHandler.cs +++ b/src/Orchard.Web/Modules/Orchard.Indexing/Handlers/CreateIndexingTaskHandler.cs @@ -23,6 +23,7 @@ namespace Orchard.Indexing.Handlers { _indexNotifierHandlers = indexNotifierHandlers; OnPublished(CreateIndexingTask); + OnUnpublished(CreateIndexingTask); OnRemoved(RemoveIndexingTask); } diff --git a/src/Orchard/ContentManagement/DefaultContentManager.cs b/src/Orchard/ContentManagement/DefaultContentManager.cs index de0ad9276..7081bd87c 100644 --- a/src/Orchard/ContentManagement/DefaultContentManager.cs +++ b/src/Orchard/ContentManagement/DefaultContentManager.cs @@ -228,11 +228,11 @@ namespace Orchard.ContentManagement { PublishingItemVersionRecord = null }; - Handlers.Invoke(handler => handler.Publishing(context), Logger); + Handlers.Invoke(handler => handler.Unpublishing(context), Logger); publishedItem.VersionRecord.Published = false; - Handlers.Invoke(handler => handler.Published(context), Logger); + Handlers.Invoke(handler => handler.Unpublished(context), Logger); } public virtual void Remove(ContentItem contentItem) { diff --git a/src/Orchard/ContentManagement/Handlers/ContentHandler.cs b/src/Orchard/ContentManagement/Handlers/ContentHandler.cs index 3984d495b..73612bb87 100644 --- a/src/Orchard/ContentManagement/Handlers/ContentHandler.cs +++ b/src/Orchard/ContentManagement/Handlers/ContentHandler.cs @@ -53,6 +53,14 @@ namespace Orchard.ContentManagement.Handlers { Filters.Add(new InlineStorageFilter { OnPublished = handler }); } + protected void OnUnpublishing(Action handler) where TPart : class, IContent { + Filters.Add(new InlineStorageFilter { OnUnpublishing = handler }); + } + + protected void OnUnpublished(Action handler) where TPart : class, IContent { + Filters.Add(new InlineStorageFilter { OnUnpublished = handler }); + } + protected void OnRemoving(Action handler) where TPart : class, IContent { Filters.Add(new InlineStorageFilter { OnRemoving = handler }); } @@ -95,6 +103,8 @@ namespace Orchard.ContentManagement.Handlers { public Action OnVersioned { get; set; } public Action OnPublishing { get; set; } public Action OnPublished { get; set; } + public Action OnUnpublishing { get; set; } + public Action OnUnpublished { get; set; } public Action OnRemoving { get; set; } public Action OnRemoved { get; set; } public Action OnIndexing { get; set; } @@ -129,6 +139,12 @@ namespace Orchard.ContentManagement.Handlers { protected override void Published(PublishContentContext context, TPart instance) { if (OnPublished != null) OnPublished(context, instance); } + protected override void Unpublishing(PublishContentContext context, TPart instance) { + if (OnUnpublishing != null) OnUnpublishing(context, instance); + } + protected override void Unpublished(PublishContentContext context, TPart instance) { + if (OnUnpublished != null) OnUnpublished(context, instance); + } protected override void Removing(RemoveContentContext context, TPart instance) { if (OnRemoving != null) OnRemoving(context, instance); } @@ -231,6 +247,18 @@ namespace Orchard.ContentManagement.Handlers { Published(context); } + void IContentHandler.Unpublishing(PublishContentContext context) { + foreach (var filter in Filters.OfType()) + filter.Unpublishing(context); + Unpublishing(context); + } + + void IContentHandler.Unpublished(PublishContentContext context) { + foreach (var filter in Filters.OfType()) + filter.Unpublished(context); + Unpublished(context); + } + void IContentHandler.Removing(RemoveContentContext context) { foreach (var filter in Filters.OfType()) filter.Removing(context); @@ -293,6 +321,9 @@ namespace Orchard.ContentManagement.Handlers { protected virtual void Publishing(PublishContentContext context) { } protected virtual void Published(PublishContentContext context) { } + protected virtual void Unpublishing(PublishContentContext context) { } + protected virtual void Unpublished(PublishContentContext context) { } + protected virtual void Removing(RemoveContentContext context) { } protected virtual void Removed(RemoveContentContext context) { } diff --git a/src/Orchard/ContentManagement/Handlers/ContentHandlerBase.cs b/src/Orchard/ContentManagement/Handlers/ContentHandlerBase.cs index 968d974fa..561f1aa01 100644 --- a/src/Orchard/ContentManagement/Handlers/ContentHandlerBase.cs +++ b/src/Orchard/ContentManagement/Handlers/ContentHandlerBase.cs @@ -11,7 +11,9 @@ public virtual void Versioned(VersionContentContext context) {} public virtual void Publishing(PublishContentContext context) {} public virtual void Published(PublishContentContext context) {} - public virtual void Removing(RemoveContentContext context) {} + public virtual void Unpublishing(PublishContentContext context) { } + public virtual void Unpublished(PublishContentContext context) { } + public virtual void Removing(RemoveContentContext context) { } public virtual void Removed(RemoveContentContext context) {} public virtual void Indexing(IndexContentContext context) {} public virtual void Indexed(IndexContentContext context) {} diff --git a/src/Orchard/ContentManagement/Handlers/IContentHandler.cs b/src/Orchard/ContentManagement/Handlers/IContentHandler.cs index 4d794a05b..31d86d6e3 100644 --- a/src/Orchard/ContentManagement/Handlers/IContentHandler.cs +++ b/src/Orchard/ContentManagement/Handlers/IContentHandler.cs @@ -11,6 +11,8 @@ void Versioned(VersionContentContext context); void Publishing(PublishContentContext context); void Published(PublishContentContext context); + void Unpublishing(PublishContentContext context); + void Unpublished(PublishContentContext context); void Removing(RemoveContentContext context); void Removed(RemoveContentContext context); void Indexing(IndexContentContext context); diff --git a/src/Orchard/ContentManagement/Handlers/IContentStorageFilter.cs b/src/Orchard/ContentManagement/Handlers/IContentStorageFilter.cs index cdfe9f99b..4cac591b6 100644 --- a/src/Orchard/ContentManagement/Handlers/IContentStorageFilter.cs +++ b/src/Orchard/ContentManagement/Handlers/IContentStorageFilter.cs @@ -10,6 +10,8 @@ namespace Orchard.ContentManagement.Handlers { void Versioned(VersionContentContext context); void Publishing(PublishContentContext context); void Published(PublishContentContext context); + void Unpublishing(PublishContentContext context); + void Unpublished(PublishContentContext context); void Removing(RemoveContentContext context); void Removed(RemoveContentContext context); void Indexing(IndexContentContext context); diff --git a/src/Orchard/ContentManagement/Handlers/StorageFilterBase.cs b/src/Orchard/ContentManagement/Handlers/StorageFilterBase.cs index aed0ac0da..81a94958f 100644 --- a/src/Orchard/ContentManagement/Handlers/StorageFilterBase.cs +++ b/src/Orchard/ContentManagement/Handlers/StorageFilterBase.cs @@ -11,6 +11,8 @@ namespace Orchard.ContentManagement.Handlers { protected virtual void Versioned(VersionContentContext context, TPart existing, TPart building) { } protected virtual void Publishing(PublishContentContext context, TPart instance) { } protected virtual void Published(PublishContentContext context, TPart instance) { } + protected virtual void Unpublishing(PublishContentContext context, TPart instance) { } + protected virtual void Unpublished(PublishContentContext context, TPart instance) { } protected virtual void Removing(RemoveContentContext context, TPart instance) { } protected virtual void Removed(RemoveContentContext context, TPart instance) { } protected virtual void Indexing(IndexContentContext context, TPart instance) { } @@ -67,6 +69,16 @@ namespace Orchard.ContentManagement.Handlers { Published(context, context.ContentItem.As()); } + void IContentStorageFilter.Unpublishing(PublishContentContext context) { + if (context.ContentItem.Is()) + Unpublishing(context, context.ContentItem.As()); + } + + void IContentStorageFilter.Unpublished(PublishContentContext context) { + if (context.ContentItem.Is()) + Unpublished(context, context.ContentItem.As()); + } + void IContentStorageFilter.Removing(RemoveContentContext context) { if (context.ContentItem.Is()) Removing(context, context.ContentItem.As());