mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-01-19 17:51:45 +08:00
Adding session to import context with an utility method.
Import handlers for common and route parts. --HG-- branch : dev
This commit is contained in:
@@ -121,6 +121,33 @@ namespace Orchard.Core.Common.Drivers {
|
||||
() => shapeHelper.EditorTemplate(TemplateName: "Parts.Common.Container", Model: model, Prefix: Prefix));
|
||||
}
|
||||
|
||||
protected override void Importing(CommonPart part, ImportContentContext context) {
|
||||
var owner = context.Attribute(part.PartDefinition.Name, "Owner");
|
||||
if (owner != null) {
|
||||
part.Owner = _membershipService.GetUser(owner);
|
||||
}
|
||||
|
||||
var container = context.Attribute(part.PartDefinition.Name, "Container");
|
||||
if (container != null) {
|
||||
part.Container = context.Session.Get(container);
|
||||
}
|
||||
|
||||
var createdUtc = context.Attribute(part.PartDefinition.Name, "CreatedUtc");
|
||||
if (createdUtc != null) {
|
||||
part.CreatedUtc = XmlConvert.ToDateTime(createdUtc, XmlDateTimeSerializationMode.Utc);
|
||||
}
|
||||
|
||||
var publishedUtc = context.Attribute(part.PartDefinition.Name, "PublishedUtc");
|
||||
if (publishedUtc != null) {
|
||||
part.PublishedUtc = XmlConvert.ToDateTime(publishedUtc, XmlDateTimeSerializationMode.Utc);
|
||||
}
|
||||
|
||||
var modifiedUtc = context.Attribute(part.PartDefinition.Name, "ModifiedUtc");
|
||||
if (modifiedUtc != null) {
|
||||
part.ModifiedUtc = XmlConvert.ToDateTime(modifiedUtc, XmlDateTimeSerializationMode.Utc);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void Exporting(CommonPart part, ExportContentContext context) {
|
||||
if (part.Owner != null) {
|
||||
var ownerIdentity = _contentManager.GetItemMetadata(part.Owner).Identity;
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Xml.Linq;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.ContentManagement.Aspects;
|
||||
using Orchard.ContentManagement.Drivers;
|
||||
@@ -96,6 +95,23 @@ namespace Orchard.Core.Routable.Drivers {
|
||||
return Editor(part, shapeHelper);
|
||||
}
|
||||
|
||||
protected override void Importing(RoutePart part, ImportContentContext context) {
|
||||
var title = context.Attribute(part.PartDefinition.Name, "Title");
|
||||
if (title != null) {
|
||||
part.Title = title;
|
||||
}
|
||||
|
||||
var slug = context.Attribute(part.PartDefinition.Name, "Slug");
|
||||
if (slug != null) {
|
||||
part.Slug = slug;
|
||||
}
|
||||
|
||||
var path = context.Attribute(part.PartDefinition.Name, "Path");
|
||||
if (path != null) {
|
||||
part.Path = path;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void Exporting(RoutePart part, ExportContentContext context) {
|
||||
context.Element(part.PartDefinition.Name).SetAttributeValue("Title", part.Title);
|
||||
context.Element(part.PartDefinition.Name).SetAttributeValue("Slug", part.Slug);
|
||||
|
||||
@@ -416,7 +416,7 @@ namespace Orchard.ContentManagement {
|
||||
item = Get(item.Id, VersionOptions.DraftRequired);
|
||||
}
|
||||
|
||||
var context = new ImportContentContext(item, element);
|
||||
var context = new ImportContentContext(item, element, importContentSession);
|
||||
foreach (var contentHandler in Handlers) {
|
||||
contentHandler.Importing(context);
|
||||
}
|
||||
|
||||
@@ -3,10 +3,12 @@ using System.Xml.Linq;
|
||||
namespace Orchard.ContentManagement.Handlers {
|
||||
public class ImportContentContext : ContentContextBase {
|
||||
public XElement Data { get; set; }
|
||||
public ImportContentSession Session { get; set; }
|
||||
|
||||
public ImportContentContext(ContentItem contentItem, XElement data)
|
||||
public ImportContentContext(ContentItem contentItem, XElement data, ImportContentSession importContentSession)
|
||||
: base(contentItem) {
|
||||
Data = data;
|
||||
Session = importContentSession;
|
||||
}
|
||||
|
||||
public string Attribute(string elementName, string attributeName) {
|
||||
@@ -19,6 +21,9 @@ namespace Orchard.ContentManagement.Handlers {
|
||||
return null;
|
||||
}
|
||||
|
||||
public ContentItem GetItemFromSession(string id) {
|
||||
return Session.Get(id);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user