From a361ad263ebc06311651fc901583f2f729ae413e Mon Sep 17 00:00:00 2001 From: Sebastien Ros Date: Thu, 1 Mar 2012 12:06:16 -0800 Subject: [PATCH] #18505: Fields could not be imported in setup recipes Work Item: 18505 --HG-- branch : 1.x --- .../Comments/Services/CommentServiceTests.cs | 5 +++ .../DefaultContentManager.cs | 33 ++++++++++++++----- 2 files changed, 29 insertions(+), 9 deletions(-) diff --git a/src/Orchard.Tests.Modules/Comments/Services/CommentServiceTests.cs b/src/Orchard.Tests.Modules/Comments/Services/CommentServiceTests.cs index d4ce1ea96..bfe276efc 100644 --- a/src/Orchard.Tests.Modules/Comments/Services/CommentServiceTests.cs +++ b/src/Orchard.Tests.Modules/Comments/Services/CommentServiceTests.cs @@ -91,6 +91,7 @@ namespace Orchard.Tests.Modules.Comments.Services { } + _contentManager.Flush(); Assert.That(_commentService.GetComments().Count(), Is.EqualTo(12)); } @@ -180,11 +181,15 @@ namespace Orchard.Tests.Modules.Comments.Services { commentIds[i] = commentedItem.As().Id; } + _contentManager.Flush(); Assert.That(_commentService.GetComments().Count(), Is.EqualTo(12)); for (int i = 0; i < 12; i++) { _commentService.DeleteComment(commentIds[i]); } + + _contentManager.Flush(); + Assert.That(_commentService.GetComments().Count(), Is.EqualTo(0)); } } diff --git a/src/Orchard/ContentManagement/DefaultContentManager.cs b/src/Orchard/ContentManagement/DefaultContentManager.cs index e4297faa1..f5e6f4e7a 100644 --- a/src/Orchard/ContentManagement/DefaultContentManager.cs +++ b/src/Orchard/ContentManagement/DefaultContentManager.cs @@ -439,15 +439,18 @@ namespace Orchard.ContentManagement { } public virtual void Create(ContentItem contentItem, VersionOptions options) { - // produce root record to determine the model id - contentItem.VersionRecord = new ContentItemVersionRecord { - ContentItemRecord = new ContentItemRecord { - ContentType = AcquireContentTypeRecord(contentItem.ContentType) - }, - Number = 1, - Latest = true, - Published = true - }; + if (contentItem.VersionRecord == null) { + // produce root record to determine the model id + contentItem.VersionRecord = new ContentItemVersionRecord { + ContentItemRecord = new ContentItemRecord { + ContentType = AcquireContentTypeRecord(contentItem.ContentType) + }, + Number = 1, + Latest = true, + Published = true + }; + } + // add to the collection manually for the created case contentItem.VersionRecord.ContentItemRecord.Versions.Add(contentItem.VersionRecord); @@ -574,6 +577,18 @@ namespace Orchard.ContentManagement { } } + // create a version record if import handlers need it + if(item.VersionRecord == null) { + item.VersionRecord = new ContentItemVersionRecord { + ContentItemRecord = new ContentItemRecord { + ContentType = AcquireContentTypeRecord(item.ContentType) + }, + Number = 1, + Latest = true, + Published = true + }; + } + importContentSession.Store(identity, item); var context = new ImportContentContext(item, element, importContentSession);