Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
174 views
in Technique[技术] by (71.8m points)

Change name, type and value of a page or block property in Episerver

We often need to refactor existing pages and blocks due to new requirements. Usually one or more properties are to be replaced by one or more new properties. Existing pages and blocks need to keep on working and it is not uncommon that settings made using the old properties need to affect the settings of the new properties. Creating new pages or blocks to replace existing ones is not an option - unless it can be automated.

Simple example #1: The old Boolean property UseDarkBackgroundColor is replaced by the new string property BackgroundColor. If UseDarkBackgroundColor was set, BackgroundColor should be set to a specific color.

Simple example #2: The old Boolean property IsWide is replaced by the new property IsNarrow (basically flipping name and value). If IsWide was true, IsNarrow should be false and vice versa.

In the past we have solved this by updating the Episerver database using an SQL script. I find this kind of scary and I would therefore like to find a better approach.

The following article gives me some hope: https://world.episerver.com/documentation/developer-guides/CMS/Content/Refactoring-content-type-classes#API

The information under the section "Renaming a content type by API" is easy to understand and when testing it the result was as expected. However, the text under the section "Changing the type for a property" is next to gibberish to me. I don't even know where to start, even after a lot of googling.

Does anybody know of an example that shows how to change the type (and value) of a property in Episerver without an SQL script?

question from:https://stackoverflow.com/questions/65902540/change-name-type-and-value-of-a-page-or-block-property-in-episerver

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

We never change types for an existing property, but rather we introduce a new property, hide the old one from the UI, and (if applicable) implement a custom getter for the new property so that it uses the old property as "fallback" until an editor has published content with the new property.

Sometimes we migrate the old property value to the new property through some type of batch job, and then delete the old property.

We never manipulate the database directly.

Also check out migration steps, commonly used if you for example need to rename a property: https://www.jondjones.com/learn-episerver-cms/episerver-developers-tutorials/importing-content-into-episerver-programmatically/episerver-migration-steps-explained/


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...