Draft import support.

Fixing a bug with DraftRequired in the ContentManager.

--HG--
branch : dev
This commit is contained in:
Suha Can
2011-03-18 14:38:26 -07:00
parent c048ab2aeb
commit 30b69ed8d8
3 changed files with 38 additions and 7 deletions

View File

@@ -33,13 +33,22 @@ namespace Orchard.ImportExport.RecipeHandlers {
continue;
var identity = elementId.Value;
var status = element.Attribute("Status");
var item = importContentSession.Get(identity);
if (item == null) {
item = _orchardServices.ContentManager.New(element.Name.LocalName);
_orchardServices.ContentManager.Create(item);
importContentSession.Store(identity, item);
if (status != null && status.Value == "Draft") {
_orchardServices.ContentManager.Create(item, VersionOptions.Draft);
}
else {
_orchardServices.ContentManager.Create(item);
}
}
else {
item = _orchardServices.ContentManager.Get(item.Id, VersionOptions.DraftRequired);
}
importContentSession.Store(identity, item);
}
// Second pass to import the content items.

View File

@@ -24,6 +24,8 @@ namespace Orchard.ContentManagement {
private readonly IContentDefinitionManager _contentDefinitionManager;
private readonly Func<IContentManagerSession> _contentManagerSession;
private readonly Lazy<IContentDisplay> _contentDisplay;
private const string Published = "Published";
private const string Draft = "Draft";
public DefaultContentManager(
IComponentContext context,
@@ -127,6 +129,9 @@ namespace Orchard.ContentManagement {
// return item if obtained earlier in session
if (session.RecallVersionRecordId(versionRecord.Id, out contentItem)) {
if (options.IsDraftRequired && versionRecord.Published) {
return BuildNewVersion(contentItem);
}
return contentItem;
}
@@ -406,15 +411,22 @@ namespace Orchard.ContentManagement {
return;
var identity = elementId.Value;
var status = element.Attribute("Status");
var item = importContentSession.Get(identity);
if (item == null) {
item = New(element.Name.LocalName);
Create(item);
importContentSession.Store(identity, item);
if (status != null && status.Value == "Draft") {
Create(item, VersionOptions.Draft);
}
else {
Create(item);
}
}
else {
item = Get(item.Id, VersionOptions.DraftRequired);
}
importContentSession.Store(identity, item);
var context = new ImportContentContext(item, element, importContentSession);
foreach (var contentHandler in Handlers) {
@@ -424,7 +436,9 @@ namespace Orchard.ContentManagement {
contentHandler.Imported(context);
}
Publish(item);
if (status == null || status.Value == Published) {
Publish(item);
}
}
public XElement Export(ContentItem contentItem) {
@@ -438,8 +452,13 @@ namespace Orchard.ContentManagement {
contentHandler.Exported(context);
}
// Put version information in the id.
context.Data.SetAttributeValue("Id", GetItemMetadata(contentItem).Identity.ToString());
if (contentItem.IsPublished()) {
context.Data.SetAttributeValue("Status", Published);
}
else {
context.Data.SetAttributeValue("Status", Draft);
}
return context.Data;
}

View File

@@ -18,7 +18,7 @@ namespace Orchard.ContentManagement {
if (_dictionary.ContainsKey(contentIdentity))
return _dictionary[contentIdentity];
foreach (var item in _contentManager.Query(VersionOptions.Published).List()) {
foreach (var item in _contentManager.Query(VersionOptions.Latest).List()) {
var identity = _contentManager.GetItemMetadata(item).Identity;
var equalityComparer = new ContentIdentity.ContentIdentityEqualityComparer();
if (equalityComparer.Equals(identity, contentIdentity)) {
@@ -32,6 +32,9 @@ namespace Orchard.ContentManagement {
public void Store(string id, ContentItem item) {
var contentIdentity = new ContentIdentity(id);
if (_dictionary.ContainsKey(contentIdentity)) {
_dictionary.Remove(contentIdentity);
}
_dictionary.Add(contentIdentity, item);
}