Virtual Happy Hour this month, Jun 28, we'll be getting a sneak preview at our soon to launch SaaS CMS!

Try our conversational search powered by Generative AI!

How to convert block property types with MigrationSteps?

Vote:
 

Hello everyone,

the question was already asked here:

https://world.episerver.com/forum/developer-forum/Developer-to-developer/Thread-Container/2018/2/how-to-update-old-page-type-property-values/

i actually want to do exactly the same, convert an existing string property in a page to XhtmlString. So i want to use MigrationSteps.

Unfortunately there is nowhere an example on how to do it. This is the documentation:

https://world.episerver.com/documentation/developer-guides/CMS/Content/Refactoring-content-type-classes/#changetype

It lacks sample code(apart from renaming a property which you find everywhere in the internet) that shows how to convert the type.

As a workaround i have tried to do it with another property even if that pollutes my class and needs a lot of work to fix it everywhere:

[CultureSpecific]
[Display(
	Name = "Title",
	Description = "Article title",
	Order = 999)]
[ScaffoldColumn(false)]
[Editable(false)]
[Obsolete("Replaced with the XhtmlString property ArticleTitle")]
public virtual string Title { get; set; }

[CultureSpecific]
[Display(
	Name = "Title",
	Description = "Article title",
	Order = 220)]
[UIHint(UIHint.Textarea)]
public virtual XhtmlString ArticleTitle
{
	get
	{
		XhtmlString articleTitle = this.GetPropertyValue(page => page.ArticleTitle);
		return articleTitle ?? new XhtmlString(this.GetPropertyValue(page => page.Title));
	}
	set { this.SetPropertyValue(page => page.ArticleTitle, value); }
}

One issue i have with this is that the old Title is correctly returned but it's not visible in CMS. So the CMS-Editor thinks it is empty. How to fix that? Another minor one is that the order of the new property that should replace the old is ordered last, so not at the same position even if i gave it the same Order value. I really would prefer MigrationSteps(or a similar programmatic approach) if possible because we have several systems apart from production that need to be maintained.

Thanks in advance,

Tim

#246543
Edited, Jan 08, 2021 15:34
* 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.