In special cases, you may need to use Kentico CMS API to perform your own synchronization process. There are several methods you can use to work with synchronization.
WorkflowEngine.DocumentHelper.LogSynchronization |
Creates a synchronization task for the specified document. This method does not actually perform the synchronization, it only creates the task which can be later synchronized. By default, the method creates the task for all the enabled servers. You can use the overriden version with serverId parameter to specify the particular server. |
CMSStaging.StagingHelper.RunSynchronization |
Runs the synchronization of specified task for the specified server or servers. |
Here is an example code how to synchronize the content of the document “/Home” to server “Staging.Target1”:
[C#]
using CMS.TreeEngine; using CMS.CMSHelper; using CMS.Staging; using CMS.WorkflowEngine;
TreeProvider tree = new TreeProvider(CMSContext.CurrentUser); // Get the base document record TreeNode node = tree.SelectSingleNode(CMSContext.CurrentSiteName, "/Home", "en-us", false, null, false); if (node != null) { // Get full document record (required for synchronization logging) node = tree.SelectSingleNode(CMSContext.CurrentSiteName, node.NodeAliasPath, node.DocumentCulture, false, node.NodeClassName, false); if (node != null) { // Get the server ServerInfo si = ServerInfoProvider.GetServerInfo("Staging.Target1", CMSContext.CurrentSiteID); if (si != null) { // Log the synchronization task for the given server TaskInfo ti = DocumentHelper.LogSynchronization(node, TaskTypeEnum.UpdateDocument, tree, si.ServerID); if (ti != null) { // Run the task synchronization StagingHelper.RunSynchronization(ti.TaskID, si.ServerID); } } } } |
You can also use low level operations from TaskInfoProvider, SynchronizationInfoProvider and ServerInfoProvider to achieve synchronization, but previous methods should be enough to perform any simple synchronization actions.
The following example shows how you can synchronize the administrator user account. Synchronization of any other objects is done the same way using the API, as all objects implement the IInfoObject interface.
[C#]
using CMS.SiteProvider; using CMS.Staging; using CMS.CMSHelper;
// Gets the object UserInfo userObj = UserInfoProvider.GetUserInfo("administrator"); if (userObj != null) { // Gets the server ServerInfo si = ServerInfoProvider.GetServerInfo("Staging.Target1", CMSContext.CurrentSiteID); if (si != null) { // Creates the synchronization task TaskInfo ti = TaskInfoProvider.LogSynchronization(userObj, TaskTypeEnum.UpdateObject, null, null, si.ServerID); if (ti != null) { // Runs the synchronization task StagingHelper.RunSynchronization(ti.TaskID, si.ServerID); } } } |
Page url: http://devnet.kentico.com/docs/devguide/index.html?staging_synchronization_using_api.htm