Error when working with the Import Tool with Content Versioning

Topics: General, Troubleshooting
Feb 25, 2013 at 9:11 PM
Edited Mar 3, 2013 at 9:27 PM
When trying to update Blog Posts using the import tool I am running into two errors which I think are related

The first BlogPost always seems to update just fine. Adds a new record in the Orchard_Framework_ContentItemVersionRecord table which I would expect and the settings for latest and published are all fine. The second entry seems to throw an error. It creates a new record that has the updated content but has lost its alias. The record has the updated content and its versioning is latest and published. All Blog Posts run after this point have a different pattern that is causing me problems. The content gets updated just fine for the Publised version but it is creating 3 new records in the Orchard_Framework_ContentItemVersionRecord table. The first one it creates isn't published or latest, the second is published but not latest and the content is updated. The next record is latest but we have noticed the content is not updated.

I have also tried this against a new instance of Orchard so hopefully it will repeatable. I will first give a small sample of the XML to import into the new instance of Orachard. The only change I made when I ran it against a new instance of Orchard is that I shortened the body text.
<!--Exported from Orchard-->
<Orchard>
  <Recipe>
    <Name>Generated by Orchard.ImportExport</Name>
    <Author>admin</Author>
  </Recipe>
  <Data>
    <BlogPost Id="/alias=news\/expect-more-older-drivers-on-the-road" Status="Published">
      <BodyPart Text="Crawford Frazer&lt;br /&gt;It's no secret that Americans live longer today than at any point in our country's history. What might come as a surpr...." />
      <CommonPart Owner="/User.UserName=admin" Container="/alias=news" CreatedUtc="2010-12-08T18:19:00Z" PublishedUtc="2012-08-06T13:02:48Z" ModifiedUtc="2013-02-25T19:44:48Z" />
      <TitlePart Title="Expect more older drivers on the road" />
      <AutoroutePart Alias="news/expect-more-older-drivers-on-the-road" UseCustomPattern="false" />
      <CommentsPart CommentsShown="true" CommentsActive="true" />
      <TagsPart Tags="" />
    </BlogPost>
    <BlogPost Id="/alias=news\/leasing-a-car-the-insurance-costs-may-surprise-you" Status="Published">
      <BodyPart Text="Crawford Frazer&lt;br /&gt;After driving the same car with a dent in the front bumper for months, you may be ready to upgrade to a nicer model..... " />
      <CommonPart Owner="/User.UserName=admin" Container="/alias=news" CreatedUtc="2010-12-21T17:27:07Z" PublishedUtc="2012-08-06T13:02:48Z" ModifiedUtc="2013-02-25T19:45:29Z" />
      <TitlePart Title="Leasing a car? The insurance costs may surprise you" />
      <AutoroutePart Alias="news/leasing-a-car-the-insurance-costs-may-surprise-you" UseCustomPattern="false" />
      <CommentsPart CommentsShown="true" CommentsActive="true" />
    </BlogPost>
    <BlogPost Id="/alias=news\/how-car-modifications-can-affect-your-auto-insurance" Status="Published">
      <BodyPart Text="Crawford Frazer&lt;br /&gt;It makes sense that your car insurance premium is linked to the cost of the car. After all, if you get into an acc..." />
      <CommonPart Owner="/User.UserName=admin" Container="/alias=news" CreatedUtc="2010-12-21T17:31:49Z" PublishedUtc="2012-08-06T13:02:48Z" ModifiedUtc="2013-02-25T19:46:27Z" />
      <TitlePart Title="How car modifications can affect your auto insurance" />
      <AutoroutePart Alias="news/how-car-modifications-can-affect-your-auto-insurance" UseCustomPattern="false" />
      <CommentsPart CommentsShown="true" CommentsActive="true" />
      <TagsPart Tags="" />
    </BlogPost>
    <BlogPost Id="/alias=news\/drowsy-drivers-accidents-waiting-to-happen" Status="Published">
      <BodyPart Text="&lt;a href=&quot;/news/contributors/mary-lou-jay/&quot; rel=&quot;author&quot;&gt;Mary Lou Jay&lt;/a&gt;&lt;br /&gt;&lt;p&gt;The dangers of u..." />
      <CommonPart Owner="/User.UserName=admin" Container="/alias=news" CreatedUtc="2010-12-21T17:46:44Z" PublishedUtc="2012-08-06T13:02:48Z" ModifiedUtc="2013-02-25T19:47:24Z" />
      <TitlePart Title="Drowsy drivers: Accidents waiting to happen" />
      <AutoroutePart Alias="news/drowsy-drivers-accidents-waiting-to-happen" UseCustomPattern="false" />
      <CommentsPart CommentsShown="true" CommentsActive="true" />
      <TagsPart Tags="" />
    </BlogPost>
   </Data>
</Orchard>
I than next import my xml file to update the content above which basically just extracts the author from the story. The xml looks as follows
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<!--Imported from Author Byline-->
<Orchard>
  <Recipe>
    <Name>Generated by Author Byline Import</Name>
    <Author>AuthorByLineImport</Author>
  </Recipe>
  <Data>
    <BlogPost Id="/alias=news\/expect-more-older-drivers-on-the-road" Status="Published">
      <CommonPart Owner="/User.UserName=admin" Container="/alias=news" CreatedUtc="2010-12-08T18:19:00Z" PublishedUtc="2012-08-06T13:02:48Z" ModifiedUtc="2010-12-08T18:19:05Z" />
      <BodyPart Text="It's no secret that Americans live longer today than at any point in our country's history. What might come as a surpr...." />
    </BlogPost>
    <BlogPost Id="/alias=news\/leasing-a-car-the-insurance-costs-may-surprise-you" Status="Published">
      <CommonPart Owner="/User.UserName=admin" Container="/alias=news" CreatedUtc="2010-12-21T17:27:07Z" PublishedUtc="2012-08-06T13:02:48Z" ModifiedUtc="2010-12-21T17:27:12Z" />
      <BodyPart Text="After driving the same car with a dent in the front bumper for months, you may be ready to upgrade to a nicer model...." />  
    </BlogPost>
    <BlogPost Id="/alias=news\/how-car-modifications-can-affect-your-auto-insurance" Status="Published">
      <CommonPart Owner="/User.UserName=admin" Container="/alias=news" CreatedUtc="2010-12-21T17:31:49Z" PublishedUtc="2012-08-06T13:02:48Z" ModifiedUtc="2010-12-21T17:31:54Z" />
      <BodyPart Text="It makes sense that your car insurance premium is linked to the cost of the car. After all, if you get into an acc...." />  
    </BlogPost>
    <BlogPost Id="/alias=news\/drowsy-drivers-accidents-waiting-to-happen" Status="Published">
      <CommonPart Owner="/User.UserName=admin" Container="/alias=news" CreatedUtc="2010-12-21T17:46:44Z" PublishedUtc="2012-08-06T13:02:48Z" ModifiedUtc="2010-12-21T17:46:49Z" />
      <BodyPart Text="&lt;br /&gt;&lt;p&gt;The dangers of using a cell phone  or texting while behind the wheel have been.... " /> 
    </BlogPost>
    </Data>
</Orchard>
When you go look at the Orchard_Framework_ContentItemVersionRecord table you will find that it has created the record I talk about. I also check the content with the following SQL statement.
SELECT cir.Id, bpr.Text, apr.DisplayAlias, upr.UserName, cpr.CreatedUtc, cpr.PublishedUtc, cpr.ModifiedUtc 
FROM Orchard_Framework_ContentItemRecord cir (NOLOCK) 
JOIN Common_BodyPartRecord bpr (NOLOCK) ON bpr.ContentItemRecord_id=cir.Id 
JOIN Common_CommonPartRecord cpr (NOLOCK) ON cpr.Id=cir.id 
JOIN Orchard_Users_UserPartRecord upr (NOLOCK) ON upr.Id=cpr.OwnerId
JOIN Common_CommonPartVersionRecord cpvr (NOLOCK) ON cpvr.ContentItemRecord_id=cir.Id AND cpvr.id=bpr.id 
JOIN Orchard_Autoroute_AutoroutePartRecord apr (NOLOCK) ON apr.ContentItemRecord_id=cir.id AND apr.id=bpr.id 
JOIN Orchard_Framework_ContentTypeRecord ctr (NOLOCK) ON ctr.id=cir.ContentType_id 
JOIN Orchard_Framework_ContentItemVersionRecord civr (NOLOCK) ON civr.ContentItemRecord_id=cir.Id AND civr.id=bpr.id 
JOIN Title_TitlePartRecord tpr (NOLOCK) ON tpr.ContentItemRecord_id=cir.id AND tpr.id=bpr.id 
WHERE ctr.Name = 'BlogPost'
AND civr.Published = 1
Feb 25, 2013 at 10:42 PM
Edited Mar 3, 2013 at 9:28 PM
Before importing any of the data you have to make a Blog Post group named "News Articles" with the url "~/news".
Mar 4, 2013 at 4:35 PM
Hi BoxingMyEars -

Have you had any luck getting to the bottom of this issue? Seems to be a serious problem that renders the Import feature of Orchard useless!!!

thanks,
Bruce
Coordinator
Mar 4, 2013 at 6:00 PM
Not sure I understand what the problem is here. Is it that you need a blog to import posts into?
Mar 5, 2013 at 8:01 PM
The problem comes when using the import tool to update existing content. for the example here I create a Blog with the url "~/news" and than I import the first XML recipe. When doing this against a new instance it will add 4 new entries with the Id of 16 through 19 in the Orchard_Framework_ContentItemRecord table. If you run my SQL I provided above you will see the details of each BlogPost. You will also see that there are 4 entries in the Orchard_Framework_ContentItemVersionRecord table with all of them marked as true on the Latest and Published fields. All of this is expected and works fine. When I run the recipe to update the content is where the problems arise.

When I run the second XML recipe I am getting two inconsistencies on how the data is coming in. The first record always updates just fine, in this test case it is the one with the ID of 16. The second entry [Id 17 in this case], the content doesn't update but a new record is created [with the ID of 20] and has the updated content. This new record has lost its alias but other than that appears to be fine.

The second inconsistency I am finding deals with the last two entries [which would be Ids 18 and 19 in this test case]. From the SQL I provided the entries have appeared to update fine but the problem comes from the versions. If you look at the Orchard_Framework_ContentItemVersionRecord you will see both entries with the ID of 18 and 19 added 3 more records. One that is neither published or latest, one that is published and one that is latest. Only the published one has the updated content. The latest does not and this causes a problem because users will go back and publish the latest content and in turn undo the update being accomplished by the import tool.
Coordinator
Mar 7, 2013 at 9:28 PM
Please file a bug.