如何将来自 REST API 或外部应用程序的 Kentico 更改关联到暂存任务组

How to associate Kentico changes from REST API or External Application to a staging task group

如何将 Kentico 更改从 REST API 或外部应用程序(如 windows 控制台应用程序)关联到暂存任务组

static void Main ( string [ ] args )
{
    UserInfo userInfo = UserInfoProvider.GetUserInfo ( "User1" );
    using ( new CMSActionContext ( userInfo ) )
    {
        TreeProvider treeProvider = new TreeProvider ( userInfo );
        NodeSelectionParameters nodeSelectionParameters = new NodeSelectionParameters
        {
            AliasPath = "Path"
        };
        TreeNode parentPage = treeProvider.SelectSingleNode ( nodeSelectionParameters );

        TreeNode newPage = TreeNode.New ( "Class", treeProvider );
        newPage.DocumentName = "Test Title";
        newPage.DocumentCulture = "en-us";
        newPage.DocumentUrlPath = "Path";

        newPage.Insert ( parentPage );
    }
}

以上代码使用用户上下文正确创建了文档和暂存任务。如何将此文档的暂存任务关联到暂存任务组?

首先,我会确保您要更改的对象在内容暂存支持的项目列表中。您可以在此处查看该列表:Content staging - What can be synchronized

只要您最终使用 Kentico 的 API 和 Content Staging is enabled, then Kentico should be creating these tasks for you. If you're updating the Kentico database directly without the API, you're probably going to run into trouble and might need to manually create staging tasks or use the API to perform synchronisation

我们可以使用 Synchronization ActionContext class 将 API 更改关联到暂存任务组。

    static void Main ( string [ ] args )
    {
        List<TaskGroupInfo> taskGroups = TaskGroupInfoProvider.GetTaskGroups ( ).WhereEquals ( "TaskGroupCodeName", "MyTaskGroup" ).ToList ( );
        using ( new SynchronizationActionContext ( ) { TaskGroups = taskGroups } )
        {
            UserInfo userInfo = UserInfoProvider.GetUserInfo ( "User1" );
            using ( new CMSActionContext ( userInfo ) )
            {
                TreeProvider treeProvider = new TreeProvider ( userInfo );
                NodeSelectionParameters nodeSelectionParameters = new NodeSelectionParameters
                {
                    AliasPath = "Path"
                };
                TreeNode parentPage = treeProvider.SelectSingleNode ( nodeSelectionParameters );

                TreeNode newPage = TreeNode.New ( "Class", treeProvider );
                newPage.DocumentName = "Test Title";
                newPage.DocumentCulture = "en-us";
                newPage.DocumentUrlPath = "Path";

                newPage.Insert ( parentPage );
            }
        }
    }