Skip to content

Preserving Navigation Redirects

Trevor Fayas edited this page Aug 7, 2023 · 2 revisions

If you wish to preserve the Navigation Redirection logic, you'll need to run the below SQL script to migrate your Navigation Redirect properties to the Node Custom Data, then install and use Sean Wright's KX13 Page Navigation Redirects after you upgrade to KX13.

This script must be run PRIOR to upgrade.

update 
  Tree 
set 
  NodeCustomData = NewNodeCustomData 
from 
  CMS_Tree Tree 
  inner join (
    select 
      NodeID as ExistingNodeID, 
      '<CustomData>' + ExistingNodeCustomData + case when PageRedirectionType is not null then '<PageRedirectionType>' + PageRedirectionType + '</PageRedirectionType>' else '' end + case when PageInternalRedirectNodeGuid is not null then '<PageInternalRedirectNodeGuid>' + CAST(
        PageInternalRedirectNodeGuid as nvarchar(50)
      )+ '</PageInternalRedirectNodeGuid>' else '' end + case when PageExternalRedirectURL is not null then '<PageExternalRedirectURL>' + PageExternalRedirectURL + '</PageExternalRedirectURL>' else '' end + case when PageUsePermanentRedirects is not null then '<PageUsePermanentRedirects>' + CAST(
        PageUsePermanentRedirects as nvarchar(10)
      )+ '</PageUsePermanentRedirects>' else '' end + '</CustomData>' as NewNodeCustomData 
    from 
      (
        select 
          distinct firstLevel.NodeID, 
          case when NodeCustomData is null then '' else REPLACE(
            REPLACE(
              NodeCustomData, '<CustomData>', ''
            ), 
            '</CustomData>', 
            ''
          ) end as ExistingNodeCustomData, 
          Urls.FoundNodeGuid as PageInternalRedirectNodeGuid, 
          case when Urls.FoundNodeGuid is null then NULLIF(DocumentMenuRedirectUrl, '') else null end as PageExternalRedirectURL, 
          case when PageRedirectionType = 'FirstChild' then 'FirstChild' else case when Urls.FoundNodeGuid is not null then 'Internal' else 'External' end end as PageRedirectionType, 
          1 as PageUsePermanentRedirects 
        from 
          (
            select 
              NodeID, 
              NodeAliasPath, 
              NodeCustomData, 
              case when len(DocumentMenuRedirectUrl) > 0 
              and CHARINDEX('~', DocumentMenuRedirectUrl) = 1 then RIGHT(
                DocumentMenuRedirectUrl, 
                len(DocumentMenuRedirectUrl)-1
              ) else DocumentMenuRedirectUrl end as DocumentMenuRedirectUrl, 
              DocumentMenuRedirectToFirstChild, 
              case when DocumentMenuRedirectToFirstChild = 1 then 'FirstChild' else case when DocumentMenuRedirectUrl like 'http%' then 'External' else 'Internal' end end as PageRedirectionType 
            from 
              View_CMS_Tree_Joined 
            where 
              NULLIF(DocumentMenuRedirectUrl, '') is not null 
              or DocumentMenuRedirectToFirstChild = 1
          ) firstLevel 
          left join (
            select 
              NodeID as FoundNodeID, 
              NodeGuid as FoundNodeGuid, 
              COALESCE(
                NULLIF(FoundMatch.DocumentUrlPath, ''), 
                FoundMatch.NodeAliasPath
              ) as Url1, 
              AlternativeUrlUrl as Url2 
            from 
              View_CMS_Tree_Joined FoundMatch 
              left outer join CMS_AlternativeUrl on AlternativeUrlDocumentID = FoundMatch.DocumentID
          ) Urls on Urls.FoundNodeID = firstLevel.NodeID 
          and (
            firstLevel.DocumentMenuRedirectUrl = Url1 
            or firstLevel.DocumentMenuRedirectUrl = Url2
          )
      ) AllData
  ) NewCustomData on ExistingNodeID = NodeID