Try our conversational search powered by Generative AI!

Can't skip block properties from being imported using ImportPropertyEvent of DataImporter

Vote:
 

Hello everyone,

I use DataImporter class to import an exported page from one environment to another (TEST and DEV in my case). I need some properties to be ignored during the import because they are different for different environments. So I use ImportPropertyEvent to handle that. It works fine for page properties but it works strange when it comes to block properties on the page. By strange I mean that it works for some properties and it doesn't for the others. And I don't see any difference in those properties. Let me explain the problem more detailed with an example.

I have the following page type class:

    [ContentType(DisplayName = "Login page", GUID = "54ae5cb3-ce0f-46b7-95da-d04c610e24ae", Description = "")]
    public class LoginPage : BasePageData
    {
        [Display(Name = "Mobile bankid title", Order = 100)]
        public virtual string MobileBankIdTitle { get; set; }

        [Display(Name = "Mobile bankid link", Order = 110)]
        public virtual LinkBlock MobileBankIdLink { get; set; }
    }

Here is the LinkBlock type class:

    [ContentType(DisplayName = "Link block", GUID = "ae7ab682-1be0-4f84-a938-ce8c28305b10", Description = "", AvailableInEditMode = false)]
    public class LinkBlock : BlockData
    {
        [CultureSpecific]
        [Display(GroupName = SystemTabNames.Content, Order = 1, Name = "Link name")]
        public virtual string LinkName { get; set; }

        [CultureSpecific]
        [Display(GroupName = SystemTabNames.Content, Order = 3, Name = "Link url")]
        public virtual Url LinkUrl { get; set; }

        [CultureSpecific]
        [Display(GroupName = SystemTabNames.Content, Order = 5, Name = "Open link in new tab")]
        public virtual bool OpenLinkInNewTab { get; set; }
    }

Here is my event handler for ImportPropertyEvent:

            DataImporter.ImportPropertyEvent += (sender, args) =>
            {
                // Don't import properties that are marked to be ignored 
                if (IsToBeIgnored(args))
                {
                    // Don't do any modifications to this property and signal that its handled
                    args.IsHandled = true;
                }
            };

IsToBeIgnored method returns boolean value if property must be ignored. It doesn't come to that method and I'm not listing it here just to not overcomplicate the example.

Input argument "args" has PropertyDestination and PropertySource properties. To my understanding PropertyDestination should have old value, or rather current value on the site, and PropertySource should have new value taken from export file that is being imported. And it works like that for page properties, which is MobileBankIdTitle in this example. But when it comes to block properties it doesn't work like that in some cases. PropertyDestination for LinkName property of LinkBlock has old value as it should. But for property LinkUrl it has new imported value instead. Here is screenshots of Watch window to demonstrate what I mean:

As you can see, LinkName property works OK, source and destination values are different.

For LinkUrl property it works wrong, destination value has the same value as source. It should be "https://dev?debug=true" instead. It seems that it has been imported already. 

Long story short - I cannot have LinkUrl property being ignored during the import. It seems to be imported already when ImportPropertyEvent gets raised. And I just can't find a reason of this happening. The only difference of working and non working property is their type, which is string and Url for LinkName and LinkUrl respectively. Other than that they are the same simple properties.

Does anyone know if this is a bug or is there something special to consider when using ImportPropertyEvent that I'm not aware of?

#154845
Aug 31, 2016 11:43
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.