mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
Adding modified by to common part
This commit is contained in:
@@ -75,7 +75,7 @@ namespace Orchard.Core.Common.Handlers {
|
||||
protected bool ContentTypeWithACommonPart(string typeName) {
|
||||
//Note: What about content type handlers which activate "CommonPart" in code?
|
||||
var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(typeName);
|
||||
|
||||
|
||||
if (contentTypeDefinition != null)
|
||||
return contentTypeDefinition.Parts.Any(part => part.PartDefinition.Name == "CommonPart");
|
||||
|
||||
@@ -97,6 +97,7 @@ namespace Orchard.Core.Common.Handlers {
|
||||
part.ModifiedUtc = utcNow;
|
||||
part.VersionCreatedUtc = utcNow;
|
||||
part.VersionModifiedUtc = utcNow;
|
||||
part.VersionModifiedBy = GetUserName();
|
||||
}
|
||||
|
||||
private void AssignUpdateDates(UpdateEditorContext context, CommonPart part) {
|
||||
@@ -104,6 +105,7 @@ namespace Orchard.Core.Common.Handlers {
|
||||
|
||||
part.ModifiedUtc = utcNow;
|
||||
part.VersionModifiedUtc = utcNow;
|
||||
part.VersionModifiedBy = GetUserName();
|
||||
}
|
||||
|
||||
private void AssignRemovingDates(RemoveContentContext context, CommonPart part) {
|
||||
@@ -111,15 +113,17 @@ namespace Orchard.Core.Common.Handlers {
|
||||
|
||||
part.ModifiedUtc = utcNow;
|
||||
part.VersionModifiedUtc = utcNow;
|
||||
part.VersionModifiedBy = GetUserName();
|
||||
}
|
||||
|
||||
protected void AssignVersioningDates(VersionContentContext context, CommonPart existing, CommonPart building) {
|
||||
var utcNow = _clock.UtcNow;
|
||||
|
||||
// assign the created date
|
||||
// assign the created date
|
||||
building.VersionCreatedUtc = utcNow;
|
||||
// assign modified date for the new version
|
||||
building.VersionModifiedUtc = utcNow;
|
||||
building.VersionModifiedBy = GetUserName();
|
||||
// publish date should be null until publish method called
|
||||
building.VersionPublishedUtc = null;
|
||||
|
||||
@@ -134,7 +138,7 @@ namespace Orchard.Core.Common.Handlers {
|
||||
|
||||
protected void AssignPublishingDates(PublishContentContext context, CommonPart part) {
|
||||
var utcNow = _clock.UtcNow;
|
||||
|
||||
|
||||
part.PublishedUtc = utcNow;
|
||||
part.VersionPublishedUtc = utcNow;
|
||||
}
|
||||
@@ -142,33 +146,37 @@ namespace Orchard.Core.Common.Handlers {
|
||||
protected void LazyLoadHandlers(CommonPart part) {
|
||||
// add handlers that will load content for id's just-in-time
|
||||
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) {
|
||||
// add handlers that will update records when part properties are set
|
||||
|
||||
part.OwnerField.Setter(user => {
|
||||
part.Record.OwnerId = user == null
|
||||
? 0
|
||||
: user.ContentItem.Id;
|
||||
return user;
|
||||
});
|
||||
part.Record.OwnerId = user == null
|
||||
? 0
|
||||
: user.ContentItem.Id;
|
||||
return user;
|
||||
});
|
||||
|
||||
// Force call to setter if we had already set a value
|
||||
if (part.OwnerField.Value != null)
|
||||
part.OwnerField.Value = part.OwnerField.Value;
|
||||
|
||||
part.ContainerField.Setter(container => {
|
||||
part.Record.Container = container == null
|
||||
? null
|
||||
: container.ContentItem.Record;
|
||||
return container;
|
||||
});
|
||||
part.Record.Container = container == null
|
||||
? null
|
||||
: container.ContentItem.Record;
|
||||
return container;
|
||||
});
|
||||
|
||||
// Force call to setter if we had already set a value
|
||||
if (part.ContainerField.Value != null)
|
||||
part.ContainerField.Value = part.ContainerField.Value;
|
||||
}
|
||||
private string GetUserName() {
|
||||
var user = _authenticationService.GetAuthenticatedUser();
|
||||
return (user == null) ? string.Empty : user.UserName;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -15,14 +15,14 @@ namespace Orchard.Core.Common {
|
||||
}
|
||||
|
||||
public int Create() {
|
||||
SchemaBuilder.CreateTable("BodyPartRecord",
|
||||
SchemaBuilder.CreateTable("BodyPartRecord",
|
||||
table => table
|
||||
.ContentPartVersionRecord()
|
||||
.Column<string>("Text", column => column.Unlimited())
|
||||
.Column<string>("Format")
|
||||
);
|
||||
|
||||
SchemaBuilder.CreateTable("CommonPartRecord",
|
||||
SchemaBuilder.CreateTable("CommonPartRecord",
|
||||
table => table
|
||||
.ContentPartRecord()
|
||||
.Column<int>("OwnerId")
|
||||
@@ -31,8 +31,8 @@ namespace Orchard.Core.Common {
|
||||
.Column<DateTime>("ModifiedUtc")
|
||||
.Column<int>("Container_id")
|
||||
);
|
||||
|
||||
SchemaBuilder.CreateTable("CommonPartVersionRecord",
|
||||
|
||||
SchemaBuilder.CreateTable("CommonPartVersionRecord",
|
||||
table => table
|
||||
.ContentPartVersionRecord()
|
||||
.Column<DateTime>("CreatedUtc")
|
||||
@@ -99,13 +99,17 @@ namespace Orchard.Core.Common {
|
||||
|
||||
foreach (var existingIdentityPart in existingIdentityParts) {
|
||||
var updateIdentityPartRecord = _identityPartRepository.Get(existingIdentityPart.Id);
|
||||
|
||||
|
||||
updateIdentityPartRecord.Identifier = existingIdentityPart.Identifier;
|
||||
|
||||
|
||||
_identityPartRepository.Update(updateIdentityPartRecord);
|
||||
}
|
||||
|
||||
return 4;
|
||||
}
|
||||
public int UpdateFrom4() {
|
||||
SchemaBuilder.AlterTable("CommonPartVersionRecord", table => table.AddColumn<string>("ModifiedBy", command => command.Nullable()));
|
||||
return 5;
|
||||
}
|
||||
}
|
||||
}
|
@@ -54,6 +54,15 @@ namespace Orchard.Core.Common.Models {
|
||||
PartVersionRecord.CreatedUtc = value;
|
||||
}
|
||||
}
|
||||
public string VersionModifiedBy {
|
||||
get {
|
||||
return PartVersionRecord == null ? null : PartVersionRecord.ModifiedBy;
|
||||
}
|
||||
set {
|
||||
if (PartVersionRecord != null)
|
||||
PartVersionRecord.ModifiedBy = value;
|
||||
}
|
||||
}
|
||||
|
||||
public DateTime? VersionPublishedUtc {
|
||||
get {
|
||||
|
@@ -6,5 +6,6 @@ namespace Orchard.Core.Common.Models {
|
||||
public virtual DateTime? CreatedUtc { get; set; }
|
||||
public virtual DateTime? PublishedUtc { get; set; }
|
||||
public virtual DateTime? ModifiedUtc { get; set; }
|
||||
public virtual string ModifiedBy { get; set; }
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user