Try our conversational search powered by Generative AI!

Moving data around in your existing content types

Vote:
 

Im looking for some advice around what to do when you need to move data around in your existing content types. 

Say for instance that you have a pagetype with an image property used show an image on the top the page. 

    public class ExamplePage : SitePageData
    {
        [UIHint(UIHint.Image)]
        public virtual ContentReference ImageReference { get; set; }
    }

A new requirement might then be added after a while, that says that you should also be able to create a link with that image.

I could of couse just add a UrlProperty to the page type and change the template to render a href if the url has been set. But then i couldent edit the two properties together in "on page editing"-mode. To do that I would have to group the two properties into a block. Something like this:

    public class ExamplePage : SitePageData
    {
        public virtual ImageBlock Image { get; set; }
    }

    public class ImageBlock : BlockData
    {
        [UIHint(UIHint.Image)]
        public virtual ContentReference ImageReference { get; set; }

        public virtual Url ImageUrl { get; set; }
    }

The problem is then that I then already have a bunch of pages that has data in currentPage.ImageReference rather then currentPage.Image.ImageReference and these needs to still work of course.

How do you deal with this type of problem? In my experience most developers just add the UrlProperty to the page and tell the editors that they need to go into "form edit"-mode if they want to add a url. That solution makes me a bit sad though :)

#131944
Aug 10, 2015 15:12
Vote:
 

Hi,

If you remove the property from your model ("ImageReference"), but the content contains data for this property (editors set images before), then the property won't be removed from EPiServer database. It won't be directly accessible through you model but it will be still available under Property["propertyName"]

So you could think about migration tool. Remove ImageUrl property from the model. Then you need a custom tool in admin. In that tool you should iterate all contents with ImageReference property and assign value to the new Image block.

You will be able to access this property by content.Property["ImageReference"] (since it's not avaialable by content.ImageReference).

After you copied the data you could remove the old property programmatically (load definition from PageTypeRepository and use Delete method).

There is also buildin EPiServer migration system, but I'm not sure if it's fits your requirements.

#131948
Aug 10, 2015 16:03
Vote:
 

Yes, you could of course build a custom migration tool every time you move a property, but that feels like alot of friction to me. Its only likely to be done when it absolutely necessary. 

Preferably I would like to be able to create a migration for this type of stuff as well. Something like:

ContentType("ExamplePage")
                .Block("Image")
                .Property("ImageReference")
                    .UsedToBeNamed("ImageReference");
#131983
Aug 11, 2015 16:44
Vote:
 

+1 for 

ContentType("ExamplePage")
                .Block("Image")
                .Property("ImageReference")
                    .UsedToBeNamed("ImageReference");
#133048
Aug 25, 2015 16:20
* 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.