mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
Added CompleteImport to IContentManager.
This makes it easier for other places that leverage the Import method to also invoke the CompleteImport method.
This commit is contained in:
@@ -202,6 +202,7 @@ namespace Orchard.Tests.ContentManagement {
|
||||
private void Import(XElement element) {
|
||||
var importContentSession = new ImportContentSession(_contentManager);
|
||||
_contentManager.Import(element, importContentSession);
|
||||
_contentManager.CompleteImport(element, importContentSession);
|
||||
}
|
||||
|
||||
private XElement CreateContentElement(string title = "Dummy", string identity = "123456789012345678901234567890ab", string version = null) {
|
||||
|
@@ -82,11 +82,7 @@ namespace Orchard.Recipes.Providers.Executors {
|
||||
|
||||
// Invoke ImportCompleted.
|
||||
BatchedInvoke(context, "ImportCompleted", (itemId, nextIdentityValue, element, importContentSession, elementDictionary) => {
|
||||
var contentItem = importContentSession.Get(itemId, VersionOptions.Latest);
|
||||
var importContentContext = new ImportContentContext(contentItem, elementDictionary[nextIdentityValue], importContentSession);
|
||||
foreach (var handler in _handlers.Value) {
|
||||
handler.ImportCompleted(importContentContext);
|
||||
}
|
||||
_orchardServices.ContentManager.CompleteImport(element, importContentSession);
|
||||
});
|
||||
}
|
||||
|
||||
|
@@ -563,11 +563,9 @@ namespace Orchard.ContentManagement {
|
||||
|
||||
public virtual ContentItem Clone(ContentItem contentItem) {
|
||||
// Mostly taken from: http://orchard.codeplex.com/discussions/396664
|
||||
var importContentSession = new ImportContentSession(this);
|
||||
|
||||
var element = Export(contentItem);
|
||||
|
||||
// If a handler prevents this element from being exported, it can't be cloned
|
||||
// If a handler prevents this element from being exported, it can't be cloned.
|
||||
if (element == null) {
|
||||
throw new InvalidOperationException("The content item couldn't be cloned because a handler prevented it from being exported.");
|
||||
}
|
||||
@@ -578,9 +576,10 @@ namespace Orchard.ContentManagement {
|
||||
var status = element.Attribute("Status");
|
||||
if (status != null) status.SetValue("Draft"); // So the copy is always a draft.
|
||||
|
||||
var importContentSession = new ImportContentSession(this);
|
||||
importContentSession.Set(copyId, element.Name.LocalName);
|
||||
|
||||
Import(element, importContentSession);
|
||||
CompleteImport(element, importContentSession);
|
||||
|
||||
return importContentSession.Get(copyId, element.Name.LocalName);
|
||||
}
|
||||
@@ -790,6 +789,26 @@ namespace Orchard.ContentManagement {
|
||||
}
|
||||
}
|
||||
|
||||
public void CompleteImport(XElement element, ImportContentSession importContentSession) {
|
||||
var elementId = element.Attribute("Id");
|
||||
if (elementId == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
var identity = elementId.Value;
|
||||
|
||||
if (String.IsNullOrWhiteSpace(identity)) {
|
||||
return;
|
||||
}
|
||||
|
||||
var item = importContentSession.Get(identity, VersionOptions.Latest, XmlConvert.DecodeName(element.Name.LocalName));
|
||||
var context = new ImportContentContext(item, element, importContentSession);
|
||||
|
||||
foreach (var handler in _handlers.Value) {
|
||||
handler.ImportCompleted(context);
|
||||
}
|
||||
}
|
||||
|
||||
public XElement Export(ContentItem contentItem) {
|
||||
var context = new ExportContentContext(contentItem, new XElement(XmlConvert.EncodeLocalName(contentItem.ContentType)));
|
||||
|
||||
|
@@ -1,5 +1,6 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Xml.Linq;
|
||||
using Orchard.ContentManagement.Handlers;
|
||||
using Orchard.ContentManagement.MetaData.Models;
|
||||
using Orchard.Indexing;
|
||||
|
||||
@@ -92,6 +93,7 @@ namespace Orchard.ContentManagement {
|
||||
|
||||
XElement Export(ContentItem contentItem);
|
||||
void Import(XElement element, ImportContentSession importContentSession);
|
||||
void CompleteImport(XElement element, ImportContentSession importContentSession);
|
||||
|
||||
/// <summary>
|
||||
/// Clears the current referenced content items
|
||||
|
Reference in New Issue
Block a user