From e18c962e04b8c0a7e76e9014313068f2517ce250 Mon Sep 17 00:00:00 2001 From: rpaquay Date: Sun, 24 Jan 2010 21:58:37 +0000 Subject: [PATCH] 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 --- .../Packages/Orchard.Blogs/Models/BlogPostHandler.cs | 7 +------ .../Packages/Orchard.Pages/Controllers/AdminController.cs | 4 +++- .../Packages/Orchard.Pages/Models/PageHandler.cs | 6 +----- src/Orchard/ContentManagement/Handlers/StorageFilter.cs | 7 ++++++- 4 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/Orchard.Web/Packages/Orchard.Blogs/Models/BlogPostHandler.cs b/src/Orchard.Web/Packages/Orchard.Blogs/Models/BlogPostHandler.cs index abd6d1783..f18475689 100644 --- a/src/Orchard.Web/Packages/Orchard.Blogs/Models/BlogPostHandler.cs +++ b/src/Orchard.Web/Packages/Orchard.Blogs/Models/BlogPostHandler.cs @@ -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 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>(BlogPostDriver.ContentType.Name)); Filters.Add(new ActivatingFilter(BlogPostDriver.ContentType.Name)); Filters.Add(new ActivatingFilter(BlogPostDriver.ContentType.Name)); - Filters.Add(StorageFilter.For(commonRepository)); Action updateBlogPostCount = (blog => { diff --git a/src/Orchard.Web/Packages/Orchard.Pages/Controllers/AdminController.cs b/src/Orchard.Web/Packages/Orchard.Pages/Controllers/AdminController.cs index 2130d37b0..551084222 100644 --- a/src/Orchard.Web/Packages/Orchard.Pages/Controllers/AdminController.cs +++ b/src/Orchard.Web/Packages/Orchard.Pages/Controllers/AdminController.cs @@ -132,7 +132,9 @@ namespace Orchard.Pages.Controllers { } } - model.Page = Services.ContentManager.UpdateEditorModel(Services.ContentManager.New("page"), this); + var page = Services.ContentManager.New("page"); + model.Page = Services.ContentManager.UpdateEditorModel(page, this); + if (!publishNow && publishDate != null) model.Page.Item.Published = publishDate.Value; diff --git a/src/Orchard.Web/Packages/Orchard.Pages/Models/PageHandler.cs b/src/Orchard.Web/Packages/Orchard.Pages/Models/PageHandler.cs index cbd8d0e4e..4999dab84 100644 --- a/src/Orchard.Web/Packages/Orchard.Pages/Models/PageHandler.cs +++ b/src/Orchard.Web/Packages/Orchard.Pages/Models/PageHandler.cs @@ -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 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>(PageDriver.ContentType.Name)); Filters.Add(new ActivatingFilter(PageDriver.ContentType.Name)); Filters.Add(new ActivatingFilter(PageDriver.ContentType.Name)); - Filters.Add(StorageFilter.For(commonRepository)); OnPublished((context, p) => ProcessSlug(p)); } diff --git a/src/Orchard/ContentManagement/Handlers/StorageFilter.cs b/src/Orchard/ContentManagement/Handlers/StorageFilter.cs index 65f7ab70b..2abdc5efe 100644 --- a/src/Orchard/ContentManagement/Handlers/StorageFilter.cs +++ b/src/Orchard/ContentManagement/Handlers/StorageFilter.cs @@ -19,7 +19,7 @@ namespace Orchard.ContentManagement.Handlers { public StorageFilter(IRepository repository) { if (this.GetType() == typeof(StorageFilter) && typeof(TRecord).IsSubclassOf(typeof(ContentPartVersionRecord))) { throw new ArgumentException( - string.Format("Use {0} (or {1}.For()) for versionable record types", typeof (StorageVersionFilter<>).Name, typeof(StorageFilter).Name), + string.Format("Use {0} (or {1}.For()) 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 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).FullName)); + } instance.Record = new TRecord(); }