Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Sean Holmesby 61 posts 82 karma points
    May 05, 2011 @ 05:14
    Sean Holmesby
    0

    Change Existing Document Type to Inherit from Another

    Hi there,

    I installed one of the starter kits with Umbraco, and found that I wanted to add some fields to all of the existing document types. I figured the best way was to create a Master Document Type, and have all of the other Document Types inherit from it, however I couldn't find a way to change the existing document types to do this.

    Is there a way to make existing Document Types inherit from a newly created Document Type? At the moment it looks like I'll have to go through and create new Document Types under my Master one that are copies of the existing ones.... This will be pretty tedious.
    Cheers,
    Sean

  • Eran Meir 401 posts 543 karma points
    May 05, 2011 @ 08:35
    Eran Meir
    0

    there are some options but they are not safe as creating a new ones under the master template from the umbraco backend.

  • Rich Green 2246 posts 4008 karma points
    May 05, 2011 @ 08:48
  • Rich Green 2246 posts 4008 karma points
    May 05, 2011 @ 11:05
    Rich Green
    0

    Sorry for the short post, posting from an iPad is a nightmare!

    Hope the link helped.

    Rich

  • Hendy Racher 863 posts 3849 karma points MVP 2x admin c-trib
    May 05, 2011 @ 11:17
    Hendy Racher
    0

    Hi Sean,

    The Doc Type Extensions package Rich mentioned above should do the trick, but it can also be done manually:

    1) Create new Document Type (don't add any properties)

    2) Update the cmsContentType.masterContentType field for each of the Document Types you'd like to inherit from (1)

    3) Add properties to (1)

    HTH,

    Hendy

  • Jeroen Breuer 4908 posts 12265 karma points MVP 4x admin c-trib
    May 05, 2011 @ 11:40
    Jeroen Breuer
    0

    I think the Doc Type Extension project doens't work with Umbraco 4.7. Ask Matt to be sure.

    Jeroen

  • Rich Green 2246 posts 4008 karma points
    May 05, 2011 @ 11:46
    Rich Green
    0

    Didn't know that.

    The other option (if you don't have any current data) is to export each Doc Type (right click and export doc type) you then get an XML file with all the doc type properties, it's pretty easy to understand.

    You can then change the master doc/properties etc. and import the Doc Types back in (Right click, import Doc Type)

    Rich

     

     

  • Hendy Racher 863 posts 3849 karma points MVP 2x admin c-trib
    May 05, 2011 @ 11:53
    Hendy Racher
    0

    @Rich, might be quicker and easier to update the cmsContentType table to set the new parent Document Type (which should not have any properties as yet) for each of Document Types to be moved - this will keep any existing content & values. New properties can then be added to the newly added base Document Type.

  • Rich Green 2246 posts 4008 karma points
    May 05, 2011 @ 11:57
    Rich Green
    0

    @Hendy agreed that should work and be quicker, always good to have options though :)

  • Sean Holmesby 61 posts 82 karma points
    May 06, 2011 @ 03:09
    Sean Holmesby
    0

    @Hendy How do you update the cmxContentType.masterContentType? Is that done in the SQL database, or can you do it through the Umbraco admin UI?

     

    Thanks all for your suggestions. I'm keen to give the Doc Type Extension project a run when I get a chance, just to see the different ways it can be run.

  • Hendy Racher 863 posts 3849 karma points MVP 2x admin c-trib
    May 06, 2011 @ 11:31
    Hendy Racher
    1

    Hi Sean,

    Yes it's a SQL update to the masterContentType field of the cmsContentType table.

    1) Create new Document Type in Umbraco - this one is to be inserted as the new parent - take a note of it's ID.

    2) Update cmsContentType.masterContentType field for all Document Types that'd you'd like to inherit from (1) - so set this field to the ID of (1)

    3) Add properties to (1)

    HTH,

    Hendy

  • Tobias Morf 80 posts 183 karma points
    Aug 14, 2013 @ 18:27
    Tobias Morf
    0

    Does anyone know how to achieve the same thing with umbraco v6?

    There is a table called "cmsContentType2ContentType" which is updated when you add a new child doc type. But if you add new entries manually - it seems to have no influence. 

     

  • Tobias Morf 80 posts 183 karma points
    Aug 15, 2013 @ 07:57
  • Flavio Spezi 128 posts 314 karma points
    Sep 14, 2013 @ 19:02
    Flavio Spezi
    0

    I solved the issue with 2 SQL commands. This is the SQL code:

    USE WebsiteDB;  -- Set with your DB name
    GO
    
    DECLARE @ContentTypeId INT, @NewParentId INT;
    SET @ContentTypeId = 1285;  -- set with ID of ContentType to change
    SET @NewParentId = 1381;    -- set with ID of new parent to set to @ContentTypeId (use -1 to set to root)
    
    IF @NewParentId IN (0, -1) BEGIN
        SET @NewParentId = -1;  -- new parent is Root node.
    END
    
    -- Common variables
    DECLARE @strSplit VARCHAR(100), @str VARCHAR(100), @ind INT, @count INT;
    
    -- Reading current path info
    DECLARE @CurrentParentPathTable TABLE (Id INT, Sort INT);
    SELECT @strSplit = [path] FROM umbracoNode WHERE id = @ContentTypeId;
    
    -- Split @CurrentPath to @CurrentParentPathTable table
    SET @ind = CharIndex(',', @strSplit);
    SET @count = 0;
    WHILE @ind > 0 BEGIN
        SET @str = SUBSTRING(@strSplit, 1, @ind - 1);
        SET @strSplit = SUBSTRING(@strSplit, @ind + 1, LEN(@strSplit) - @ind);
        INSERT INTO @CurrentParentPathTable values (@str, @count);
        SET @count = @count + 1;
        SET @ind = CharIndex(',', @strSplit);
    END
    SET @str = @strSplit;
    INSERT INTO @CurrentParentPathTable values (@str, @count);
    
    -- Reading new path info
    DECLARE @NewParentPath VARCHAR(100);
    DECLARE @NewParentPathTable TABLE (Id INT, Sort INT);
    IF @NewParentId = -1 BEGIN
        SET @NewParentPath = '';
    END ELSE BEGIN
        SELECT @strSplit = [path] FROM umbracoNode WHERE id = @NewParentId;
        SET @NewParentPath = @strSplit + ',';
    
        -- Split @path to @NewParentPathTable table
        SET @ind = CharIndex(',', @strSplit);
        SET @count = 0;
        WHILE @ind > 0 BEGIN
            SET @str = SUBSTRING(@strSplit, 1, @ind - 1);
            SET @strSplit = SUBSTRING(@strSplit, @ind + 1, LEN(@strSplit) - @ind);
            INSERT INTO @NewParentPathTable values (@str, @count);
            SET @count = @count + 1;
            SET @ind = CharIndex(',', @strSplit);
        END
        SET @str = @strSplit;
        INSERT INTO @NewParentPathTable values (@str, @count);
    END
    
    -- Clean current document type inherit structure
    DELETE TB1
    FROM [cmsContentType2ContentType] TB1
        INNER JOIN @CurrentParentPathTable TB2 ON TB1.parentContentTypeId = TB2.Id
    WHERE TB1.[childContentTypeId] = @ContentTypeId;
    
    -- Set new document type inherit structure
    INSERT INTO [cmsContentType2ContentType] ([parentContentTypeId], [childContentTypeId])
    SELECT TB1.Id, @ContentTypeId
    FROM @NewParentPathTable TB1
    WHERE TB1.Sort IN (SELECT MAX(Sort) FROM @NewParentPathTable WHERE Id > 0);
    
    -- Remove GroupID from properties that are in inherits groups
    UPDATE cmsPropertyType
    SET propertyTypeGroupId = NULL
    FROM cmsPropertyType
        INNER JOIN cmsPropertyTypeGroup ON cmsPropertyType.propertyTypeGroupId = cmsPropertyTypeGroup.id
    WHERE (cmsPropertyType.contentTypeId = @ContentTypeId) AND (cmsPropertyTypeGroup.parentGroupId IS NOT NULL);
    
    -- Remove inherits groups
    DELETE TB1
    FROM cmsPropertyTypeGroup TB1
    WHERE (TB1.contenttypeNodeId = @ContentTypeId) AND (TB1.parentGroupId IS NOT NULL);
    
    
    -- Update Path field
    UPDATE umbracoNode
    SET parentId = @NewParentId
        , [path] = @NewParentPath + CAST(id AS VARCHAR(20))
        , [level] = (SELECT COUNT(*) + 1 FROM @NewParentPathTable WHERE Id > 0)
    WHERE id = @ContentTypeId;
    
    GO
    

    After execution, it is important to reset WebApplication. To do this, open web.config then do save it.

    UPDATE 2015-01-27:

    • add support for set "root" as new parent.
    • add compatibility to Umbraco 7.2

    Note: to move a documentType that has children:

    • run T-SQL for the first documentType
    • run T-SQL for any children
Please Sign in or register to post replies

Write your reply to:

Draft