mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
Add a "OnUnpublish" event to content handlers
Work Item: 16856 --HG-- branch : dev
This commit is contained in:
@@ -45,7 +45,9 @@ namespace Orchard.Core.Common.Handlers {
|
|||||||
OnVersioned<ContentPart<CommonPartVersionRecord>>(AssignVersioningDates);
|
OnVersioned<ContentPart<CommonPartVersionRecord>>(AssignVersioningDates);
|
||||||
|
|
||||||
OnPublishing<CommonPart>(AssignPublishingDates);
|
OnPublishing<CommonPart>(AssignPublishingDates);
|
||||||
|
OnUnpublishing<CommonPart>(AssignPublishingDates);
|
||||||
OnPublishing<ContentPart<CommonPartVersionRecord>>(AssignPublishingDates);
|
OnPublishing<ContentPart<CommonPartVersionRecord>>(AssignPublishingDates);
|
||||||
|
OnUnpublishing<ContentPart<CommonPartVersionRecord>>(AssignPublishingDates);
|
||||||
|
|
||||||
OnIndexing<CommonPart>((context, commonPart) => context.DocumentIndex
|
OnIndexing<CommonPart>((context, commonPart) => context.DocumentIndex
|
||||||
.Add("type", commonPart.ContentItem.ContentType).Store()
|
.Add("type", commonPart.ContentItem.ContentType).Store()
|
||||||
|
@@ -49,14 +49,14 @@ namespace Orchard.Core.Routable.Handlers {
|
|||||||
OnGetEditorShape<RoutePart>(SetModelProperties);
|
OnGetEditorShape<RoutePart>(SetModelProperties);
|
||||||
OnUpdateEditorShape<RoutePart>(SetModelProperties);
|
OnUpdateEditorShape<RoutePart>(SetModelProperties);
|
||||||
|
|
||||||
OnPublished<RoutePart>((context, route) => {
|
Action<PublishContentContext, RoutePart> handler = (context, route) => {
|
||||||
FinalizePath(route, context, processSlug);
|
FinalizePath(route, context, processSlug);
|
||||||
|
|
||||||
if (route.Id != 0 && route.PromoteToHomePage && _routableHomePageProvider != null) {
|
if (route.Id != 0 && route.PromoteToHomePage && _routableHomePageProvider != null) {
|
||||||
var homePageSetting = _workContextAccessor.GetContext().CurrentSite.HomePage;
|
var homePageSetting = _workContextAccessor.GetContext().CurrentSite.HomePage;
|
||||||
var currentHomePageId = !string.IsNullOrWhiteSpace(homePageSetting)
|
var currentHomePageId = !string.IsNullOrWhiteSpace(homePageSetting)
|
||||||
? _routableHomePageProvider.GetHomePageId(homePageSetting)
|
? _routableHomePageProvider.GetHomePageId(homePageSetting)
|
||||||
: 0;
|
: 0;
|
||||||
|
|
||||||
if (currentHomePageId != route.Id) {
|
if (currentHomePageId != route.Id) {
|
||||||
// reset the path on the current home page
|
// reset the path on the current home page
|
||||||
@@ -73,7 +73,9 @@ namespace Orchard.Core.Routable.Handlers {
|
|||||||
_routableService.FixContainedPaths(route);
|
_routableService.FixContainedPaths(route);
|
||||||
_routablePathConstraint.AddPath(route.Path);
|
_routablePathConstraint.AddPath(route.Path);
|
||||||
}
|
}
|
||||||
});
|
};
|
||||||
|
OnPublished<RoutePart>(handler);
|
||||||
|
OnUnpublished<RoutePart>(handler);
|
||||||
|
|
||||||
OnRemoved<RoutePart>((context, route) => {
|
OnRemoved<RoutePart>((context, route) => {
|
||||||
if (!string.IsNullOrWhiteSpace(route.Path))
|
if (!string.IsNullOrWhiteSpace(route.Path))
|
||||||
|
@@ -14,6 +14,7 @@ namespace Orchard.Blogs.Handlers {
|
|||||||
public class BlogPartArchiveHandler : ContentHandler {
|
public class BlogPartArchiveHandler : ContentHandler {
|
||||||
public BlogPartArchiveHandler(IRepository<BlogPartArchiveRecord> blogArchiveRepository, IBlogPostService blogPostService) {
|
public BlogPartArchiveHandler(IRepository<BlogPartArchiveRecord> blogArchiveRepository, IBlogPostService blogPostService) {
|
||||||
OnPublished<BlogPostPart>((context, bp) => RecalculateBlogArchive(blogArchiveRepository, blogPostService, bp));
|
OnPublished<BlogPostPart>((context, bp) => RecalculateBlogArchive(blogArchiveRepository, blogPostService, bp));
|
||||||
|
OnUnpublished<BlogPostPart>((context, bp) => RecalculateBlogArchive(blogArchiveRepository, blogPostService, bp));
|
||||||
OnRemoved<BlogPostPart>((context, bp) => RecalculateBlogArchive(blogArchiveRepository, blogPostService, bp));
|
OnRemoved<BlogPostPart>((context, bp) => RecalculateBlogArchive(blogArchiveRepository, blogPostService, bp));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,3 +1,4 @@
|
|||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Web.Routing;
|
using System.Web.Routing;
|
||||||
@@ -24,7 +25,7 @@ namespace Orchard.Blogs.Handlers {
|
|||||||
_routableHomePageProvider = homePageProviders.SingleOrDefault(p => p.GetProviderName() == RoutableHomePageProvider.Name);
|
_routableHomePageProvider = homePageProviders.SingleOrDefault(p => p.GetProviderName() == RoutableHomePageProvider.Name);
|
||||||
Filters.Add(StorageFilter.For(repository));
|
Filters.Add(StorageFilter.For(repository));
|
||||||
|
|
||||||
OnPublished<RoutePart>((context, route) => {
|
Action<PublishContentContext, RoutePart> publishedHandler = (context, route) => {
|
||||||
if (route.Is<BlogPart>()) {
|
if (route.Is<BlogPart>()) {
|
||||||
if (route.ContentItem.Id != 0 && route.PromoteToHomePage)
|
if (route.ContentItem.Id != 0 && route.PromoteToHomePage)
|
||||||
_blogSlugConstraint.AddSlug("");
|
_blogSlugConstraint.AddSlug("");
|
||||||
@@ -32,12 +33,15 @@ namespace Orchard.Blogs.Handlers {
|
|||||||
else if (route.ContentItem.Id != 0 && route.PromoteToHomePage) {
|
else if (route.ContentItem.Id != 0 && route.PromoteToHomePage) {
|
||||||
_blogSlugConstraint.RemoveSlug("");
|
_blogSlugConstraint.RemoveSlug("");
|
||||||
}
|
}
|
||||||
});
|
};
|
||||||
|
|
||||||
|
OnPublished<RoutePart>(publishedHandler);
|
||||||
|
OnUnpublished<RoutePart>(publishedHandler);
|
||||||
|
|
||||||
OnGetDisplayShape<BlogPart>((context, blog) => {
|
OnGetDisplayShape<BlogPart>((context, blog) => {
|
||||||
context.Shape.Description = blog.Description;
|
context.Shape.Description = blog.Description;
|
||||||
context.Shape.PostCount = blog.PostCount;
|
context.Shape.PostCount = blog.PostCount;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void GetItemMetadata(GetContentItemMetadataContext context) {
|
protected override void GetItemMetadata(GetContentItemMetadataContext context) {
|
||||||
|
@@ -50,6 +50,7 @@ namespace Orchard.Blogs.Handlers {
|
|||||||
});
|
});
|
||||||
OnCreated<BlogPostPart>((context, bp) => updateBlogPostCount(bp.BlogPart));
|
OnCreated<BlogPostPart>((context, bp) => updateBlogPostCount(bp.BlogPart));
|
||||||
OnPublished<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));
|
OnVersioned<BlogPostPart>((context, bp1, bp2) => updateBlogPostCount(bp2.BlogPart));
|
||||||
OnRemoved<BlogPostPart>((context, bp) => updateBlogPostCount(bp.BlogPart));
|
OnRemoved<BlogPostPart>((context, bp) => updateBlogPostCount(bp.BlogPart));
|
||||||
|
|
||||||
|
@@ -23,6 +23,7 @@ namespace Orchard.Indexing.Handlers {
|
|||||||
_indexNotifierHandlers = indexNotifierHandlers;
|
_indexNotifierHandlers = indexNotifierHandlers;
|
||||||
|
|
||||||
OnPublished<ContentPart>(CreateIndexingTask);
|
OnPublished<ContentPart>(CreateIndexingTask);
|
||||||
|
OnUnpublished<ContentPart>(CreateIndexingTask);
|
||||||
OnRemoved<ContentPart>(RemoveIndexingTask);
|
OnRemoved<ContentPart>(RemoveIndexingTask);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -228,11 +228,11 @@ namespace Orchard.ContentManagement {
|
|||||||
PublishingItemVersionRecord = null
|
PublishingItemVersionRecord = null
|
||||||
};
|
};
|
||||||
|
|
||||||
Handlers.Invoke(handler => handler.Publishing(context), Logger);
|
Handlers.Invoke(handler => handler.Unpublishing(context), Logger);
|
||||||
|
|
||||||
publishedItem.VersionRecord.Published = false;
|
publishedItem.VersionRecord.Published = false;
|
||||||
|
|
||||||
Handlers.Invoke(handler => handler.Published(context), Logger);
|
Handlers.Invoke(handler => handler.Unpublished(context), Logger);
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual void Remove(ContentItem contentItem) {
|
public virtual void Remove(ContentItem contentItem) {
|
||||||
|
@@ -53,6 +53,14 @@ namespace Orchard.ContentManagement.Handlers {
|
|||||||
Filters.Add(new InlineStorageFilter<TPart> { OnPublished = handler });
|
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 {
|
protected void OnRemoving<TPart>(Action<RemoveContentContext, TPart> handler) where TPart : class, IContent {
|
||||||
Filters.Add(new InlineStorageFilter<TPart> { OnRemoving = handler });
|
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<VersionContentContext, TPart, TPart> OnVersioned { get; set; }
|
||||||
public Action<PublishContentContext, TPart> OnPublishing { get; set; }
|
public Action<PublishContentContext, TPart> OnPublishing { get; set; }
|
||||||
public Action<PublishContentContext, TPart> OnPublished { 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> OnRemoving { get; set; }
|
||||||
public Action<RemoveContentContext, TPart> OnRemoved { get; set; }
|
public Action<RemoveContentContext, TPart> OnRemoved { get; set; }
|
||||||
public Action<IndexContentContext, TPart> OnIndexing { 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) {
|
protected override void Published(PublishContentContext context, TPart instance) {
|
||||||
if (OnPublished != null) OnPublished(context, 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) {
|
protected override void Removing(RemoveContentContext context, TPart instance) {
|
||||||
if (OnRemoving != null) OnRemoving(context, instance);
|
if (OnRemoving != null) OnRemoving(context, instance);
|
||||||
}
|
}
|
||||||
@@ -231,6 +247,18 @@ namespace Orchard.ContentManagement.Handlers {
|
|||||||
Published(context);
|
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) {
|
void IContentHandler.Removing(RemoveContentContext context) {
|
||||||
foreach (var filter in Filters.OfType<IContentStorageFilter>())
|
foreach (var filter in Filters.OfType<IContentStorageFilter>())
|
||||||
filter.Removing(context);
|
filter.Removing(context);
|
||||||
@@ -293,6 +321,9 @@ namespace Orchard.ContentManagement.Handlers {
|
|||||||
protected virtual void Publishing(PublishContentContext context) { }
|
protected virtual void Publishing(PublishContentContext context) { }
|
||||||
protected virtual void Published(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 Removing(RemoveContentContext context) { }
|
||||||
protected virtual void Removed(RemoveContentContext context) { }
|
protected virtual void Removed(RemoveContentContext context) { }
|
||||||
|
|
||||||
|
@@ -11,7 +11,9 @@
|
|||||||
public virtual void Versioned(VersionContentContext context) {}
|
public virtual void Versioned(VersionContentContext context) {}
|
||||||
public virtual void Publishing(PublishContentContext context) {}
|
public virtual void Publishing(PublishContentContext context) {}
|
||||||
public virtual void Published(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 Removed(RemoveContentContext context) {}
|
||||||
public virtual void Indexing(IndexContentContext context) {}
|
public virtual void Indexing(IndexContentContext context) {}
|
||||||
public virtual void Indexed(IndexContentContext context) {}
|
public virtual void Indexed(IndexContentContext context) {}
|
||||||
|
@@ -11,6 +11,8 @@
|
|||||||
void Versioned(VersionContentContext context);
|
void Versioned(VersionContentContext context);
|
||||||
void Publishing(PublishContentContext context);
|
void Publishing(PublishContentContext context);
|
||||||
void Published(PublishContentContext context);
|
void Published(PublishContentContext context);
|
||||||
|
void Unpublishing(PublishContentContext context);
|
||||||
|
void Unpublished(PublishContentContext context);
|
||||||
void Removing(RemoveContentContext context);
|
void Removing(RemoveContentContext context);
|
||||||
void Removed(RemoveContentContext context);
|
void Removed(RemoveContentContext context);
|
||||||
void Indexing(IndexContentContext context);
|
void Indexing(IndexContentContext context);
|
||||||
|
@@ -10,6 +10,8 @@ namespace Orchard.ContentManagement.Handlers {
|
|||||||
void Versioned(VersionContentContext context);
|
void Versioned(VersionContentContext context);
|
||||||
void Publishing(PublishContentContext context);
|
void Publishing(PublishContentContext context);
|
||||||
void Published(PublishContentContext context);
|
void Published(PublishContentContext context);
|
||||||
|
void Unpublishing(PublishContentContext context);
|
||||||
|
void Unpublished(PublishContentContext context);
|
||||||
void Removing(RemoveContentContext context);
|
void Removing(RemoveContentContext context);
|
||||||
void Removed(RemoveContentContext context);
|
void Removed(RemoveContentContext context);
|
||||||
void Indexing(IndexContentContext context);
|
void Indexing(IndexContentContext context);
|
||||||
|
@@ -11,6 +11,8 @@ namespace Orchard.ContentManagement.Handlers {
|
|||||||
protected virtual void Versioned(VersionContentContext context, TPart existing, TPart building) { }
|
protected virtual void Versioned(VersionContentContext context, TPart existing, TPart building) { }
|
||||||
protected virtual void Publishing(PublishContentContext context, TPart instance) { }
|
protected virtual void Publishing(PublishContentContext context, TPart instance) { }
|
||||||
protected virtual void Published(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 Removing(RemoveContentContext context, TPart instance) { }
|
||||||
protected virtual void Removed(RemoveContentContext context, TPart instance) { }
|
protected virtual void Removed(RemoveContentContext context, TPart instance) { }
|
||||||
protected virtual void Indexing(IndexContentContext 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>());
|
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) {
|
void IContentStorageFilter.Removing(RemoveContentContext context) {
|
||||||
if (context.ContentItem.Is<TPart>())
|
if (context.ContentItem.Is<TPart>())
|
||||||
Removing(context, context.ContentItem.As<TPart>());
|
Removing(context, context.ContentItem.As<TPart>());
|
||||||
|
Reference in New Issue
Block a user