Rock.Model.PageService.GeneratePageCopy C# (CSharp) Method

GeneratePageCopy() private method

This method generates a copy of the given page along with any descendant pages, as well as any blocks on any of those pages.
private GeneratePageCopy ( Rock sourcePage, Guid>.Dictionary pageGuidDictionary, Guid>.Dictionary blockGuidDictionary, int currentPersonAliasId = null ) : Rock.Model.Page
sourcePage Rock The source page.
pageGuidDictionary Guid>.Dictionary The dictionary containing the original page guids and the corresponding copied page guids.
blockGuidDictionary Guid>.Dictionary The dictionary containing the original block guids and the corresponding copied block guids.
currentPersonAliasId int The current person alias identifier.
return Rock.Model.Page
        private Rock.Model.Page GeneratePageCopy( Rock.Model.Page sourcePage, Dictionary<Guid, Guid> pageGuidDictionary, Dictionary<Guid, Guid> blockGuidDictionary, int? currentPersonAliasId = null )
        {
            var targetPage = new Rock.Model.Page();
            targetPage = sourcePage.Clone( false );
            targetPage.CreatedByPersonAlias = null;
            targetPage.CreatedByPersonAliasId = currentPersonAliasId;
            targetPage.CreatedDateTime = RockDateTime.Now;
            targetPage.ModifiedByPersonAlias = null;
            targetPage.ModifiedByPersonAliasId = currentPersonAliasId;
            targetPage.ModifiedDateTime = RockDateTime.Now;
            targetPage.BodyCssClass = sourcePage.BodyCssClass;
            targetPage.Id = 0;
            targetPage.Guid = Guid.NewGuid();
            targetPage.PageTitle = sourcePage.PageTitle + " - Copy";
            targetPage.InternalName = sourcePage.InternalName + " - Copy";
            targetPage.BrowserTitle = sourcePage.BrowserTitle + " - Copy";
            pageGuidDictionary.Add( sourcePage.Guid, targetPage.Guid );

            foreach ( var block in sourcePage.Blocks )
            {
                var newBlock = block.Clone( false );
                newBlock.CreatedByPersonAlias = null;
                newBlock.CreatedByPersonAliasId = currentPersonAliasId;
                newBlock.CreatedDateTime = RockDateTime.Now;
                newBlock.ModifiedByPersonAlias = null;
                newBlock.ModifiedByPersonAliasId = currentPersonAliasId;
                newBlock.ModifiedDateTime = RockDateTime.Now;
                newBlock.Id = 0;
                newBlock.Guid = Guid.NewGuid();
                newBlock.PageId = 0;

                blockGuidDictionary.Add( block.Guid, newBlock.Guid );
                targetPage.Blocks.Add( newBlock );
            }

            foreach ( var oldchildPage in sourcePage.Pages )
            {
                targetPage.Pages.Add( GeneratePageCopy( oldchildPage, pageGuidDictionary, blockGuidDictionary ) );
            }

            return targetPage;
        }