|
Member
|
garet
-
4/28/2011 9:40:25 AM
Is there a simple way to clone a document type?
Hi, I wanted to update the Blog Transformations (found under document types) but keep them specific to my site.
For example instead of CMS.Blog I wanted to have SC.Blog.
My first thought was to Export CMS.Blog, then Import it in. Hoping that the system would show two, then I could simply rename it. That didn't work. Next I thought of modifying the exported zip file, it is just a text file. The question is which text to adjust, only the values CMS. ? My fear here is corrupting my installation. Any thoughts?
I did find an article that suggests writing some code to clone it: http://devnet.kentico.com/Knowledge-Base/API-and-Internals/How-to-clone-a-document-type.aspx
What I am unclear on is this a 'throwaway' page. Create the page, let it rip, it copies the article document type?
Apparently there is thought into adding it into version 6. I am surprised this hasn't come up before. http://kentico.uservoice.com/forums/33767-general-suggestions/suggestions/392432-copy-document-type
I suppose I could back up my site by exporting it. That way if I blow it up I can reinstall it.
Anyone have any suggestions on cloning a transformation (document type)?
Thanks in advance
|
|
|
Kentico Support
|
kentico_zdenekc
-
4/28/2011 6:05:18 PM
RE:Is there a simple way to clone a document type?
Hi, For cloning the document type using export/import, you would need to change many values and keys in the xml structures inside the package. We can't recommend this approach. The KB article can be used, the page is just to run the code...so yes, it's kinda 'disposable'. There are plans on adding support for cloning system objects into next version, however it's not yet promised feature, so I can't give any guarantees. Best way to backup the site is to have database and project folder backups... this allows fastest and most accurate restore of the whole application with data. Generally, if the requirement is just about cloning the transformations, then you could either manually copy the transformation codes to your custom document type, or use API to do that programmatically, e.g. through TransformationInfoProvider and TransformationInfo object(s). For more details please see Kentico CMS API Reference within Documentation on devnet.kentico.com. Regards, Zdenek
|
|
|
Member
|
garet
-
4/29/2011 9:03:24 AM
RE:Is there a simple way to clone a document type?
Thanks Zdenek I will use the coding example then.
Copying the transformation is a simple copy/paste. It is the document type details (fields, transformations, queries, etc) that make up the document type was a bit more complex to copy/recreate.
Thanks again, I'm looking forward to version 6.
Take care, Garet
|
|
|
Member
|
wensveen-evident
-
5/24/2011 7:00:39 AM
RE:Is there a simple way to clone a document type?
Hi,
I used the code example in the KB article. Most of the times it works fine, however, one time it failed on CMS.DataEngine.TableManager.CreateTable(dci.ClassTableName, CMS.DataEngine.TableManager.GetPrimaryKeyColumns(orgTableName)[0].ToString()) with an index out of range exception. After that the document type could not be used nor deleted because the actual table was never created.
I fixed it by creating a table with the correct name in the DB with SQL server manager, and then deleting the doctype.
USE WITH CARE!
I've created an aspx page with inputs for: source class name, destination class name, dest. table name, dest. display name and dest. primary key column name, and modified the code behind accordingly. This makes the code somewhat more versatile and kills this bug as a bonus.
|
|
|
Member
|
wensveen-evident
-
5/25/2011 3:30:55 AM
RE:Is there a simple way to clone a document type?
More problems. The version of the page where I could type in the primary column name creates a table with the typed in column name AND the column from the original table (but not as PK). Using the resulting document type does not work at all. Instead it corrupts the database when you try to create a document based on this type. Somehow a Node is created but no Document. Thereafter it is impossible to delete the stale node from the tree.
When I create a document type where the PK is copied from the original table (see caution above), the resulting table is fine (although I'd really like it to have another PK column name). But when I try to create a document based on this type an SQL error occurs:
"An error occurred when saving data:[DataConnection.ExecuteQuery]: Query: INSERT INTO VTL_Event ([NewsPressArticleID], [Title], [Author], [Date], [StartDate], [EndDate], [Summary], [Image], [ImageDescription], [BodyText], [Tags], [Sector], [Deelmarkt], [Onderwerp], [ShowSubnavigation], [ShowBreadcrumb], [EventType], [Provincie] ) VALUES ( @NewsPressArticleID, @Title, @Author, @Date, @StartDate, @EndDate, @Summary, @Image, @ImageDescription, @BodyText, @Tags, @Sector, @Deelmarkt, @Onderwerp, @ShowSubnavigation, @ShowBreadcrumb, @EventType, @Provincie); SELECT SCOPE_IDENTITY() AS [EventID] : caused exception: Cannot insert the value NULL into column 'NewsPressArticleID', table 'xxxx.dbo.VTL_Event'; column does not allow nulls. INSERT fails. The statement has been terminated."
It seems as though it tries to insert NULL into the PK column.
I strongly advice to take down the KB article as it has only caused trouble thus far. Or at the very least put up some disclaimers.
Regards, Matthijs
|
|
|
Kentico Support
|
kentico_jurajo
-
5/26/2011 6:16:19 AM
RE:Is there a simple way to clone a document type?
Hi,
So far when I used that code and also recommended to other customer, it worked fine.
Could you please describe us what inputs are you using and also more details about how are you using it? E.g. some examples?
How are you creating the primary key? Are you adding it in this line of code:
CMS.DataEngine.TableManager.CreateTable(dci.ClassTableName, CMS.DataEngine.TableManager.GetPrimaryKeyColumns(orgTableName)[0].ToString()); Could you please provide us with the code so we can check it or run it in debug mode so you can see where the data becomes inconsistent?
Please note - the intention of cloning document type is to have an identical document type just with other name. So making changes to its definition, especially to primary keys can cause issues since other things from the document type are bound to that original PK.
Best regards, Juraj Ondrus
|
|
|
Member
|
wensveen-evident
-
5/27/2011 2:25:01 AM
RE:Is there a simple way to clone a document type?
Hi,
I've actually changed the creation of the PK back to what it was in the KB article, because I ended up with two ID columns. The line is dangerous though, because when GetPrimaryKeyColumns returns null or an empty list, an exception is thrown and the CreateTable method is never called, putting the DB in an inconsistent state. This happened to me only once however.
My colleague made his own version of an aspx page with your code as code behind and found that when the class name is in lower-case the code works, but when the class name contains capitals, it (sometimes) fails.
I'll do a little more research and then post back.
Regards, Matthijs
|
|
|
Kentico Support
|
kentico_jurajo
-
5/31/2011 1:44:45 AM
RE:Is there a simple way to clone a document type?
Hi,
Please, let us know if you will find something interesting. I checked the code and the upper or lower case document type code name should not be the problem - it is case insensitive. I guess there is something else.
If possible, could you please post also the code you are using as it is so we can reproduce the issue?
Best regards, Juraj Ondrus
|
|
|