Import/Export not working correctly on custom content type

Topics: Writing modules
Feb 7, 2012 at 2:01 PM

Hi,

I have a custom content type "Carousel" with two parts: CommonPart and my custom part CarouselPart. I have overridden the driver class to import and export the appropriate fields and after export I see the right data in the output Xml file. When I import the file Orchard tells me it was imported successfully but my carousel data is not inserted into the database. I don't see any messages in the recipe log other than success messages. I can step through the import code and the correct values are set on the relevant part instance. It's baffling.

What could be going wrong?

Driver code:

        protected override void Exporting(CarouselPart part, Orchard.ContentManagement.Handlers.ExportContentContext context)
        {
            base.Exporting(part, context);
            context.Element(part.PartDefinition.Name).SetAttributeValue("Name",part.Name);
            context.Element(part.PartDefinition.Name).SetAttributeValue("CssStylesheetUrl", part.CssStylesheetUrl);
        }

        protected override void Importing(CarouselPart part, Orchard.ContentManagement.Handlers.ImportContentContext context)
        {
            base.Importing(part, context);
            part.Name = context.Attribute(part.PartDefinition.Name, "Name");
            part.CssStylesheetUrl = context.Attribute(part.PartDefinition.Name, "CssStylesheetUrl");
        }

Exported xml:

<!--Exported from Orchard-->
<Orchard>
  <Recipe>
    <Name>Generated by Orchard.ImportExport</Name>
    <Author>admin</Author>
  </Recipe>
  <Metadata>
    <Types>
      <Carousel ContentTypeSettings.Creatable="True" DisplayName="Carousel">
        <CommonPart />
        <CarouselPart />
      </Carousel>
    </Types>
    <Parts>
      <CommonPart ContentPartSettings.Attachable="True" />
      <CarouselPart ContentPartSettings.Attachable="True" />
    </Parts>
  </Metadata>
  <Data>
    <Carousel Id="" Status="Published">
      <CommonPart Owner="/User.UserName=admin" CreatedUtc="2011-12-02T15:30:37Z" PublishedUtc="2011-12-02T15:30:37Z" ModifiedUtc="2012-02-07T10:43:17Z" />
      <CarouselPart Name="homepage" CssStylesheetUrl="test" />
    </Carousel>
    <Carousel Id="" Status="Published">
      <CommonPart Owner="/User.UserName=admin" CreatedUtc="2012-01-25T13:02:33Z" PublishedUtc="2012-01-25T13:02:33Z" ModifiedUtc="2012-02-07T10:43:50Z" />
      <CarouselPart Name="Why Online Fundraising" CssStylesheetUrl="http://v3-staging.justgiving.com/en/SharedMedia/Default/common/css/style.css" />
    </Carousel>
  </Data>
</Orchard>

Coordinator
Feb 7, 2012 at 5:56 PM

Why are you calling base?

Feb 7, 2012 at 9:14 PM
No good reason... it makes no difference though because the base
implementation is just a return statement. Tried with and without...

A correction to my first email though - I can break into the code
during the *exporting* phase but not the *importing* phase.

On Tue, Feb 7, 2012 at 6:56 PM, bertrandleroy
<notifications@codeplex.com> wrote:
> From: bertrandleroy
>
> Why are you calling base?
>
> Read the full discussion online.
>
> To add a post to this discussion, reply to this email
> ([email removed])
>
> To start a new discussion for this project, email
> [email removed]
>
> You are receiving this email because you subscribed to this discussion on
> CodePlex. You can unsubscribe on CodePlex.com.
>
> Please note: Images and attachments will be removed from emails. Any posts
> to this discussion will also be available online at CodePlex.com
Coordinator
Feb 7, 2012 at 9:25 PM

Did you try to attach a debugger and break on all exceptions? Do you see anything in logs? Might be that something happens before it ever reaches your code.

Oh wait, I know: seems like your content type has no part that emits an id (your ids are all empty). That's probably your problem.

Feb 8, 2012 at 4:38 AM

Okay, could you point me to an example of where this is done in the orchard codebase?

On Feb 7, 2012 10:25 PM, "bertrandleroy" <notifications@codeplex.com> wrote:

From: bertrandleroy

Did you try to attach a debugger and break on all exceptions? Do you see anything in logs? Might be that something happens before it ever reaches your code.

Oh wait, I know: seems like your content type has no part that emits an id (your ids are all empty). That's probably your problem.

Read the full discussion online.

To add a post to this discussion, reply to this email (orchard@discussions.codeplex.com)

To start a new discussion for this project, email orchard@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe on CodePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at CodePlex.com

Coordinator
Feb 8, 2012 at 5:19 AM

The simplest is for you to add the IdentityPart or RoutePart to your content type. It already implements what's needed (if you're interested check out the handler for those parts).

Feb 8, 2012 at 12:41 PM

I had a similar issue: http://orchard.codeplex.com/discussions/285797

I manually added route parts, and set the identity values in my recipe, and that got the import working.