Adding modified by to common part

This commit is contained in:
Bing Huan Chio
2015-04-22 12:22:00 -07:00
parent 96b41fb9b7
commit df483c3a8e
4 changed files with 42 additions and 20 deletions

View File

@@ -75,7 +75,7 @@ namespace Orchard.Core.Common.Handlers {
protected bool ContentTypeWithACommonPart(string typeName) { protected bool ContentTypeWithACommonPart(string typeName) {
//Note: What about content type handlers which activate "CommonPart" in code? //Note: What about content type handlers which activate "CommonPart" in code?
var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(typeName); var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(typeName);
if (contentTypeDefinition != null) if (contentTypeDefinition != null)
return contentTypeDefinition.Parts.Any(part => part.PartDefinition.Name == "CommonPart"); return contentTypeDefinition.Parts.Any(part => part.PartDefinition.Name == "CommonPart");
@@ -97,6 +97,7 @@ namespace Orchard.Core.Common.Handlers {
part.ModifiedUtc = utcNow; part.ModifiedUtc = utcNow;
part.VersionCreatedUtc = utcNow; part.VersionCreatedUtc = utcNow;
part.VersionModifiedUtc = utcNow; part.VersionModifiedUtc = utcNow;
part.VersionModifiedBy = GetUserName();
} }
private void AssignUpdateDates(UpdateEditorContext context, CommonPart part) { private void AssignUpdateDates(UpdateEditorContext context, CommonPart part) {
@@ -104,6 +105,7 @@ namespace Orchard.Core.Common.Handlers {
part.ModifiedUtc = utcNow; part.ModifiedUtc = utcNow;
part.VersionModifiedUtc = utcNow; part.VersionModifiedUtc = utcNow;
part.VersionModifiedBy = GetUserName();
} }
private void AssignRemovingDates(RemoveContentContext context, CommonPart part) { private void AssignRemovingDates(RemoveContentContext context, CommonPart part) {
@@ -111,15 +113,17 @@ namespace Orchard.Core.Common.Handlers {
part.ModifiedUtc = utcNow; part.ModifiedUtc = utcNow;
part.VersionModifiedUtc = utcNow; part.VersionModifiedUtc = utcNow;
part.VersionModifiedBy = GetUserName();
} }
protected void AssignVersioningDates(VersionContentContext context, CommonPart existing, CommonPart building) { protected void AssignVersioningDates(VersionContentContext context, CommonPart existing, CommonPart building) {
var utcNow = _clock.UtcNow; var utcNow = _clock.UtcNow;
// assign the created date // assign the created date
building.VersionCreatedUtc = utcNow; building.VersionCreatedUtc = utcNow;
// assign modified date for the new version // assign modified date for the new version
building.VersionModifiedUtc = utcNow; building.VersionModifiedUtc = utcNow;
building.VersionModifiedBy = GetUserName();
// publish date should be null until publish method called // publish date should be null until publish method called
building.VersionPublishedUtc = null; building.VersionPublishedUtc = null;
@@ -134,7 +138,7 @@ namespace Orchard.Core.Common.Handlers {
protected void AssignPublishingDates(PublishContentContext context, CommonPart part) { protected void AssignPublishingDates(PublishContentContext context, CommonPart part) {
var utcNow = _clock.UtcNow; var utcNow = _clock.UtcNow;
part.PublishedUtc = utcNow; part.PublishedUtc = utcNow;
part.VersionPublishedUtc = utcNow; part.VersionPublishedUtc = utcNow;
} }
@@ -142,33 +146,37 @@ namespace Orchard.Core.Common.Handlers {
protected void LazyLoadHandlers(CommonPart part) { protected void LazyLoadHandlers(CommonPart part) {
// add handlers that will load content for id's just-in-time // add handlers that will load content for id's just-in-time
part.OwnerField.Loader(() => _contentManager.Get<IUser>(part.Record.OwnerId)); part.OwnerField.Loader(() => _contentManager.Get<IUser>(part.Record.OwnerId));
part.ContainerField.Loader(() => part.Record.Container == null ? null : _contentManager.Get(part.Record.Container.Id)); part.ContainerField.Loader(() => part.Record.Container == null ? null : _contentManager.Get(part.Record.Container.Id));
} }
protected static void PropertySetHandlers(ActivatedContentContext context, CommonPart part) { protected static void PropertySetHandlers(ActivatedContentContext context, CommonPart part) {
// add handlers that will update records when part properties are set // add handlers that will update records when part properties are set
part.OwnerField.Setter(user => { part.OwnerField.Setter(user => {
part.Record.OwnerId = user == null part.Record.OwnerId = user == null
? 0 ? 0
: user.ContentItem.Id; : user.ContentItem.Id;
return user; return user;
}); });
// Force call to setter if we had already set a value // Force call to setter if we had already set a value
if (part.OwnerField.Value != null) if (part.OwnerField.Value != null)
part.OwnerField.Value = part.OwnerField.Value; part.OwnerField.Value = part.OwnerField.Value;
part.ContainerField.Setter(container => { part.ContainerField.Setter(container => {
part.Record.Container = container == null part.Record.Container = container == null
? null ? null
: container.ContentItem.Record; : container.ContentItem.Record;
return container; return container;
}); });
// Force call to setter if we had already set a value // Force call to setter if we had already set a value
if (part.ContainerField.Value != null) if (part.ContainerField.Value != null)
part.ContainerField.Value = part.ContainerField.Value; part.ContainerField.Value = part.ContainerField.Value;
} }
private string GetUserName() {
var user = _authenticationService.GetAuthenticatedUser();
return (user == null) ? string.Empty : user.UserName;
}
} }
} }

View File

@@ -15,14 +15,14 @@ namespace Orchard.Core.Common {
} }
public int Create() { public int Create() {
SchemaBuilder.CreateTable("BodyPartRecord", SchemaBuilder.CreateTable("BodyPartRecord",
table => table table => table
.ContentPartVersionRecord() .ContentPartVersionRecord()
.Column<string>("Text", column => column.Unlimited()) .Column<string>("Text", column => column.Unlimited())
.Column<string>("Format") .Column<string>("Format")
); );
SchemaBuilder.CreateTable("CommonPartRecord", SchemaBuilder.CreateTable("CommonPartRecord",
table => table table => table
.ContentPartRecord() .ContentPartRecord()
.Column<int>("OwnerId") .Column<int>("OwnerId")
@@ -31,8 +31,8 @@ namespace Orchard.Core.Common {
.Column<DateTime>("ModifiedUtc") .Column<DateTime>("ModifiedUtc")
.Column<int>("Container_id") .Column<int>("Container_id")
); );
SchemaBuilder.CreateTable("CommonPartVersionRecord", SchemaBuilder.CreateTable("CommonPartVersionRecord",
table => table table => table
.ContentPartVersionRecord() .ContentPartVersionRecord()
.Column<DateTime>("CreatedUtc") .Column<DateTime>("CreatedUtc")
@@ -99,13 +99,17 @@ namespace Orchard.Core.Common {
foreach (var existingIdentityPart in existingIdentityParts) { foreach (var existingIdentityPart in existingIdentityParts) {
var updateIdentityPartRecord = _identityPartRepository.Get(existingIdentityPart.Id); var updateIdentityPartRecord = _identityPartRepository.Get(existingIdentityPart.Id);
updateIdentityPartRecord.Identifier = existingIdentityPart.Identifier; updateIdentityPartRecord.Identifier = existingIdentityPart.Identifier;
_identityPartRepository.Update(updateIdentityPartRecord); _identityPartRepository.Update(updateIdentityPartRecord);
} }
return 4; return 4;
} }
public int UpdateFrom4() {
SchemaBuilder.AlterTable("CommonPartVersionRecord", table => table.AddColumn<string>("ModifiedBy", command => command.Nullable()));
return 5;
}
} }
} }

View File

@@ -54,6 +54,15 @@ namespace Orchard.Core.Common.Models {
PartVersionRecord.CreatedUtc = value; PartVersionRecord.CreatedUtc = value;
} }
} }
public string VersionModifiedBy {
get {
return PartVersionRecord == null ? null : PartVersionRecord.ModifiedBy;
}
set {
if (PartVersionRecord != null)
PartVersionRecord.ModifiedBy = value;
}
}
public DateTime? VersionPublishedUtc { public DateTime? VersionPublishedUtc {
get { get {

View File

@@ -6,5 +6,6 @@ namespace Orchard.Core.Common.Models {
public virtual DateTime? CreatedUtc { get; set; } public virtual DateTime? CreatedUtc { get; set; }
public virtual DateTime? PublishedUtc { get; set; } public virtual DateTime? PublishedUtc { get; set; }
public virtual DateTime? ModifiedUtc { get; set; } public virtual DateTime? ModifiedUtc { get; set; }
public virtual string ModifiedBy { get; set; }
} }
} }