EPiServer: Change block on page

Prereq:

In this use case I had a page: OverviewPage with a block: PageHeader.

Req:

Other pages were still using PageHeader, while OverviewPage page needed to have PageHeader replaced with a new block: PageHeaderMandatory. Here is the code:

// Before
    public class OverviewPage : PageData{
        [Display(Name = "Page Header")]
        public virtual PageHeaderBlock PageHeader { get; set; }
   }
// After - notice both the type and the name needs to be replaced. 
// Type is stored in tblPropertyDefinitionType and name is stored in tblPropertyDefinition
// In this way the OverviewPage will then have the old PageHeader (stored in DB) and then new PageHeaderMandatory (gotten from code)
// Other pages can still use the old PageHeader
    public class OverviewPage : PageData{
        [Display(Name = "Page Header Mandatory")]
        public virtual PageHeaderBlockMandatory PageHeaderMandatory { get; set; }
    }
// Remember to give the new ContentType PageHeaderBlockMandatory a new GUID!

Next run the code and goto the OverviewPage. This will create new block PageHeaderMandatory in the DB.

Next you want to copy data from old PageHeader to new PageHeaderMandatory.

On OverviewPage – for each language do:

1: Copy content from old PageHeader

CopyFromOldPageHeader

2: Paste content to new PageHeaderMandatory

PasteToNewPageHeaderMandatory

3: Publich OverviewPage for all languages after content has been copied to new PageHeaderMandatory

Finally you want to remove the old block PageHeader from the OverviewPage, so it does not show up in edit mode

4: goto /EPiServer/CMS/Admin

5: In tab “Contenttype” – press OverviewPage
6: Click on property PageHeader (the old one)

CTOverviewPage0

7: Click Delete

CTOverviewPage1

Now you have removed the old property from the database

With this SQL you can check what you have in the DB for OverviewPage and PageHeader:

PRINT 'ContentTypes:'
SELECT [pkID] AS [ContentTypeID]
      ,[ContentTypeGUID]
      ,[Created]
      ,[Name]
      ,[ContentType]
  FROM [dbo].[tblContentType]
  WHERE [Name] like 'PageHeaderBlock%' OR [Name] like 'OverviewP%'

  -- Props *********************
PRINT 'PropertyNames:'
SELECT [pkID] AS [PropertyDefinitionID]
      ,[fkContentTypeID]
      ,[fkPropertyDefinitionTypeID]
      ,[Name]
      ,[Property]
      ,[Required]
      ,[DefaultValueType]
      ,[LongStringSettings]
      ,[SettingsID]
      ,[LanguageSpecific]
      ,[ExistsOnModel]
  FROM [dbo].[tblPropertyDefinition]
  WHERE [fkContentTypeID] in 
  (
	  SELECT [pkID]
		  FROM [dbo].[tblContentType]
		  WHERE [Name] like 'PageHeaderBlock%' OR [Name] like 'OverviewP%'
  ) 
  ORDER BY [fkContentTypeID], [fkPropertyDefinitionTypeID]

PRINT 'PropertyTypes:'
SELECT [pkID] AS [PropertyDefinitionTypeID]
      ,[Property]
      ,[Name]
      ,[fkContentTypeGUID]
  FROM [dbo].[tblPropertyDefinitionType]
  WHERE [pkID] in (
	SELECT [fkPropertyDefinitionTypeID]
	  FROM [dbo].[tblPropertyDefinition]
	  WHERE [fkContentTypeID] in 
	  (
		  SELECT [pkID]
			  FROM [dbo].[tblContentType]
			  WHERE [Name] like 'PageHeaderBlock%' OR [Name] like 'OverviewP%'
	  ) 
  )
  OR [Name] like 'PageHeaderBlock%' 

  -- Content *********************
PRINT 'Pages and Blocks:'
  SELECT [pkID] AS [ContentID]
      ,[fkContentTypeID]
      --,[fkParentID]
      --,[ArchiveContentGUID]
      --,[CreatorName]
      ,[ContentGUID]
      --,[VisibleInMenu]
      ,[Deleted]
      ,[ChildOrderRule]
      --,[PeerOrder]
      --,[ExternalFolderID]
      --,[ContentAssetsID]
      --,[ContentOwnerID]
      --,[DeletedBy]
      --,[DeletedDate]
      ,[fkMasterLanguageBranchID]
      ,[ContentPath]
      --,[ContentType]
      --,[IsLeafNode]
  FROM [dbo].[tblContent]
  WHERE [fkContentTypeID] in (
	  SELECT [pkID]
		  FROM [dbo].[tblContentType]
		  WHERE [Name] like 'PageHeaderBlock%' OR [Name] like 'OverviewP%'
  ) 


PRINT 'Content and Property values:'
SELECT [pkID] AS [ContentPropertyID]
      ,[fkPropertyDefinitionID]
      ,[fkContentID]
      ,[fkLanguageBranchID]
      --,[ScopeName]
      --,[guid]
      ,[Boolean]
      ,[Number]
      --,[FloatNumber]
      --,[ContentType]
      --,[ContentLink]
      --,[Date]
      ,SUBSTRING([String],1,29) AS [StringPart]
      ,SUBSTRING(LongString,1,29) AS [LongStringPart]
      --,[LongStringLength]
      --,[LinkGuid]
  FROM [dbo].[tblContentProperty]
  WHERE [fkContentID] in (
	SELECT [pkID]
	  FROM [dbo].[tblContent]
	  WHERE [fkContentTypeID] in (
		  SELECT [pkID]
			  FROM [dbo].[tblContentType]
			  WHERE [Name] like 'PageHeaderBlock%' OR [Name] like 'OverviewP%'
	  )
	  OR [fkPropertyDefinitionID] in (
		SELECT [pkID]
		  FROM [dbo].[tblPropertyDefinition]
		  WHERE [fkContentTypeID] in 
		  (
			  SELECT [pkID]
				  FROM [dbo].[tblContentType]
				  WHERE [Name] like 'PageHeaderBlock%' OR [Name] like 'OverviewP%'
		  ) 
	  )
  )

Output:

ContentTypes:
ContentTypeID ContentTypeGUID                      Created                 Name                                               ContentType
------------- ------------------------------------ ----------------------- ----------------
14            F813D281-CD20-491E-9FD4-19779B381318 2014-12-18 15:21:44.127 OverviewPage                                       0
34            D83178D8-0B4F-4543-B223-AE467DC505F0 2015-01-28 15:17:49.003 PageHeaderBlock                                    1
47            D83178D8-0B4F-4543-B223-AE467DC505F1 2015-03-02 12:07:25.400 PageHeaderBlockMandatory                           1

(3 row(s) affected)

PropertyNames:
PropertyDefinitionID fkContentTypeID fkPropertyDefinitionTypeID Name                                               Property    Required DefaultValueType LongStringSettings SettingsID                           LanguageSpecific ExistsOnModel
-------------------- --------------- -------------------------- ---------------------------
218                  14              7                          CommonTaskHeading                                  7           NULL     0                0                  NULL                                 4                1
219                  14              7                          CommonTaskSubHeading                               7           NULL     0                0                  NULL                                 4                1
296                  14              25                         BannerArea                                         7           NULL     0                0                  NULL                                 4                1
314                  14              25                         CommonTaskArea                                     7           NULL     0                0                  NULL                                 4                1
2700                 14              1015                       PageHeaderMandatory                                12          NULL     0                0                  NULL                                 2                1
1824                 34              1                          GreetingBackgroundTheme                            1           NULL     0                0                  NULL                                 4                1
2696                 34              13                         BodyText                                           7           NULL     0                0                  NULL                                 4                1
1822                 34              13                         Title                                              7           NULL     0                0                  218255E2-437C-4AAD-AC3D-99A0876A069B 4                1
1823                 34              13                         GreetingText                                       7           NULL     0                0                  BEBA83A1-DE58-4674-8B70-7B97270B046E 4                1
2697                 34              1004                       Link                                               12          NULL     0                0                  NULL                                 2                1
2432                 47              1                          GreetingBackgroundTheme                            1           NULL     0                0                  NULL                                 4                1
2705                 47              13                         BodyText                                           7           NULL     0                0                  NULL                                 4                1
2430                 47              13                         Title                                              7           NULL     0                0                  NULL                                 4                1
2431                 47              13                         GreetingText                                       7           NULL     0                0                  NULL                                 4                1
2706                 47              1004                       Link                                               12          NULL     0                0                  NULL                                 2                1

(17 row(s) affected)

PropertyTypes:
PropertyDefinitionTypeID Property    Name                                                                                                                                                                                                                                                            fkContentTypeGUID
------------------------ ----------- -------------------------------------------------------
1                        1           Number                                                                                                                                                                                                                                                          NULL
7                        7           LongString                                                                                                                                                                                                                                                      NULL
13                       7           XhtmlString                                                                                                                                                                                                                                                     NULL
25                       7           ContentArea                                                                                                                                                                                                                                                     NULL
1004                     12          LinkBlock                                                                                                                                                                                                                                                       BC791128-0748-4959-A1D9-20378A905114
1010                     12          PageHeaderBlock                                                                                                                                                                                                                                                 D83178D8-0B4F-4543-B223-AE467DC505F0
1015                     12          PageHeaderBlockMandatory                                                                                                                                                                                                                                        D83178D8-0B4F-4543-B223-AE467DC505F1

(7 row(s) affected)

Pages and Blocks:
ContentID   fkContentTypeID ContentGUID                          Deleted ChildOrderRule fkMasterLanguageBranchID ContentPath
----------- --------------- ------------------------------------ ------- -------------- ----
16          14              7E6C3A57-40DA-4180-ABB6-F25A68435CA3 0       1              8                        .1.9.
41          34              8A35DE28-A30A-44F8-89EA-2E1A1BA5A9CC 0       3              8                        .1.3.

(2 row(s) affected)

Content and Property values:
ContentPropertyID fkPropertyDefinitionID fkContentID fkLanguageBranchID Boolean Number      StringPart                    LongStringPart
----------------- ---------------------- ----------- ------------------ ------- -----------
...
8897              2430                   16          9                  0       NULL        NULL                          <p>Overview NO</p>
8899              2430                   16          11                 0       NULL        NULL                          <p>Overview FI</p>
...

(62 row(s) affected)

The end.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: