Updating the CommonPart to once again make use of the CommonPartVersionRecord

--HG--
branch : dev
This commit is contained in:
Nathan Heskew
2010-11-22 13:52:40 -08:00
parent 7b64e6f30b
commit fd802c3334
7 changed files with 70 additions and 74 deletions

View File

@@ -1,13 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Routing;
using Autofac;
using JetBrains.Annotations;
using Moq;
using NUnit.Framework;
using Orchard.ContentManagement.Aspects;
using Orchard.ContentManagement.Drivers;
using Orchard.ContentManagement.Drivers.Coordinators;
using Orchard.ContentManagement.MetaData;
using Orchard.Core.Common;
using Orchard.Core.Common.Drivers;
using Orchard.Core.Common.Handlers;
using Orchard.Core.Common.Models;
using Orchard.ContentManagement;
@@ -27,6 +31,7 @@ using Orchard.Tests.Modules;
using Orchard.Core.Common.ViewModels;
using System.Web.Mvc;
using Orchard.Tests.Stubs;
using Orchard.Themes;
namespace Orchard.Core.Tests.Common.Providers {
[TestFixture]
@@ -41,12 +46,19 @@ namespace Orchard.Core.Tests.Common.Providers {
builder.RegisterType<DefaultContentManagerSession>().As<IContentManagerSession>();
builder.RegisterType<TestHandler>().As<IContentHandler>();
builder.RegisterType<CommonPartHandler>().As<IContentHandler>();
builder.RegisterType<CommonPartDriver>().As<IContentPartDriver>();
builder.RegisterType<ContentPartDriverCoordinator>().As<IContentHandler>();
builder.RegisterType<CommonService>().As<ICommonService>();
builder.RegisterType<ScheduledTaskManager>().As<IScheduledTaskManager>();
builder.RegisterType<DefaultShapeTableManager>().As<IShapeTableManager>();
builder.RegisterType<DefaultShapeFactory>().As<IShapeFactory>();
builder.RegisterType<StubExtensionManager>().As<IExtensionManager>();
builder.RegisterInstance(new Mock<IContentDisplay>().Object);
builder.RegisterInstance(new Mock<IThemeManager>().Object);
builder.RegisterInstance(new Mock<IOrchardServices>().Object);
builder.RegisterInstance(new Mock<RequestContext>().Object);
builder.RegisterType<DefaultShapeTableManager>().As<IShapeTableManager>();
builder.RegisterType<DefaultShapeFactory>().As<IShapeFactory>();
builder.RegisterType<DefaultContentDisplay>().As<IContentDisplay>();
_authn = new Mock<IAuthenticationService>();
_authz = new Mock<IAuthorizationService>();
@@ -152,7 +164,7 @@ namespace Orchard.Core.Tests.Common.Providers {
contentManager.UpdateEditor(item.ContentItem, updater);
}
[Test, Ignore("Fix pending")]
[Test]
public void PublishingShouldFailIfOwnerIsEmpty()
{
var contentManager = _container.Resolve<IContentManager>();
@@ -222,9 +234,9 @@ namespace Orchard.Core.Tests.Common.Providers {
Assert.That(item1.CreatedUtc, Is.EqualTo(createUtc));
Assert.That(item2.CreatedUtc, Is.EqualTo(createUtc));
// both instances non-versioned dates show the most recent publish
Assert.That(item1.PublishedUtc, Is.EqualTo(publish2Utc));
Assert.That(item2.PublishedUtc, Is.EqualTo(publish2Utc));
// both instances non-versioned dates show the earliest publish date
Assert.That(item1.PublishedUtc, Is.EqualTo(publish1Utc));
Assert.That(item2.PublishedUtc, Is.EqualTo(publish1Utc));
// version1 versioned dates show create was upfront and publish was oldest
Assert.That(item1.VersionCreatedUtc, Is.EqualTo(createUtc));

View File

@@ -51,14 +51,10 @@ namespace Orchard.Core.Common.Drivers {
ContainerEditor(part, null, shapeHelper));
}
protected override DriverResult Editor(CommonPart instance, IUpdateModel updater, dynamic shapeHelper) {
// this event is hooked so the modified timestamp is changed when an edit-post occurs.
instance.ModifiedUtc = _clock.UtcNow;
instance.VersionModifiedUtc = _clock.UtcNow;
protected override DriverResult Editor(CommonPart part, IUpdateModel updater, dynamic shapeHelper) {
return Combined(
OwnerEditor(instance, updater, shapeHelper),
ContainerEditor(instance, updater, shapeHelper));
OwnerEditor(part, updater, shapeHelper),
ContainerEditor(part, updater, shapeHelper));
}
DriverResult OwnerEditor(CommonPart part, IUpdateModel updater, dynamic shapeHelper) {

View File

@@ -1,4 +1,6 @@
using System.Linq;
using JetBrains.Annotations;
using Orchard.ContentManagement.MetaData;
using Orchard.Core.Common.Models;
using Orchard.Data;
using Orchard.Localization;
@@ -13,40 +15,40 @@ namespace Orchard.Core.Common.Handlers {
private readonly IClock _clock;
private readonly IAuthenticationService _authenticationService;
private readonly IContentManager _contentManager;
private readonly IContentDefinitionManager _contentDefinitionManager;
public CommonPartHandler(
IRepository<CommonPartRecord> commonRepository,
IRepository<CommonPartVersionRecord> commonVersionRepository,
IClock clock,
IAuthenticationService authenticationService,
IContentManager contentManager) {
IContentManager contentManager,
IContentDefinitionManager contentDefinitionManager) {
_clock = clock;
_authenticationService = authenticationService;
_contentManager = contentManager;
_contentDefinitionManager = contentDefinitionManager;
T = NullLocalizer.Instance;
Filters.Add(StorageFilter.For(commonRepository));
Filters.Add(StorageFilter.For(commonVersionRepository));
Filters.Add(new ActivatingFilter<ContentPart<CommonPartVersionRecord>>(ContentTypeWithACommonPart));
OnInitializing<CommonPart>(PropertySetHandlers);
OnInitializing<CommonPart>(AssignCreatingOwner);
OnInitializing<ContentPart<CommonPartRecord>>(AssignCreatingDates);
OnInitializing<CommonPart>(AssignCreatingDates);
OnInitializing<ContentPart<CommonPartVersionRecord>>(AssignCreatingDates);
OnLoaded<CommonPart>(LazyLoadHandlers);
OnVersioning<CommonPart>(CopyOwnerAndContainer);
OnVersioned<CommonPart>(AssignVersioningDates);
OnVersioned<ContentPart<CommonPartVersionRecord>>(AssignVersioningDates);
OnPublishing<ContentPart<CommonPartRecord>>(AssignPublishingDates);
OnPublishing<CommonPart>(AssignPublishingDates);
OnPublishing<ContentPart<CommonPartVersionRecord>>(AssignPublishingDates);
//OnGetDisplayViewModel<CommonPart>();
//OnGetEditorViewModel<CommonPart>(GetEditor);
//OnUpdateEditorViewModel<CommonPart>(UpdateEditor);
OnIndexing<CommonPart>((context, commonPart) => context.DocumentIndex
.Add("type", commonPart.ContentItem.ContentType).Store()
.Add("author", commonPart.Owner.UserName).Store()
@@ -58,6 +60,9 @@ namespace Orchard.Core.Common.Handlers {
public Localizer T { get; set; }
bool ContentTypeWithACommonPart(string typeName) {
return _contentDefinitionManager.GetTypeDefinition(typeName).Parts.Any(part => part.PartDefinition.Name == "CommonPart");
}
void AssignCreatingOwner(InitializingContentContext context, CommonPart part) {
// and use the current user as Owner
@@ -66,10 +71,10 @@ namespace Orchard.Core.Common.Handlers {
}
}
void AssignCreatingDates(InitializingContentContext context, ContentPart<CommonPartRecord> part) {
void AssignCreatingDates(InitializingContentContext context, CommonPart part) {
// assign default create/modified dates
part.Record.CreatedUtc = _clock.UtcNow;
part.Record.ModifiedUtc = _clock.UtcNow;
part.CreatedUtc = _clock.UtcNow;
part.ModifiedUtc = _clock.UtcNow;
}
void AssignCreatingDates(InitializingContentContext context, ContentPart<CommonPartVersionRecord> part) {
@@ -78,22 +83,31 @@ namespace Orchard.Core.Common.Handlers {
part.Record.ModifiedUtc = _clock.UtcNow;
}
void AssignVersioningDates(VersionContentContext context, ContentPart<CommonPartVersionRecord> existing, ContentPart<CommonPartVersionRecord> building) {
// assign create/modified dates for the new version
building.Record.CreatedUtc = _clock.UtcNow;
building.Record.ModifiedUtc = _clock.UtcNow;
void AssignVersioningDates(VersionContentContext context, CommonPart existing, CommonPart building) {
// assign the created
building.CreatedUtc = existing.CreatedUtc ?? _clock.UtcNow;
// persist and published dates
building.PublishedUtc = existing.PublishedUtc;
// assign modified date for the new version
building.ModifiedUtc = _clock.UtcNow;
}
void AssignVersioningDates(VersionContentContext context, ContentPart<CommonPartVersionRecord> existing, ContentPart<CommonPartVersionRecord> building) {
// assign the created date
building.Record.CreatedUtc = _clock.UtcNow;
// assign modified date for the new version
building.Record.ModifiedUtc = _clock.UtcNow;
// publish date should be null until publish method called
building.Record.PublishedUtc = null;
}
void AssignPublishingDates(PublishContentContext context, ContentPart<CommonPartRecord> part) {
void AssignPublishingDates(PublishContentContext context, CommonPart part) {
// don't assign dates when unpublishing
if (context.PublishingItemVersionRecord == null)
return;
// assign version-agnostic publish date
part.Record.PublishedUtc = _clock.UtcNow;
// set the initial published date
part.PublishedUtc = part.PublishedUtc ?? _clock.UtcNow;
}
void AssignPublishingDates(PublishContentContext context, ContentPart<CommonPartVersionRecord> part) {
@@ -101,13 +115,8 @@ namespace Orchard.Core.Common.Handlers {
if (context.PublishingItemVersionRecord == null)
return;
// assign version-specific publish date
part.Record.PublishedUtc = _clock.UtcNow;
}
private static void CopyOwnerAndContainer(VersionContentContext c, CommonPart c1, CommonPart c2) {
c2.Owner = c1.Owner;
c2.Container = c1.Container;
// assign the version's published date
part.Record.PublishedUtc = part.Record.PublishedUtc ?? _clock.UtcNow;
}
void LazyLoadHandlers(LoadContentContext context, CommonPart part) {
@@ -120,12 +129,9 @@ namespace Orchard.Core.Common.Handlers {
// add handlers that will update records when part properties are set
part.OwnerField.Setter(user => {
if (user == null) {
part.Record.OwnerId = 0;
}
else {
part.Record.OwnerId = user.ContentItem.Id;
}
part.Record.OwnerId = user == null
? 0
: user.ContentItem.Id;
return user;
});
@@ -134,12 +140,9 @@ namespace Orchard.Core.Common.Handlers {
part.OwnerField.Value = part.OwnerField.Value;
part.ContainerField.Setter(container => {
if (container == null) {
part.Record.Container = null;
}
else {
part.Record.Container = container.ContentItem.Record;
}
part.Record.Container = container == null
? null
: container.ContentItem.Record;
return container;
});

View File

@@ -1,9 +0,0 @@
using System.Collections.Generic;
using Orchard.ContentManagement.Drivers;
using Orchard.ContentManagement.Handlers;
namespace Orchard.Core.Common.Handlers {
public class ItemReferenceContentFieldHandler : ContentFieldHandler {
public ItemReferenceContentFieldHandler(IEnumerable<IContentFieldDriver> contentFieldDrivers) : base(contentFieldDrivers) { }
}
}

View File

@@ -50,32 +50,29 @@ namespace Orchard.Core.Common.Models {
return PartVersionRecord == null ? CreatedUtc : PartVersionRecord.CreatedUtc;
}
set {
if (PartVersionRecord != null) {
if (PartVersionRecord != null)
PartVersionRecord.CreatedUtc = value;
}
}
}
public DateTime? VersionPublishedUtc {
get {
return PartVersionRecord == null ? PublishedUtc : PartVersionRecord.PublishedUtc;
}
set {
if (PartVersionRecord != null) {
if (PartVersionRecord != null)
PartVersionRecord.PublishedUtc = value;
}
}
}
public DateTime? VersionModifiedUtc {
get {
return PartVersionRecord == null ? ModifiedUtc : PartVersionRecord.ModifiedUtc;
}
set {
if (PartVersionRecord != null) {
if (PartVersionRecord != null)
PartVersionRecord.ModifiedUtc = value;
}
}
}
}
}

View File

@@ -70,6 +70,7 @@
<Reference Include="System.Xml.Linq" />
</ItemGroup>
<ItemGroup>
<Compile Include="Common\Models\CommonPartVersionRecord.cs" />
<Compile Include="Containers\Controllers\ItemController.cs" />
<Compile Include="Containers\Drivers\ContainablePartDriver.cs" />
<Compile Include="Containers\Drivers\ContainerPartDriver.cs" />
@@ -131,7 +132,6 @@
<Compile Include="Routable\IRoutablePathConstraint.cs" />
<Compile Include="Routable\Models\RoutePart.cs" />
<Compile Include="Common\Permissions.cs" />
<Compile Include="Common\Models\CommonPartVersionRecord.cs" />
<Compile Include="Common\Utilities\LazyField.cs" />
<Compile Include="Common\Handlers\CommonPartHandler.cs" />
<Compile Include="Common\Models\CommonPart.cs" />

View File

@@ -1,6 +1,5 @@
using System;
using Orchard.ContentManagement;
using Orchard.Core.Common.Models;
using Orchard.PublishLater.Models;
namespace Orchard.PublishLater.ViewModels {
@@ -30,8 +29,6 @@ namespace Orchard.PublishLater.ViewModels {
get { return IsPublished || ContentItem.ContentManager.Get(ContentItem.Id, VersionOptions.Published) != null; }
}
public DateTime? VersionPublishedUtc { get { return ContentItem.As<CommonPart>() == null ? null : ContentItem.As<CommonPart>().VersionPublishedUtc; } }
public DateTime? ScheduledPublishUtc { get; set; }
public string ScheduledPublishDate { get; set; }