11

Resolved

Projection Part import/export issue

description

see https://orchard.codeplex.com/workitem/19687

The fix is not enough, when LayoutIndex is exported as -1, which happened in my case when the query had no layouts.

The code piece in release 1.7 is as follows:
        protected override void Imported(ProjectionPart part, ImportContentContext context) {
            // assign the query only when everythin is imported
            var query = context.Attribute(part.PartDefinition.Name, "Query");
            if (query != null) {
                part.Record.QueryPartRecord = context.GetItemFromSession(query).As<QueryPart>().Record;
                var layoutIndex = context.Attribute(part.PartDefinition.Name, "LayoutIndex");
                int layoutIndexValue;
                if (layoutIndex != null 
                    && Int32.TryParse(layoutIndex, out layoutIndexValue) 
                    && part.Record.QueryPartRecord.Layouts.Count >= layoutIndexValue + 1) {
                    part.Record.LayoutRecord = part.Record.QueryPartRecord.Layouts[Int32.Parse(layoutIndex)];
                }
            }
        }
It would work if a condition to see if parsed value is non-negative, or if count/index comparison is done this way:
        protected override void Imported(ProjectionPart part, ImportContentContext context) {
            // assign the query only when everythin is imported
            var query = context.Attribute(part.PartDefinition.Name, "Query");
            if (query != null) {
                part.Record.QueryPartRecord = context.GetItemFromSession(query).As<QueryPart>().Record;
                var layoutIndex = context.Attribute(part.PartDefinition.Name, "LayoutIndex");
                int layoutIndexValue;
                if (layoutIndex != null 
                    && Int32.TryParse(layoutIndex, out layoutIndexValue)
                    && layoutIndexValue >= 0
                    && part.Record.QueryPartRecord.Layouts.Count > layoutIndexValue) {
                        part.Record.LayoutRecord = part.Record.QueryPartRecord.Layouts[layoutIndexValue];
                }
            }
        }
edit note: Non-negative check is necessary, uncommented that part.

comments

VMakaev wrote Sep 28, 2013 at 9:47 PM

Just came across the same issue here...

Znowman wrote Nov 13, 2013 at 6:43 AM

In my case, the query has a layout specified. During the import of the projectionpart after that, the layouts of the specified query are empty. So the layouts dissapears from the imported queries during the import session.

sebastienros wrote Mar 15 at 1:07 AM

Fixed in changeset ab72235c3f6d14e936a53e9195718266ac80dcee