mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-02-09 09:16:41 +08:00
Comments,tags,localization import handlers.
--HG-- branch : dev
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
using System;
|
||||
using System.Xml;
|
||||
using JetBrains.Annotations;
|
||||
using Orchard.Comments.Models;
|
||||
@@ -14,6 +15,59 @@ namespace Orchard.Comments.Drivers {
|
||||
_contentManager = contentManager;
|
||||
}
|
||||
|
||||
protected override void Importing(CommentPart part, ContentManagement.Handlers.ImportContentContext context) {
|
||||
var author = context.Attribute(part.PartDefinition.Name, "Author");
|
||||
if (author != null) {
|
||||
part.Record.Author = author;
|
||||
}
|
||||
|
||||
var siteName = context.Attribute(part.PartDefinition.Name, "SiteName");
|
||||
if (siteName != null) {
|
||||
part.Record.SiteName = siteName;
|
||||
}
|
||||
|
||||
var userName = context.Attribute(part.PartDefinition.Name, "UserName");
|
||||
if (userName != null) {
|
||||
part.Record.UserName = userName;
|
||||
}
|
||||
|
||||
var email = context.Attribute(part.PartDefinition.Name, "Email");
|
||||
if (email != null) {
|
||||
part.Record.Email = email;
|
||||
}
|
||||
|
||||
var status = context.Attribute(part.PartDefinition.Name, "Status");
|
||||
if (status != null) {
|
||||
part.Record.Status = (CommentStatus) Enum.Parse(typeof(CommentStatus), status);
|
||||
}
|
||||
|
||||
var commentDate = context.Attribute(part.PartDefinition.Name, "CommentDateUtc");
|
||||
if (commentDate != null) {
|
||||
part.Record.CommentDateUtc = XmlConvert.ToDateTime(commentDate, XmlDateTimeSerializationMode.Utc);
|
||||
}
|
||||
|
||||
var text = context.Attribute(part.PartDefinition.Name, "CommentText");
|
||||
if (text != null) {
|
||||
part.Record.CommentText = text;
|
||||
}
|
||||
|
||||
var commentedOn = context.Attribute(part.PartDefinition.Name, "CommentedOn");
|
||||
if (commentedOn != null) {
|
||||
var contentItem = context.Session.Get(commentedOn);
|
||||
if (contentItem != null) {
|
||||
part.Record.CommentedOn = contentItem.Id;
|
||||
}
|
||||
}
|
||||
|
||||
var commentedOnContainer = context.Attribute(part.PartDefinition.Name, "CommentedOnContainer");
|
||||
if (commentedOnContainer != null) {
|
||||
var container = context.Session.Get(commentedOnContainer);
|
||||
if (container != null) {
|
||||
part.Record.CommentedOnContainer = container.Id;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected override void Exporting(CommentPart part, ContentManagement.Handlers.ExportContentContext context) {
|
||||
context.Element(part.PartDefinition.Name).SetAttributeValue("Author", part.Record.Author);
|
||||
context.Element(part.PartDefinition.Name).SetAttributeValue("SiteName", part.Record.SiteName);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using JetBrains.Annotations;
|
||||
using System;
|
||||
using JetBrains.Annotations;
|
||||
using Orchard.Comments.Models;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.ContentManagement.Drivers;
|
||||
@@ -30,6 +31,18 @@ namespace Orchard.Comments.Drivers {
|
||||
return Editor(part, shapeHelper);
|
||||
}
|
||||
|
||||
protected override void Importing(CommentsPart part, ContentManagement.Handlers.ImportContentContext context) {
|
||||
var commentsShown = context.Attribute(part.PartDefinition.Name, "CommentsShown");
|
||||
if (commentsShown != null) {
|
||||
part.CommentsShown = Convert.ToBoolean(commentsShown);
|
||||
}
|
||||
|
||||
var commentsActive = context.Attribute(part.PartDefinition.Name, "CommentsActive");
|
||||
if (commentsActive != null) {
|
||||
part.CommentsActive = Convert.ToBoolean(commentsActive);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void Exporting(CommentsPart part, ContentManagement.Handlers.ExportContentContext context) {
|
||||
context.Element(part.PartDefinition.Name).SetAttributeValue("CommentsShown", part.CommentsShown);
|
||||
context.Element(part.PartDefinition.Name).SetAttributeValue("CommentsActive", part.CommentsActive);
|
||||
|
||||
@@ -78,6 +78,27 @@ namespace Orchard.Localization.Drivers {
|
||||
}).ToList();
|
||||
}
|
||||
|
||||
protected override void Importing(LocalizationPart part, ContentManagement.Handlers.ImportContentContext context) {
|
||||
var masterContentItem = context.Attribute(part.PartDefinition.Name, "MasterContentItem");
|
||||
if (masterContentItem != null) {
|
||||
var contentItem = context.Session.Get(masterContentItem);
|
||||
if (contentItem != null) {
|
||||
part.MasterContentItem = contentItem;
|
||||
}
|
||||
}
|
||||
|
||||
var culture = context.Attribute(part.PartDefinition.Name, "Culture");
|
||||
if (culture != null) {
|
||||
var targetCulture = _cultureManager.GetCultureByName(culture);
|
||||
// Add Culture.
|
||||
if (targetCulture == null && _cultureManager.IsValidCulture(culture)) {
|
||||
_cultureManager.AddCulture(culture);
|
||||
targetCulture = _cultureManager.GetCultureByName(culture);
|
||||
}
|
||||
part.Culture = targetCulture;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void Exporting(LocalizationPart part, ContentManagement.Handlers.ExportContentContext context) {
|
||||
if (part.MasterContentItem != null) {
|
||||
var masterContentItemIdentity = _contentManager.GetItemMetadata(part.MasterContentItem).Identity;
|
||||
|
||||
@@ -59,6 +59,18 @@ namespace Orchard.Tags.Drivers {
|
||||
};
|
||||
}
|
||||
|
||||
protected override void Importing(TagsPart part, ImportContentContext context) {
|
||||
var tagString = context.Attribute(part.PartDefinition.Name, "Tags");
|
||||
if (tagString != null) {
|
||||
var tags = tagString.Split(new[] {","}, StringSplitOptions.RemoveEmptyEntries);
|
||||
// Merge tags.
|
||||
if (tags.Length > 0) {
|
||||
var currentTags = part.CurrentTags.Select(t => t.TagName);
|
||||
_tagService.UpdateTagsForContentItem(context.ContentItem, tags.Concat(currentTags));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected override void Exporting(TagsPart part, ExportContentContext context) {
|
||||
context.Element(part.PartDefinition.Name).SetAttributeValue("Tags", String.Join(",", part.CurrentTags.Select(t => t.TagName)));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user