Update/Modify default Master language for a site

Vote:
 

Hi Folks,

We are having multiple sites in our solution, and few of them are in production with “en” as a master language. But for one new site we want to set “en-us” as master language as we are not using “en” here. 

To change the Master language, we used below SQL script, But it is working for pages only not for blocks. Could someone help on this, how we can modify/update the master langue for page dependents blocks also.


/****** Object:  StoredProcedure [dbo].[cogChangePageBranchMasterLanguage]    Script Date: 01/07/2013 14:49:59 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[EPiCode_ChangePageBranchMasterLanguage]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[EPiCode_ChangePageBranchMasterLanguage]

/****** Object:  StoredProcedure [dbo].[EPiCode_ChangePageBranchMasterLanguage]    Script Date: 01/07/2013 14:49:59 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[EPiCode_ChangePageBranchMasterLanguage]
 @content_id    int,
 @language_branch varchar(20),
 @recursive bit,
 @switch_only bit
AS

DECLARE @language_branch_id nchar(17);
DECLARE @language_branch_nid int;
DECLARE @prev_language_branch_nid int;
DECLARE @child_Id int;
DECLARE @Fetch int;
DECLARE @target_lang_version_exist int;

SET @language_branch_nid = (SELECT pkID FROM tblLanguageBranch WHERE (LanguageID = @language_branch))
SET @language_branch_id = (SELECT LanguageID FROM tblLanguageBranch WHERE (LanguageID = @language_branch))
SET @prev_language_branch_nid = (SELECT fkMasterLanguageBranchID FROM tblContent WHERE pkID = @content_id)
SET @target_lang_version_exist = (SELECT count(*) FROM tblContentLanguage WHERE (fkContentID = @content_id AND fkLanguageBranchID = @language_branch_nid))

-- for switch only check if the page exist in the selected language and only then switch
IF 1 = @switch_only
  BEGIN
 print 'target_lang_version_exist' + str(@target_lang_version_exist);
 IF @target_lang_version_exist > 0
 BEGIN
 UPDATE tblContent
  SET fkMasterLanguageBranchID = @language_branch_nid
  WHERE pkID = @content_id AND fkMasterLanguageBranchID = @prev_language_branch_nid
 END
 ELSE
 BEGIN
 RAISERROR
 (N'The Selected page with ID:%d, cannot switch master branch since there is no version in the selected target language: %s.',
    11, 1, @content_id,  @language_branch);
 END
  END
ELSE
  BEGIN
 IF @target_lang_version_exist > 0
 BEGIN
  RAISERROR
    (N'The Selected page with ID:%d, cannot be translated since there already is a version in the selected target language: %s.',
        11, 1, @content_id,  @language_branch);
  END
 ELSE
  BEGIN
  UPDATE tblContent
    SET --fkLanguageID = @language_branch_id,
    fkMasterLanguageBranchID = @language_branch_nid
  WHERE pkID = @content_id

  UPDATE tblContentProperty
      SET fkLanguageBranchID = @language_branch_nid
  WHERE fkContentID = @content_id AND fkLanguageBranchID = @prev_language_branch_nid

  UPDATE tblContentLanguage
    SET fkLanguageBranchID = @language_branch_nid
    --,fkLanguageID = @language_branch_id
  WHERE fkContentID = @content_id AND fkLanguageBranchID = @prev_language_branch_nid

  UPDATE tblWorkContent
    SET fkLanguageBranchID = @language_branch_nid
    --,fkLanguageID = @language_branch_id
  WHERE fkContentID = @content_id AND fkLanguageBranchID = @prev_language_branch_nid
  END
  END

IF 1 = @recursive
BEGIN
 DECLARE children_cursor CURSOR LOCAL FOR
  select pkID from tblContent where fkParentID = @content_id

 OPEN children_cursor

 FETCH NEXT FROM children_cursor INTO @child_Id
 SET @Fetch=@@FETCH_STATUS

 WHILE @Fetch = 0
 BEGIN
  print @child_id
  print @language_branch_id
  exec [dbo].[EPiCode_ChangePageBranchMasterLanguage] @child_id, @language_branch_id, @recursive, @switch_only
  FETCH NEXT FROM children_cursor INTO @child_Id
  SET @Fetch=@@FETCH_STATUS
 END

 CLOSE children_cursor
 DEALLOCATE children_cursor
END

#286547
Sep 02, 2022 15:03
Vote:
 

How many pages/blocks do you expect to be changed? updating using IContentRepository should be fast enough, while safer and more future proof 

#286661
Sep 05, 2022 6:07
Rajveer Singh - Sep 05, 2022 8:10
Thank you for your reply, We want to change it for one of the sites from our Multisite solution(don't want to disturb them as they are using "en" as master and already gone live). Also, could you please explain bit in detail, how it will be done by using IContentRepository ?
Vote:
 

My bad, I always thought it is possible to change Master Language for CMS content, which is turned out to be, not. One alternative is to copy the content and resave in a different master language. quite troublesome yes but much safer ... 

#286663
Sep 05, 2022 10:24
Vote:
 

Finally Got the below script that works for all blocks and pages.

/****** Object:  StoredProcedure [dbo].[EPiCode_ChangePageAndBlockBranchMasterLanguage]
 Script Date: 2022-07-11 14:26:38 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[EPiCode_ChangePageAndBlockBranchMasterLanguage]
    @content_id    int,
    @language_branch varchar(20),
    @recursive bit,
    @switch_only bit,
    @delete_old_language_id int
AS

DECLARE @language_branch_id nchar(17);
DECLARE @language_branch_nid int;
DECLARE @prev_language_branch_nid int;
DECLARE @child_Id int;
DECLARE @Fetch int;
DECLARE @target_lang_version_exist int;

SET @language_branch_nid = (SELECT pkID FROM tblLanguageBranch WHERE (LanguageID = @language_branch))
SET @language_branch_id = (SELECT LanguageID FROM tblLanguageBranch WHERE (LanguageID = @language_branch))
SET @prev_language_branch_nid = (SELECT fkMasterLanguageBranchID FROM tblContent WHERE pkID = @content_id)
SET @target_lang_version_exist = (SELECT count(*) FROM tblContentLanguage WHERE (fkContentID = @content_id AND fkLanguageBranchID = @language_branch_nid))

-- for switch only check if the page exist in the selected language and only then switch
IF 1 = @switch_only 
  BEGIN
    print 'target_lang_version_exist' + str(@target_lang_version_exist);
    IF @target_lang_version_exist > 0
    BEGIN
    UPDATE tblContent
        SET fkMasterLanguageBranchID = @language_branch_nid
        WHERE pkID = @content_id AND fkMasterLanguageBranchID = @prev_language_branch_nid

        IF @delete_old_language_id > 0
        BEGIN
            --modify content properties which are not language specific
            update tblContentProperty set fkLanguageBranchId=@language_branch_nid where fkLanguageBranchID=@delete_old_language_id and fkContentId=@content_id and fkPropertyDefinitionID in (select pkId from tblPropertyDefinition where languagespecific=2)
            update tblWorkContentProperty set fkWorkContentId=(select [version] from tblContentLanguage where fkContentId=@content_id and fkLanguageBranchId=@language_branch_nid) where fkWorkContentId=(select [version] from tblContentLanguage where fkContentId=@content_id and fkLanguageBranchId=@delete_old_language_id) and fkPropertyDefinitionID in (select pkId from tblPropertyDefinition where languagespecific=2)

            --delete all old content
            delete from tblContentProperty where fkContentID=@content_id and fkLanguageBranchID=@delete_old_language_id
            delete from tblContentLanguage where fkContentID=@content_id and fkLanguageBranchID=@delete_old_language_id
        END
    END
    ELSE
    BEGIN
    RAISERROR 
    (N'The Selected page with ID:%d, cannot switch master branch since there is no version in the selected target language: %s.',
    11, 1, @content_id,  @language_branch); 
    END
  END
ELSE
  BEGIN
    IF @target_lang_version_exist > 0
    BEGIN
      RAISERROR 
        (N'The Selected page with ID:%d, cannot be translated since there already is a version in the selected target language: %s.',
        11, 1, @content_id,  @language_branch); 
      END
    ELSE
      BEGIN
        UPDATE tblContent
           SET --fkLanguageID = @language_branch_id,
              fkMasterLanguageBranchID = @language_branch_nid
         WHERE pkID = @content_id

        UPDATE tblContentProperty
            SET fkLanguageBranchID = @language_branch_nid
         WHERE fkContentID = @content_id AND fkLanguageBranchID = @prev_language_branch_nid

        UPDATE tblContentLanguage
           SET fkLanguageBranchID = @language_branch_nid
              --,fkLanguageID = @language_branch_id
        WHERE fkContentID = @content_id AND fkLanguageBranchID = @prev_language_branch_nid

        UPDATE tblWorkContent
           SET fkLanguageBranchID = @language_branch_nid
              --,fkLanguageID = @language_branch_id
        WHERE fkContentID = @content_id AND fkLanguageBranchID = @prev_language_branch_nid
      END
  END

-- get all 'for this page' or 'for this block' blocks and call itself recursively
DECLARE children_block_switch_cursor CURSOR LOCAL FOR
    select pkID from tblContent where fkParentId IN (SELECT pkId FROM tblContent WHERE contentOwnerId = 
    (SELECT ContentGUID FROM tblContent WHERE pkId=@content_id))

OPEN children_block_switch_cursor

FETCH NEXT FROM children_block_switch_cursor INTO @child_Id
SET @Fetch=@@FETCH_STATUS

WHILE @Fetch = 0
BEGIN
    print @child_id
    print @language_branch_id
    exec [dbo].[EPiCode_ChangePageAndBlockBranchMasterLanguage] @child_id, @language_branch_id, @recursive, @switch_only, @delete_old_language_id
    FETCH NEXT FROM children_block_switch_cursor INTO @child_Id
    SET @Fetch=@@FETCH_STATUS
END

CLOSE children_block_switch_cursor
DEALLOCATE children_block_switch_cursor

--call recursively for all child pages
IF 1 = @recursive 
BEGIN
    DECLARE children_cursor CURSOR LOCAL FOR
        select pkID from tblContent where fkParentID = @content_id

    OPEN children_cursor

    FETCH NEXT FROM children_cursor INTO @child_Id
    SET @Fetch=@@FETCH_STATUS

    WHILE @Fetch = 0
    BEGIN
        print @child_id
        print @language_branch_id
        exec [dbo].[EPiCode_ChangePageAndBlockBranchMasterLanguage] @child_id, @language_branch_id, @recursive, @switch_only, @delete_old_language_id
        FETCH NEXT FROM children_cursor INTO @child_Id
        SET @Fetch=@@FETCH_STATUS
    END

    CLOSE children_cursor
    DEALLOCATE children_cursor
END

#286707
Sep 06, 2022 11:27
* 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.