Adding Pages to Categories Module Isn't Creating a Staging Task, How to Stage Category Objects?

kentico guy asked on June 29, 2021 19:49

I am using Kentico 12 portal engine and it seems that when I add pages to categories it's not creating a staging task. I am wondering if there is any way to stage categories when a page is added to them?

I am digging around and I found this event

DocumentCategoryInfo.TYPEINFO.Events.LogChange.Before += LogDocumentCategory_Before;

so I added

        private void LogDocumentCategory_Before(object sender, LogObjectChangeEventArgs e)
    {
        var checkLogStaging = e.Settings.LogStaging;
        e.Settings.LogStaging = true;
        e.Settings.LogExportTask = true;
    }

and interestingly enough the LogStaging setting is already true, so shouldn't that mean a staging task should be created when this action occurs? the problem is that despite setting the LogStaging (already true anyway) I'm still not seeing any staging tasks created when I add pages to categories.

Any ideas here?

Recent Answers


Juraj Ondrus answered on June 30, 2021 07:29

What is the exact version including hotfix, please? Also, what are the steps to reproduce the issue? Where and how are you adding the categories to pages? I just tested it and it is working fine.
I am using the Multiple categories selector form control and adding the categories on the Form tab. Sample screen shot. Adding a category and saving the page generates the update task which contains also the categories info.
And I tested the same when adding categories on the page's Properties -> Categories tab with the same result.

Please, provide a full bug report description with all the details how to reproduce the issue. Thank you!

0 votesVote for this answer Mark as a Correct answer

kentico guy answered on June 30, 2021 13:58

Thanks for the response. I used the categories tab and that generated a task. I guess it's some type of glitch with our custom form control that sets it.

I am using 12.0.92

0 votesVote for this answer Mark as a Correct answer

Juraj Ondrus answered on June 30, 2021 14:11

It makes sense now. How are you saving the page? The staging task is being created upon saving the page - the "Update page XXX". So, maybe in your form control you just need to call the API method to save the page - page.Update();

0 votesVote for this answer Mark as a Correct answer

kentico guy answered on July 6, 2021 17:44

Thanks for the response. I was actually able to fix it by creating a custom module that manually creates a staging task when any document update happens. I've noticed sometimes randomly that staging tasks aren't created when a document is updated so I decided to extend and do it manually. Plus, it's nice to be able to generate a staging task any time that the save button is hit.

[assembly: RegisterModule(typeof(DocumentCategoryUpdateHandler))]
public class DocumentCategoryUpdateHandler : Module
{
    public DocumentCategoryUpdateHandler() : base("DocumentUpdateEvents")
    {

    }

    /// <summary>
    /// Assigns the custom staging task EventArg methods of this class to the event delegates of
    /// the userinfo types for before and after the objects get changed.
    /// </summary>
    protected override void OnInit()
    {
        base.OnInit();
        DocumentEvents.Update.After += DocumentUpdate_After;
    }

    /// <summary>
    /// Fires after the document is updated and manually creates staging task
    /// so that all fields get staged with the document
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void DocumentUpdate_After(object sender, DocumentEventArgs e)
    {
        // there is a glitch where sometimes the content category does not
        // create a staging task when the document is saved.
        // this code manually creates a staging task when a document is saved
        // to ensure that we always get the document update
        try
        {
            var document = DocumentHelper.GetDocuments()
                .WhereEquals("DocumentID", e.Node.DocumentID)
                .TopN(1)
                .First();

            DocumentSynchronizationHelper.LogDocumentChange(document, TaskTypeEnum.UpdateDocument, e.TreeProvider);
        }
        catch (Exception ex)
        {
        }
    }
}

This way I don't need to add that page.Update() into every custom control. This will do it everywhere in the app at once.

0 votesVote for this answer Mark as a Correct answer

Sean Wright answered on August 19, 2021 23:35

Just as an fyi, DocumentEventArgs.Node contains the same information you are retrieving with your query using the DocumentHelper.GetDocuments(), so you could remove that query and instead call this directly with the data you already have access to:

DocumentSynchronizationHelper.LogDocumentChange(e.Node, TaskTypeEnum.UpdateDocument, e.TreeProvider);

0 votesVote for this answer Mark as a Correct answer

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