Staging task while creating/updating a page

Sylvain C. asked on December 4, 2020 00:36

Hi,

With Kentico 12, I am using this API code for creating or updating pages in my tree. Unfortunately, there is no staging task being generated in the "Staging" app. How could I create these tasks when a page is created or updated or even deleted.

Thank you,

Sylvain

Correct Answer

Juraj Ondrus answered on December 7, 2020 08:31

The GetDocuments ensures the workflows, staging so it is slower as it has to execute few lines of code more than SelectNodes. Not sure if this is just one time job to get some content to the projhect or it will be periodical. If it is one time job, I would use SelectNodes and then once everything is in, you can run the complete staging sync. But if it is something periodical, I would use the GetDocuments or ensure logging of staging tasks by some extra code. Just a hint - if you do not need to have things logged in the Event log, when creating apges through the code, you can turn off the event logging to save some time too.

using (var context = new CMSActionContext())  
            {  
                context.DisableLogging()  
                //your code  
            }
0 votesVote for this answer Unmark Correct answer

Recent Answers


Juraj Ondrus answered on December 4, 2020 08:03

I assume that the staging is configured and you are logging the tasks - also I am assuming that performing those actions in the Admin UI logs the tasks correctly. If yes, then the question is what is the exact code you are using and where are you using it? I just tried using the code for page creation and update in a dummy ASPX page code behind within the admin project and it is working fine. Here are some screen shots:
Code I used and the result in Staging app.

0 votesVote for this answer Mark as a Correct answer

Sylvain C. answered on December 4, 2020 13:20 (last edited on December 4, 2020 13:20)

Thank you Juraj,

Staging is configured and works correctly when performing actions in the Admin UI whith the creation of logs.

I am using the following code for creating and updating page:

TreeProvider tree = new TreeProvider(MembershipContext.AuthenticatedUser);
parentNode = tree.SelectNodes()
                                .Path(kenticoTopContainerPath.TrimEnd('/'))
                                .OnCurrentSite()
                                .TopN(1)
                                .FirstOrDefault();

 var ENpage = tree.SelectNodes(Constants.Kentico.PageType.SharePointVenueItem)
                                .Path(kenticoTopContainerPath, PathTypeEnum.Children)
                                .WhereEquals(SharePointGenericColumns.ID, spVenueObj.ID)
                                .Culture("en-US")
                                .OnCurrentSite()
                                .TopN(1)
                                .FirstOrDefault();

 if (ENpage == null)
{
    ENpage.DocumentName = spVenueObj.VenueID;
    ENpage.DocumentCulture = culture;
    ENpage.Insert(parentNode);
}
else 
{
    ENpage.DocumentName = spVenueObj.VenueID;
    ENpage.DocumentCulture = culture;
    ENpage.Update();
}

It works fine, page are either created or updated but no log/task is created in the staging app.

S.

0 votesVote for this answer Mark as a Correct answer

Sylvain C. answered on December 4, 2020 13:31 (last edited on December 4, 2020 15:05)

Juraj, I have updated my code to reflect yours and by changing

            var ENpage = tree.SelectNodes(Constants.Kentico.PageType.SharePointVenueItem)
                            .Path(kenticoTopContainerPath, PathTypeEnum.Children)
                            .WhereEquals(SharePointGenericColumns.ID, spVenueObj.ID)
                            .Culture("en-US")
                            .OnCurrentSite()
                            .TopN(1)
                            .FirstOrDefault();

By

              var ENpage = DocumentHelper.GetDocuments()
                            .Types(Constants.Kentico.PageType.SharePointVenueItem)
                            .Path(kenticoTopContainerPath, PathTypeEnum.Children)
                            .WhereEquals(SharePointGenericColumns.ID, spVenueObj.ID)
                            .Culture("en-US")
                            .OnCurrentSite()
                            .TopN(1)
                            .FirstOrDefault();

Staging tasks are now created.

In your code example, could you confirm that if you select an existing page by TreeProvider.SelectNodes() and update it, you won't have a staging task? If yes, does it mean that DocumentHelper.GetDocuments() is the only method for generating staging logs/tasks?

What is the difference between the SelectNodes and GetDocument methods?

Is GetDocuments slower than the SelectNodes? I have thousand of pages to be created on the fly and I want to make sure that I am using the most efficient code for creating/updating them.

Thank you,

Sylvain

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.