Content staging - user changes excluded but still being pushed

Tom Troughton asked on January 25, 2016 12:23

I have content staging set up. I want to use this module to synchronise all object changes between dev and UAT. However I don't want users synchronised. This is mainly because user passwords differ between dev and UAT.

Therefore I've followed Kentico documentation to exclude users from the staging process. I'm using the following loader attribute:

public class KingspanUserEvents : CMSLoaderAttribute
{
    public override void Init()
    {
        UserInfo.TYPEINFO.Events.LogChange.Before += LogUserChange_Before;
    }

    private void LogUserChange_Before(object sender, CMS.DataEngine.LogObjectChangeEventArgs e)
    {
        // Gets the synchronized object
        GeneralizedInfo obj = e.Settings.InfoObj;

        if (obj != null)
        {
            // Always disable user synchronisation
            e.Settings.LogStaging = false;
        }
    }
}

Now, when I change a user I can see that no task is logged in the staging module. So far so good.

However, there are still object actions that seem to be triggering user synchronisation. For example, I think one case is where I change security settings for a widget, selecting new authorised roles. It seems as though users associated with these roles are synchronised.

Can anyone suggest a method to ensure that users are permanently and consistently excluded from staging?

Thank you.

Recent Answers


Roman Hutnyk answered on January 25, 2016 14:39

Nat, try this

private void LogUserChange_Before(object sender, CMS.DataEngine.LogObjectChangeEventArgs e)
{
    e.Using(new CMSActionContext()
    {
        LogSynchronization = false
    }
    );
}
0 votesVote for this answer Mark as a Correct answer

Zach Perry answered on January 25, 2016 15:15 (last edited on January 25, 2016 15:38)

DocumentationYou can do it on the task instead of the user:

 public override void Init()
    {
        // Assigns a handler to the StagingEvents.LogTask.Before event
        // This event occurs before the system creates content staging synchronization tasks
        StagingEvents.LogTask.Before += LogTask_Before;
    }


    //Stop staging tasks from being created.
    private void LogTask_Before(object sender, StagingLogTaskEventArgs e)
    {
        // Gets the synchronized object
        BaseInfo synchronizedObject = e.Object;

        // Gets the synchronization task
        StagingTaskInfo stagingTask = e.Task;

        // Cancels the creation of content staging tasks for the deletion of role objects
        if (synchronizedObject.TypeInfo.ObjectType == CMS.Membership.UserInfo.OBJECT_TYPE)
        {
            e.Cancel();
        }
    }
0 votesVote for this answer Mark as a Correct answer

Martin Hejtmanek answered on January 25, 2016 16:03

Hi, if you want to disable it completely for all actions that trigger logging of staging tasks, you should be able to do that with this code in your Init method:

public override void Init()
{
    CMS.Membership.UserInfo.TYPEINFO.SynchronizationSettings.LogSynchronization = CMS.DataEngine.SynchronizationTypeEnum.None;
}

This way it will also hide Users from the staging UI tree.

Cancelling staging tasks through event handler is more suitable for filtering specific objects rather than elimination of a whole object type.

2 votesVote for this answer Mark as a Correct answer

Tom Troughton answered on January 25, 2016 17:27

Thanks everyone for your answers. It will take a little while to test but I'll get back to you once I've tried your suggestions. At first glance it would appear Martin's suggestion is the place to start.

0 votesVote for this answer Mark as a Correct answer

Tom Troughton answered on January 26, 2016 11:49

Hi. Just tried Martin's suggestion and for me (on Kentico 8.2) CMS.Membership.UserInfo.TYPEINFO does not contain a SynchronizationSettings property. Is that a new Kentico 9 thing?

0 votesVote for this answer Mark as a Correct answer

Zach Perry answered on January 28, 2016 17:31

Might be.

Did you try

CMS.Membership.UserInfo.TYPEINFO.LogSynchronization = CMS.DataEngine.SynchronizationTypeEnum.None;
0 votesVote for this answer Mark as a Correct answer

Tom Troughton answered on February 19, 2016 11:20

For anyone reading this, I now have a better understanding of why this is happening. But still no solution. Please refer to new devnet thread and also Stack Overflow thread.

0 votesVote for this answer Mark as a Correct answer

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