diff --git a/src/Orchard/ContentManagement/DefaultContentManager.cs b/src/Orchard/ContentManagement/DefaultContentManager.cs index 9d4e9aeb7..506507402 100644 --- a/src/Orchard/ContentManagement/DefaultContentManager.cs +++ b/src/Orchard/ContentManagement/DefaultContentManager.cs @@ -525,7 +525,15 @@ namespace Orchard.ContentManagement { } public dynamic UpdateEditor(IContent content, IUpdateModel updater, string groupId = "") { - return _contentDisplay.Value.UpdateEditor(content, updater, groupId); + var context = new UpdateContentContext(content.ContentItem); + + Handlers.Invoke(handler => handler.Updating(context), Logger); + + var result = _contentDisplay.Value.UpdateEditor(content, updater, groupId); + + Handlers.Invoke(handler => handler.Updated(context), Logger); + + return result; } public IContentQuery Query() { diff --git a/src/Orchard/ContentManagement/Handlers/ContentHandler.cs b/src/Orchard/ContentManagement/Handlers/ContentHandler.cs index 1fd7d10f1..eae8e82c2 100644 --- a/src/Orchard/ContentManagement/Handlers/ContentHandler.cs +++ b/src/Orchard/ContentManagement/Handlers/ContentHandler.cs @@ -37,6 +37,14 @@ namespace Orchard.ContentManagement.Handlers { Filters.Add(new InlineStorageFilter { OnLoaded = handler }); } + protected void OnUpdating(Action handler) where TPart : class, IContent { + Filters.Add(new InlineStorageFilter { OnUpdating = handler }); + } + + protected void OnUpdated(Action handler) where TPart : class, IContent { + Filters.Add(new InlineStorageFilter { OnUpdated = handler }); + } + protected void OnVersioning(Action handler) where TPart : class, IContent { Filters.Add(new InlineStorageFilter { OnVersioning = handler }); } @@ -99,6 +107,8 @@ namespace Orchard.ContentManagement.Handlers { public Action OnCreated { get; set; } public Action OnLoading { get; set; } public Action OnLoaded { get; set; } + public Action OnUpdating { get; set; } + public Action OnUpdated { get; set; } public Action OnVersioning { get; set; } public Action OnVersioned { get; set; } public Action OnPublishing { get; set; } @@ -127,6 +137,12 @@ namespace Orchard.ContentManagement.Handlers { protected override void Loaded(LoadContentContext context, TPart instance) { if (OnLoaded != null) OnLoaded(context, instance); } + protected override void Updating(UpdateContentContext context, TPart instance) { + if (OnUpdating != null) OnUpdating(context, instance); + } + protected override void Updated(UpdateContentContext context, TPart instance) { + if (OnUpdated != null) OnUpdated(context, instance); + } protected override void Versioning(VersionContentContext context, TPart existing, TPart building) { if (OnVersioning != null) OnVersioning(context, existing, building); } @@ -223,6 +239,18 @@ namespace Orchard.ContentManagement.Handlers { Loaded(context); } + void IContentHandler.Updating(UpdateContentContext context) { + foreach (var filter in Filters.OfType()) + filter.Updating(context); + Updating(context); + } + + void IContentHandler.Updated(UpdateContentContext context) { + foreach (var filter in Filters.OfType()) + filter.Updated(context); + Updated(context); + } + void IContentHandler.Versioning(VersionContentContext context) { foreach (var filter in Filters.OfType()) filter.Versioning(context); @@ -331,6 +359,9 @@ namespace Orchard.ContentManagement.Handlers { protected virtual void Loading(LoadContentContext context) { } protected virtual void Loaded(LoadContentContext context) { } + protected virtual void Updating(UpdateContentContext context) { } + protected virtual void Updated(UpdateContentContext context) { } + protected virtual void Versioning(VersionContentContext context) { } protected virtual void Versioned(VersionContentContext context) { } diff --git a/src/Orchard/ContentManagement/Handlers/ContentHandlerBase.cs b/src/Orchard/ContentManagement/Handlers/ContentHandlerBase.cs index 9b3558687..a5b3c344c 100644 --- a/src/Orchard/ContentManagement/Handlers/ContentHandlerBase.cs +++ b/src/Orchard/ContentManagement/Handlers/ContentHandlerBase.cs @@ -7,7 +7,9 @@ public virtual void Created(CreateContentContext context) {} public virtual void Loading(LoadContentContext context) {} public virtual void Loaded(LoadContentContext context) {} - public virtual void Versioning(VersionContentContext context) {} + public virtual void Updating(UpdateContentContext context) { } + public virtual void Updated(UpdateContentContext context) { } + public virtual void Versioning(VersionContentContext context) { } public virtual void Versioned(VersionContentContext context) {} public virtual void Publishing(PublishContentContext context) {} public virtual void Published(PublishContentContext context) {} diff --git a/src/Orchard/ContentManagement/Handlers/IContentHandler.cs b/src/Orchard/ContentManagement/Handlers/IContentHandler.cs index 04aadce92..86489de92 100644 --- a/src/Orchard/ContentManagement/Handlers/IContentHandler.cs +++ b/src/Orchard/ContentManagement/Handlers/IContentHandler.cs @@ -7,6 +7,8 @@ void Created(CreateContentContext context); void Loading(LoadContentContext context); void Loaded(LoadContentContext context); + void Updating(UpdateContentContext context); + void Updated(UpdateContentContext context); void Versioning(VersionContentContext context); void Versioned(VersionContentContext context); void Publishing(PublishContentContext context); diff --git a/src/Orchard/ContentManagement/Handlers/IContentStorageFilter.cs b/src/Orchard/ContentManagement/Handlers/IContentStorageFilter.cs index 4cac591b6..078f36e88 100644 --- a/src/Orchard/ContentManagement/Handlers/IContentStorageFilter.cs +++ b/src/Orchard/ContentManagement/Handlers/IContentStorageFilter.cs @@ -6,6 +6,8 @@ namespace Orchard.ContentManagement.Handlers { void Created(CreateContentContext context); void Loading(LoadContentContext context); void Loaded(LoadContentContext context); + void Updating(UpdateContentContext context); + void Updated(UpdateContentContext context); void Versioning(VersionContentContext context); void Versioned(VersionContentContext context); void Publishing(PublishContentContext context); diff --git a/src/Orchard/ContentManagement/Handlers/StorageFilterBase.cs b/src/Orchard/ContentManagement/Handlers/StorageFilterBase.cs index 81a94958f..d929218ef 100644 --- a/src/Orchard/ContentManagement/Handlers/StorageFilterBase.cs +++ b/src/Orchard/ContentManagement/Handlers/StorageFilterBase.cs @@ -7,6 +7,8 @@ namespace Orchard.ContentManagement.Handlers { protected virtual void Created(CreateContentContext context, TPart instance) { } protected virtual void Loading(LoadContentContext context, TPart instance) { } protected virtual void Loaded(LoadContentContext context, TPart instance) { } + protected virtual void Updating(UpdateContentContext context, TPart instance) { } + protected virtual void Updated(UpdateContentContext context, TPart instance) { } protected virtual void Versioning(VersionContentContext context, TPart existing, TPart building) { } protected virtual void Versioned(VersionContentContext context, TPart existing, TPart building) { } protected virtual void Publishing(PublishContentContext context, TPart instance) { } @@ -49,6 +51,16 @@ namespace Orchard.ContentManagement.Handlers { Loaded(context, context.ContentItem.As()); } + void IContentStorageFilter.Updating(UpdateContentContext context) { + if (context.ContentItem.Is()) + Updating(context, context.ContentItem.As()); + } + + void IContentStorageFilter.Updated(UpdateContentContext context) { + if (context.ContentItem.Is()) + Updated(context, context.ContentItem.As()); + } + void IContentStorageFilter.Versioning(VersionContentContext context) { if (context.ExistingContentItem.Is() || context.BuildingContentItem.Is()) Versioning(context, context.ExistingContentItem.As(), context.BuildingContentItem.As()); diff --git a/src/Orchard/ContentManagement/Handlers/UpdateContentContext.cs b/src/Orchard/ContentManagement/Handlers/UpdateContentContext.cs new file mode 100644 index 000000000..8ec993e8f --- /dev/null +++ b/src/Orchard/ContentManagement/Handlers/UpdateContentContext.cs @@ -0,0 +1,11 @@ +using Orchard.ContentManagement.Records; + +namespace Orchard.ContentManagement.Handlers { + public class UpdateContentContext : ContentContextBase { + public UpdateContentContext(ContentItem contentItem) : base(contentItem) { + UpdatingItemVersionRecord = contentItem.VersionRecord; + } + + public ContentItemVersionRecord UpdatingItemVersionRecord { get; set; } + } +} \ No newline at end of file diff --git a/src/Orchard/Orchard.Framework.csproj b/src/Orchard/Orchard.Framework.csproj index e44a14e03..f2edb5ad0 100644 --- a/src/Orchard/Orchard.Framework.csproj +++ b/src/Orchard/Orchard.Framework.csproj @@ -166,6 +166,7 @@ +