Add a "OnUnpublish" event to content handlers

Work Item: 16856

--HG--
branch : dev
This commit is contained in:
Renaud Paquay
2010-12-02 20:30:13 -08:00
parent d336bfa6cf
commit cc44d1d7dd
12 changed files with 72 additions and 12 deletions

View File

@@ -45,7 +45,9 @@ namespace Orchard.Core.Common.Handlers {
OnVersioned<ContentPart<CommonPartVersionRecord>>(AssignVersioningDates);
OnPublishing<CommonPart>(AssignPublishingDates);
OnUnpublishing<CommonPart>(AssignPublishingDates);
OnPublishing<ContentPart<CommonPartVersionRecord>>(AssignPublishingDates);
OnUnpublishing<ContentPart<CommonPartVersionRecord>>(AssignPublishingDates);
OnIndexing<CommonPart>((context, commonPart) => context.DocumentIndex
.Add("type", commonPart.ContentItem.ContentType).Store()

View File

@@ -49,14 +49,14 @@ namespace Orchard.Core.Routable.Handlers {
OnGetEditorShape<RoutePart>(SetModelProperties);
OnUpdateEditorShape<RoutePart>(SetModelProperties);
OnPublished<RoutePart>((context, route) => {
Action<PublishContentContext, RoutePart> 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<RoutePart>(handler);
OnUnpublished<RoutePart>(handler);
OnRemoved<RoutePart>((context, route) => {
if (!string.IsNullOrWhiteSpace(route.Path))

View File

@@ -14,6 +14,7 @@ namespace Orchard.Blogs.Handlers {
public class BlogPartArchiveHandler : ContentHandler {
public BlogPartArchiveHandler(IRepository<BlogPartArchiveRecord> blogArchiveRepository, IBlogPostService blogPostService) {
OnPublished<BlogPostPart>((context, bp) => RecalculateBlogArchive(blogArchiveRepository, blogPostService, bp));
OnUnpublished<BlogPostPart>((context, bp) => RecalculateBlogArchive(blogArchiveRepository, blogPostService, bp));
OnRemoved<BlogPostPart>((context, bp) => RecalculateBlogArchive(blogArchiveRepository, blogPostService, bp));
}

View File

@@ -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<RoutePart>((context, route) => {
Action<PublishContentContext, RoutePart> publishedHandler = (context, route) => {
if (route.Is<BlogPart>()) {
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<RoutePart>(publishedHandler);
OnUnpublished<RoutePart>(publishedHandler);
OnGetDisplayShape<BlogPart>((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) {

View File

@@ -50,6 +50,7 @@ namespace Orchard.Blogs.Handlers {
});
OnCreated<BlogPostPart>((context, bp) => updateBlogPostCount(bp.BlogPart));
OnPublished<BlogPostPart>((context, bp) => updateBlogPostCount(bp.BlogPart));
OnUnpublished<BlogPostPart>((context, bp) => updateBlogPostCount(bp.BlogPart));
OnVersioned<BlogPostPart>((context, bp1, bp2) => updateBlogPostCount(bp2.BlogPart));
OnRemoved<BlogPostPart>((context, bp) => updateBlogPostCount(bp.BlogPart));

View File

@@ -23,6 +23,7 @@ namespace Orchard.Indexing.Handlers {
_indexNotifierHandlers = indexNotifierHandlers;
OnPublished<ContentPart>(CreateIndexingTask);
OnUnpublished<ContentPart>(CreateIndexingTask);
OnRemoved<ContentPart>(RemoveIndexingTask);
}

View File

@@ -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) {

View File

@@ -53,6 +53,14 @@ namespace Orchard.ContentManagement.Handlers {
Filters.Add(new InlineStorageFilter<TPart> { OnPublished = handler });
}
protected void OnUnpublishing<TPart>(Action<PublishContentContext, TPart> handler) where TPart : class, IContent {
Filters.Add(new InlineStorageFilter<TPart> { OnUnpublishing = handler });
}
protected void OnUnpublished<TPart>(Action<PublishContentContext, TPart> handler) where TPart : class, IContent {
Filters.Add(new InlineStorageFilter<TPart> { OnUnpublished = handler });
}
protected void OnRemoving<TPart>(Action<RemoveContentContext, TPart> handler) where TPart : class, IContent {
Filters.Add(new InlineStorageFilter<TPart> { OnRemoving = handler });
}
@@ -95,6 +103,8 @@ namespace Orchard.ContentManagement.Handlers {
public Action<VersionContentContext, TPart, TPart> OnVersioned { get; set; }
public Action<PublishContentContext, TPart> OnPublishing { get; set; }
public Action<PublishContentContext, TPart> OnPublished { get; set; }
public Action<PublishContentContext, TPart> OnUnpublishing { get; set; }
public Action<PublishContentContext, TPart> OnUnpublished { get; set; }
public Action<RemoveContentContext, TPart> OnRemoving { get; set; }
public Action<RemoveContentContext, TPart> OnRemoved { get; set; }
public Action<IndexContentContext, TPart> 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<IContentStorageFilter>())
filter.Unpublishing(context);
Unpublishing(context);
}
void IContentHandler.Unpublished(PublishContentContext context) {
foreach (var filter in Filters.OfType<IContentStorageFilter>())
filter.Unpublished(context);
Unpublished(context);
}
void IContentHandler.Removing(RemoveContentContext context) {
foreach (var filter in Filters.OfType<IContentStorageFilter>())
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) { }

View File

@@ -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) {}

View File

@@ -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);

View File

@@ -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);

View File

@@ -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<TPart>());
}
void IContentStorageFilter.Unpublishing(PublishContentContext context) {
if (context.ContentItem.Is<TPart>())
Unpublishing(context, context.ContentItem.As<TPart>());
}
void IContentStorageFilter.Unpublished(PublishContentContext context) {
if (context.ContentItem.Is<TPart>())
Unpublished(context, context.ContentItem.As<TPart>());
}
void IContentStorageFilter.Removing(RemoveContentContext context) {
if (context.ContentItem.Is<TPart>())
Removing(context, context.ContentItem.As<TPart>());