it looks like you are attempting to add the doctypes in a simliar way to how uSync does it, so it might be worth looking at the code in it's ContentTypeSerializer and ContentTypeBaseSerializer to give you pointers.
Specifically when you are creating new properties on a content type you need to do checking to confirm they are not already there.
uSync does that in its DeserializeProperties function. where it checks for both Key (guid) and Alias name - A t the very least you probably need to do the alias check
I would then check this for null before doing any creates:
With doctype compositions this is also a bit more complex because the property may exist on another composition further up and when you try to create it - umbraco will throw an error. this might be what's happening in your code. In uSync the CanCreateFunction does the checking on this.
Update DocumentType Datatypes in code
I'm trying to make a Function that Runs at Initialization of the Webpage and updates from a Backlog of DataTypes / Document Types
This allows us to keep Dev and live Environment Synchronized.
But i cant save Changes...
The issues is the
I asume Its because it tryes to add the documentType again instead of updating ...
I do have a working version but the code is Obsolete
any help would be appreciated..
PS. we have not yet updates and use Umbraco V 7.3.0
Hi Aki,
it looks like you are attempting to add the doctypes in a simliar way to how uSync does it, so it might be worth looking at the code in it's ContentTypeSerializer and ContentTypeBaseSerializer to give you pointers.
Specifically when you are creating new properties on a content type you need to do checking to confirm they are not already there.
uSync does that in its DeserializeProperties function. where it checks for both Key (guid) and Alias name - A t the very least you probably need to do the alias check
I would then check this for null before doing any creates:
With doctype compositions this is also a bit more complex because the property may exist on another composition further up and when you try to create it - umbraco will throw an error. this might be what's happening in your code. In uSync the CanCreateFunction does the checking on this.
mainly what it is doing is checking to see if the doctype you are using is in used in any compositions and if the property type exists in them.
is working on a reply...