Don't miss out Virtual Happy Hour this Friday (April 26).

Try our conversational search powered by Generative AI!

content and company name change

Vote:
 

Hi all,

We have over 1000 pages that will need to be checked as the company is going through a name change.

Wondering if anyone has gone through a global company name change and can provide the best way to update it programmatically? or any available plugins.

Thanks in advance.

Paul

#286816
Sep 08, 2022 1:39
Vote:
 

what do you want to check? is the name change only affected the page name, or even with the properties in the pages? do you just want to flag the pages that need to be reviewed, or do you want to do a find and replace? 

you can always use IContentRepository to load the content recursively those. or Find 

#286821
Sep 08, 2022 9:24
Vote:
 

I am thinking a find and replace, with some reporting so they know what changes are being made. It would be in page titles and page content.

#286895
Sep 08, 2022 23:19
Vote:
 

Hey Paul, why not create a schedule job to execute your code? Within that use Quan's suggestion of IContentRepository to load your content, replace your company name text and then republish it.

#286906
Sep 09, 2022 10:04
Vote:
 

Here some code you can use

Reading "Episerver Commerce: A problem - solution approach" | Leanpub

    public virtual IEnumerable<T> GetEntriesRecursive<T>(ContentReference parentLink, CultureInfo defaultCulture) where T : IContent
    {
        foreach (var nodeContent in LoadChildrenBatched<IContent>(parentLink, defaultCulture))
        {
            foreach (var entry in GetEntriesRecursive<T>(nodeContent.ContentLink, defaultCulture))
            {
                yield return entry;
            }
        }

        foreach (var entry in LoadChildrenBatched<T>(parentLink, defaultCulture))
        {
            yield return entry;
        }
    }

    private IEnumerable<T> LoadChildrenBatched<T>(ContentReference parentLink, CultureInfo defaultCulture) where T : IContent
    {
        var start = 0;

        while (true)
        {
            var batch = _contentLoader.GetChildren<T>(parentLink, defaultCulture, start, 50);
            if (!batch.Any())
            {
                yield break;
            }

            foreach (var content in batch)
            {
                // Don't include linked products to avoid including them multiple times when traversing the catalog
                if (!parentLink.CompareToIgnoreWorkID(content.ParentLink))
                {
                    continue;
                }

                yield return content;
            }
            start += 50;
        }
    }
#286908
Edited, Sep 09, 2022 10:23
* 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.