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.
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, 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.
@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.
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.
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.
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.
there are some options but they are not safe as creating a new ones under the master template from the umbraco backend.
http://our.umbraco.org/projects/developer-tools/doc-type-extensions
Sorry for the short post, posting from an iPad is a nightmare!
Hope the link helped.
Rich
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
I think the Doc Type Extension project doens't work with Umbraco 4.7. Ask Matt to be sure.
Jeroen
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
@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.
@Hendy agreed that should work and be quicker, always good to have options though :)
@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.
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
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.
Same problem here: http://our.umbraco.org/forum/templating/templates-and-document-types/43487-Change-document-type-inheritance-in-Umbraco-6
I solved the issue with 2 SQL commands. This is the SQL code:
After execution, it is important to reset WebApplication. To do this, open web.config then do save it.
UPDATE 2015-01-27:
Note: to move a documentType that has children:
is working on a reply...