mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-09-19 10:07:55 +08:00
Fix issues with setting proper create/update/published dates on pages/blog post
The issue was that both the Pages and BlogPost handlers were adding a StorageFilter for the CommonVersionRecord. This was already done by the CommonAspectHandler, so we ended up having 3 StorageFilter for pages and blog post content items. This lead to incorrect behavior when creating instances (the CommonVersionRecord was re-initialized 3 times). The fix is to remove the StorageFilter from BlogPost and Page. Also added a check in StorageFilter to throw an exception is this situation is be detected in the future. --HG-- extra : convert_revision : svn%3A5ff7c347-ad56-4c35-b696-ccb81de16e03/trunk%4045936
This commit is contained in:
@@ -1,7 +1,5 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using JetBrains.Annotations;
|
||||
using Orchard.Blogs.Controllers;
|
||||
using Orchard.Blogs.Services;
|
||||
using Orchard.ContentManagement;
|
||||
@@ -9,18 +7,16 @@ using Orchard.Core.Common.Models;
|
||||
using Orchard.ContentManagement.Handlers;
|
||||
using Orchard.Core.Common.Records;
|
||||
using Orchard.Core.Common.Services;
|
||||
using Orchard.Data;
|
||||
using Orchard.Localization;
|
||||
using Orchard.UI.Notify;
|
||||
|
||||
namespace Orchard.Blogs.Models {
|
||||
[UsedImplicitly]
|
||||
public class BlogPostHandler : ContentHandler {
|
||||
private readonly IBlogPostService _blogPostService;
|
||||
private readonly IRoutableService _routableService;
|
||||
private readonly IOrchardServices _orchardServices;
|
||||
|
||||
public BlogPostHandler(IRepository<CommonVersionRecord> commonRepository, IBlogPostService blogPostService, IRoutableService routableService, IOrchardServices orchardServices) {
|
||||
public BlogPostHandler(IBlogPostService blogPostService, IRoutableService routableService, IOrchardServices orchardServices) {
|
||||
_blogPostService = blogPostService;
|
||||
_routableService = routableService;
|
||||
_orchardServices = orchardServices;
|
||||
@@ -31,7 +27,6 @@ namespace Orchard.Blogs.Models {
|
||||
Filters.Add(new ActivatingFilter<ContentPart<CommonVersionRecord>>(BlogPostDriver.ContentType.Name));
|
||||
Filters.Add(new ActivatingFilter<RoutableAspect>(BlogPostDriver.ContentType.Name));
|
||||
Filters.Add(new ActivatingFilter<BodyAspect>(BlogPostDriver.ContentType.Name));
|
||||
Filters.Add(StorageFilter.For(commonRepository));
|
||||
|
||||
Action<Blog> updateBlogPostCount =
|
||||
(blog => {
|
||||
|
@@ -132,7 +132,9 @@ namespace Orchard.Pages.Controllers {
|
||||
}
|
||||
}
|
||||
|
||||
model.Page = Services.ContentManager.UpdateEditorModel(Services.ContentManager.New<Page>("page"), this);
|
||||
var page = Services.ContentManager.New<Page>("page");
|
||||
model.Page = Services.ContentManager.UpdateEditorModel(page, this);
|
||||
|
||||
if (!publishNow && publishDate != null)
|
||||
model.Page.Item.Published = publishDate.Value;
|
||||
|
||||
|
@@ -1,25 +1,22 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using JetBrains.Annotations;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.Core.Common.Records;
|
||||
using Orchard.Core.Common.Services;
|
||||
using Orchard.Localization;
|
||||
using Orchard.Pages.Controllers;
|
||||
using Orchard.Core.Common.Models;
|
||||
using Orchard.Data;
|
||||
using Orchard.ContentManagement.Handlers;
|
||||
using Orchard.Pages.Services;
|
||||
using Orchard.UI.Notify;
|
||||
|
||||
namespace Orchard.Pages.Models {
|
||||
[UsedImplicitly]
|
||||
public class PageHandler : ContentHandler {
|
||||
private readonly IPageService _pageService;
|
||||
private readonly IRoutableService _routableService;
|
||||
private readonly IOrchardServices _orchardServices;
|
||||
|
||||
public PageHandler(IRepository<CommonVersionRecord> commonRepository, IPageService pageService, IRoutableService routableService, IOrchardServices orchardServices) {
|
||||
public PageHandler(IPageService pageService, IRoutableService routableService, IOrchardServices orchardServices) {
|
||||
_pageService = pageService;
|
||||
_routableService = routableService;
|
||||
_orchardServices = orchardServices;
|
||||
@@ -30,7 +27,6 @@ namespace Orchard.Pages.Models {
|
||||
Filters.Add(new ActivatingFilter<ContentPart<CommonVersionRecord>>(PageDriver.ContentType.Name));
|
||||
Filters.Add(new ActivatingFilter<RoutableAspect>(PageDriver.ContentType.Name));
|
||||
Filters.Add(new ActivatingFilter<BodyAspect>(PageDriver.ContentType.Name));
|
||||
Filters.Add(StorageFilter.For(commonRepository));
|
||||
|
||||
OnPublished<Page>((context, p) => ProcessSlug(p));
|
||||
}
|
||||
|
@@ -19,7 +19,7 @@ namespace Orchard.ContentManagement.Handlers {
|
||||
public StorageFilter(IRepository<TRecord> repository) {
|
||||
if (this.GetType() == typeof(StorageFilter<TRecord>) && typeof(TRecord).IsSubclassOf(typeof(ContentPartVersionRecord))) {
|
||||
throw new ArgumentException(
|
||||
string.Format("Use {0} (or {1}.For<TRecord>()) for versionable record types", typeof (StorageVersionFilter<>).Name, typeof(StorageFilter).Name),
|
||||
string.Format("Use {0} (or {1}.For<TRecord>()) for versionable record types", typeof(StorageVersionFilter<>).Name, typeof(StorageFilter).Name),
|
||||
"repository");
|
||||
}
|
||||
|
||||
@@ -27,6 +27,11 @@ namespace Orchard.ContentManagement.Handlers {
|
||||
}
|
||||
|
||||
protected override void Activated(ActivatedContentContext context, ContentPart<TRecord> instance) {
|
||||
if (instance.Record != null) {
|
||||
throw new InvalidOperationException(string.Format(
|
||||
"Having more than one storage filter for a given part ({0}) is invalid.",
|
||||
typeof(ContentPart<TRecord>).FullName));
|
||||
}
|
||||
instance.Record = new TRecord();
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user