Skip to content

Cleaning Up Site After Split

Trevor Fayas edited this page Aug 24, 2022 · 2 revisions

Once you are ready to start the upgrade and have cloned your database/site, you can start doing additional clean up operations.

Disable Versioning / Workflow

When upgrading, you cannot upgrade Versioning / Workflow data anyway, so this is a good time to disable this and clean up the tables, this will shrink your database and also help speed up other clean up operations.

You can use the KX12To13Converter module's Upgrade Operations -> 1 - Versioning and Workflow UI to convert all pages to either published and/or archived/unpublished, then you can Turn off Version History and clear the workflow.

NOTE: These operations can be very resource and time consuming, it is best to run your site on debug mode and extend the SQL timeout on your connection string, and also set the database Recovery mode to "Simple." The log file will get massive otherwise and you'll probably run out of HDD Space.

Clean up Pages (again)

Now that all the pages are either published or unpublished/archived, you'll probably want to delete all archived pages or unpublished pages that you are going to Convert the widget/template content to. You don't need to do this for Content Items only that have no URL representation, but it's still a good idea to clean up as much as possible.

Below is a script I used to clear out Archived documents, although i ran into issues with delete operations failing sometimes and needing to restart the processes:

bool docsDeleted = false;
        do
        {
            docsDeleted = false;
            // Test site delete help
            //int[] docIdsToDelete = ConnectionHelper.ExecuteQuery("select top 100 DocumentID from View_CMS_Tree_Joined where NodeSiteID = 25 and NodeAliasPath <> '/' order by NodeLevel desc, NodeAliasPath", null, QueryTypeEnum.SQLQuery).Tables[0].Rows.Cast<DataRow>().Select(x => (int)x["DocumentID"]).ToArray();

            // Archived pages
            var docs = ConnectionHelper.ExecuteQuery("select top 50 * from View_CMS_Tree_Joined where DocumentIsArchived = 1 order by NodeLevel desc, NodeAliasPath", null, QueryTypeEnum.SQLQuery).Tables[0].Rows.Cast<DataRow>().Select(x => CMS.DocumentEngine.TreeNode.New(x)).ToArray();
            //var docs = ConnectionHelper.ExecuteQuery("select top 50 * from View_CMS_Tree_Joined where DocumentIsArchived = 1 and NodeAliasPath not like '/Products-Parts-and-Accessories%' order by NodeLevel desc, NodeAliasPath", null, QueryTypeEnum.SQLQuery).Tables[0].Rows.Cast<DataRow>().Select(x => CMS.DocumentEngine.TreeNode.New(x)).ToArray();

            foreach (var doc in docs)
            {
                bool noError = true;
                do
                {
                    noError = true;
                    try
                    {
                        doc.Delete();
                        //DocumentHelper.DeleteDocument(doc, null, false, true);
                        TransactionHelper.CommitTransaction();
                        docsDeleted = true;
                    } catch(System.InvalidOperationException ex)
                    {
                        noError = false;
                        Thread.Sleep(1000);
                    }
                } while (!noError);
                
            }
        } while (docsDeleted);

Clean up Templates

Ad Hoc templates can clutter up your Template Conversion Configuration, as well as you may have other pages/templates that will be replaced with MVC Functionality. For example, your Site Search may no longer be a template and a page, but an individual Controller + Custom Route. Your Sitemap page and template probably can go away as you'll be also using a custom Controller + Route. So scan through your templates and pages and remove anything that you won't need to convert at all.

Once you're done, you can use the below script to clear out any Page templates that are no longer used:

 var templates = PageTemplateInfoProvider.GetTemplates()
                .Where(@"PageTemplateType not in ('ui', 'dashboard') and PageTemplateID not in (

select DocumentPageTemplateID from View_CMS_Tree_Joined where DocumentPageTemplateID is not null
union all
select NodeTemplateID from View_CMS_Tree_Joined where NodeTemplateID is not null
)")
                .TypedResult.ToArray();

            
            foreach (var template in templates)
            {
                template.Delete();
            }