Site structure
Version 5.x > Site structure > Add custom field to system table Site View modes: 
User avatar
Member
Member
Aon_Vlado - 10/19/2011 4:29:52 PM
   
Add custom field to system table Site
Is it possible to add a custom field to system table CMS_Site and how to address it in code? I would need it for a global site property.

Thanks,
Vlado

User avatar
Kentico Support
Kentico Support
kentico_jurajo - 10/20/2011 7:52:41 AM
   
RE:Add custom field to system table Site
You could make these custom changes (please note that upgrades may re-write them):

1. Go to CMS_Class table in database.
2. Find "Site" row
3. set the ClassShowAsSystemTable attribute as true
4. then you can see the Site table in: CMS SiteManager -> Development -> System tables and you may add new fields.

Then, in the code you would need to get the site object and then you can use GetValue/SetValue("columnName") methods to get/set the values.

Best regards,
Juraj Ondrus

User avatar
Member
Member
Aon_Vlado - 10/20/2011 1:33:28 PM
   
RE:Add custom field to system table Site
Thank you for your quick response. It works exactly as you described. I assume there is no UI for this setting similar to User table. Only way to enter the data is directly in database. Correct?

User avatar
Kentico Support
Kentico Support
kentico_jurajo - 10/21/2011 12:06:19 AM
   
RE:Add custom field to system table Site
Hi,

I am sorry but I am confused. The CMS_User table is already listed in Site Manager -> Development -> Syste tables section so, I am not sure what you mean right now. Could you please explain?

Thank you.

Best regards,
Juraj Ondrus

User avatar
Member
Member
Aon_Vlado - 10/21/2011 5:41:52 AM
   
RE:Add custom field to system table Site
Iam looking for a way to enter data to my new custom fields into CMS_Site not CMS_User. Similar to as we can do it for User.
Thanks.

User avatar
Certified Developer 9
Certified Developer 9
charbf - 10/21/2011 9:02:57 AM
   
RE:Add custom field to system table Site
You would need to modify this page to include your new fields

CMSSiteManager\Sites\Site_Edit_General.aspx

User avatar
Member
Member
Aon_Vlado - 8/8/2012 3:37:53 PM
   
RE:Add custom field to system table Site
I would like to thank you for the answers. I know it has been 10 months since I added the field ClientName to CMS_Site table and it works just fine. Now we need to display that in Sites page (site_list.aspx). I was trying to change the site_list.xml like this:
<?xml version="1.0" encoding="utf-8" ?>
<grid>
<actions parameters="SiteID">
<action name="editSite" caption="$General.Edit$" icon="Edit.png" />
<action name="delete" caption="$General.Delete$" icon="Delete.png" />
<separator />
<action name="editContent" externalsourcename="editcontent" caption="$Unigrid.SiteList.Actions.EditContent$" icon="Editcontent.png" />
<action name="openLiveSite" externalsourcename="openlivesite" caption="$Unigrid.SiteList.Actions.OpenLiveSite$" icon="Livesite.png" />
<separator />
<action name="start" caption="$Unigrid.SiteList.Actions.Start$" icon="Run.png" />
<action name="stop" caption="$Unigrid.SiteList.Actions.Stop$" icon="Stop.png" />
<separator />
<action name="export" caption="$Unigrid.SiteList.Actions.Export$" icon="Exportsite.png" />
</actions>
<columns>
<column source="SiteDisplayName" caption="$general.sitename$" wrap="false" localize="true" >
<filter type="text" />
</column>
<column source="##ALL##" externalsourcename="ClientName" caption="Client name" wrap="false">
<filter type="text" />
</column>
<column source="SiteDescription" caption="Plan name" wrap="false" width="100%" localize="true" >
<filter type="text" />
</column>
<column source="SiteDomainName" caption="$Unigrid.SiteList.Columns.SiteDomainName$" wrap="false">
<filter type="text" />
</column>
<column source="##ALL##" externalsourcename="sitestatus" caption="$Unigrid.SiteList.Columns.SiteStatus$" wrap="false" />
<column source="Documents" caption="$general.documents$" wrap="false" />
<column source="##ALL##" externalsourcename="culture" caption="$Unigrid.SiteList.Columns.DefaultCulture$" wrap="false" />
</columns>
<objecttype name="cms.sitelist" columns="SiteID, SiteName, SiteDisplayName, SiteDescription, SiteStatus, SiteIsOffline, SiteDomainName, Documents" />
<options>
<key name="DisplayFilter" value="true" />
</options>
</grid>

but I am getting error “[UniGrid] : Error during reloading data.” which is caused by

<objecttype name="cms.sitelist" columns="SiteID, SiteName, SiteDisplayName, ClientName, SiteDescription, SiteStatus, SiteIsOffline, SiteDomainName, Documents" />

When I remove ClientName I get in all rows of that column “System.Data.DataRowView” text.

The new SiteDescription column works OK probably because it is cms.site object system property, but not the custom field.

What is the magic to do?

Thanks,
Vlado

User avatar
Kentico Support
Kentico Support
kentico_jurajo - 8/9/2012 3:10:35 AM
   
RE:Add custom field to system table Site
Hi,

You also need to configure/modify the UniGrid control which is using this XML to display the data. It is placed on \CMSSiteManager\Sites\site_list.aspx

Also, this documentation about UniGrid controls will help you with the configuration: UniGrid

Best regards,
Juraj Ondrus

User avatar
Member
Member
Aon_Vlado - 8/22/2012 4:08:42 PM
   
RE:Add custom field to system table Site
Hmm, there is not much to modify:
<cms:UniGrid ID="UniGridSites" runat="server" GridName="site_list.xml" OrderBy="SiteDisplayName" IsLiveSite="false" ObjectType="cms.site" />

The site_list.xml has the column in it:
<column source="##ALL##" externalsourcename="ClientName" caption="Client name" wrap="false">
<filter type="text" />
</column>
Vlado

User avatar
Member
Member
Aon_Vlado - 8/22/2012 4:15:59 PM
   
RE:Add custom field to system table Site
I think that the custom column should be added here to xml:

<objecttype name="cms.sitelist" columns="SiteID, SiteName, ClientName, SiteDisplayName, ClientName, SiteDescription, SiteStatus, SiteIsOffline, SiteDomainName, Documents" />

but it does not like it. Probably the class cms.sitelist does not know about it and I cannot find the definition of cms.sitelist to alter it.

Regards,
Vlado

User avatar
Kentico Support
Kentico Support
kentico_jurajo - 8/23/2012 3:33:56 AM
   
RE:Add custom field to system table Site
Hi again,

I found the problem - it is caused by the fact that the columns for the site list object are hard-coded in an assembly. I have already added a requirement to change this to act in the same way as e.g. for users uni-grid.

The current workaround involves the next steps - however, they are not 100% upgrade/hotfix proof, so please consider the changes and make sure you have actual DB and project backups:

1. Assuming that the custom column to the Site table was already added as mentioned above in this thread.
2. go to the database and find the view View_CMS_Site_DocumentCount
3. Modify this view and add your custom column to its definition and save the change.
4. Open the site_list.xml file and replace the "objecttype" line (mentioned in the previous post) with the "old way" line:

<query name="cms.site.selectsitelist" columns="SiteID, SiteName, SiteDisplayName, SiteStatus, SiteIsOffline, SiteDomainName, Documents, customColumn"></query>

5. Open the site_list.aspx.cs file and in the UniGridSites_OnExternalDataBound event specify the switch case for your custom column.
6. Save all the changes and test it. (I hope I haven't missed anything :-))

Best regards,
Juraj Ondrus

User avatar
Member
Member
Aon_Vlado - 8/23/2012 7:09:54 AM
   
RE:Add custom field to system table Site
Thank you Juraj,

As you said this is not hotfix proof so I rather wait for the hotfix. How long does it usually take to publish it?

BTW: will you plant a tree for me?

Vlado

User avatar
Kentico Support
Kentico Support
kentico_jurajo - 8/23/2012 8:20:55 AM
   
RE:Add custom field to system table Site
Hi,

I am sorry for the confusion but I didn't told that it is a bug and that it will be fixed in a hotfix :-)

Currently, it is by design and I have submitted it to the developers as a requirement to change it - I hope it will be changed in v7.

There won't be any hotfix for this. What I meant is that when upgrading or hotfixing, the files you have edited might by overwritten back to defaults.

Best regards,
Juraj Ondrus

User avatar
Member
Member
Aon_Vlado - 8/23/2012 9:37:36 AM
   
RE:Add custom field to system table Site
Oh, OK. I got it. Thank you any way.
Vlado