SaaS CMS has officially launched! Learn more now.

PuneetGarg
Apr 26, 2022
  1542
(4 votes)

Content Migration from one to another property for live site

In one of my projects I recently faced an issue where we have to change all the standard category properties to IList<ContentReference> and the site was live so we just couldn't take the field and get it over with.

So I create new IList<ContentReference> properties and migrate the data and change the logic. Here are the steps that I followed.

Step To follow:-

    • Create new fields -- for all categories while don't remove old ones once
    • Create a scheduled job that migrates data from the old field to the new field
    • Switch the logic from old to new fields as new fields have multiple categories
    • remove old fields (only after running the migration job)

Step-1:-

We create new Ilist<contentreference> properties for every standard category property.

 

 [Display(
            Name = "Something",
            GroupName = SystemTabNames.Content,
            Order = 10)]
        [Categories]
        public virtual IList<ContentReference> Something { get; set; }

Step-2:-

Here we have to write the code so that content that is already existing on the live site migrates from old to new properties.

Few things that I did while creating a scheduled job:

        • Get all the pages where I changed the property, So for that, I created a generic method.
 private IEnumerable<T> GetDataList<T>()
            where T : ContentData
        {
            var objectType = _contentTypeRepository.Load<T>();
            var usages = _contentModelUsage.ListContentOfContentType(objectType)
                .Select(x => x.ContentLink.ToReferenceWithoutVersion())
                .Distinct()
                .Select(x => _contentLoader.Get<IContentData>(x))
                .OfType<T>()
                .ToList();
            return (IEnumerable<T>)usages;
        }

 

        • After this method call loop through all the pages and create a writeable clone so that we change the data
        • invoke the list and then assign the value to it.
 OnStatusChanged($"Migration start for ChapterDetailPage");

            var chapterDetailPages = GetDataList<ChapterDetailPage>();
            if (chapterDetailPages != null)
            {
                foreach (var cdp in chapterDetailPages)
                {
                    //migrate data
                    var page = (ChapterDetailPage)cdp.CreateWritableClone();
                    page.LocationIdNew = new List<ContentReference>();

                    var hit = _getaCatRep.TryGet(new ContentReference(page.LocationID), out stdCat) ? stdCat : null;
                    if (hit != null)
                    {
                        page.LocationIdNew.Add(hit.ContentLink);
                        _contentRepository.Save(page, SaveAction.Publish, AccessLevel.NoAccess);
                    }
                }
            }

            OnStatusChanged($"Migration end for ChapterDetailPage");
        • Then Save the page using the Content Repository.

Step-3

Change all the existing logic so that pages don't error.

Step-4

The last step will be to remove all old properties.

Apr 26, 2022

Comments

Please login to comment.
Latest blogs
Optimizely SaaS CMS Concepts and Terminologies

Whether you're a new user of Optimizely CMS or a veteran who have been through the evolution of it, the SaaS CMS is bringing some new concepts and...

Patrick Lam | Jul 15, 2024

How to have a link plugin with extra link id attribute in TinyMce

Introduce Optimizely CMS Editing is using TinyMce for editing rich-text content. We need to use this control a lot in CMS site for kind of WYSWYG...

Binh Nguyen Thi | Jul 13, 2024

Create your first demo site with Optimizely SaaS/Visual Builder

Hello everyone, We are very excited about the launch of our SaaS CMS and the new Visual Builder that comes with it. Since it is the first time you'...

Patrick Lam | Jul 11, 2024

Integrate a CMP workflow step with CMS

As you might know Optimizely has an integration where you can create and edit pages in the CMS directly from the CMP. One of the benefits of this i...

Marcus Hoffmann | Jul 10, 2024

GetNextSegment with empty Remaining causing fuzzes

Optimizely CMS offers you to create partial routers. This concept allows you display content differently depending on the routed content in the URL...

David Drouin-Prince | Jul 8, 2024 | Syndicated blog

Product Listing Page - using Graph

Optimizely Graph makes it possible to query your data in an advanced way, by using GraphQL. Querying data, using facets and search phrases, is very...

Jonas Bergqvist | Jul 5, 2024