Excluding content from staging and integration

Event handlers allow you to disable content staging and integration bus synchronization for certain pages or objects. The system provides two types of events that you can use:

Excluding content by handling page or object changes

When changes are made to pages and objects (such as creating, editing or deleting), the system logs the change data. Content staging and the integration bus use the data to create synchronization tasks, which then transfer the changes to the target server or application.

To completely prevent the system from starting the staging or integration process, handle the following events:

  • DocumentEvents.LogChange.Before
  • ObjectEvents.LogChange.Before (or <name>Info.TYPEINFO.Events for specific object types)

You can use two different approaches to disable staging or integration inside the event handlers:

Set the properties of the event handler’s LogDocumentChangeArgs/LogObjectChangeArgs parameter:




e.Settings.LogStaging = false;
e.Settings.LogIntegration = false;


Directly switches off logging of staging or integration tasks. The properties can be changed later during the execution of the LogChange event.

OR

Call the Using method of the event handler’s LogDocumentChangeArgs/LogObjectChangeArgs parameter with a new CMSActionContext object as the parameter. Set the LogSynchronization or LogIntegration properties in the CMSActionContext constructor.




e.Using(new CMSActionContext() {LogSynchronization = false, LogIntegration = false} );


Disables logging of staging or integration tasks within the entire context of the LogChange event.

Example

The following example demonstrates how to use LogChange handlers to disable content staging and integration for pages in the /Archive section of a website.

  1. Open your Xperience solution in Visual Studio (using the WebApp.sln file).

  2. Create a custom module class.

    • Add the class into a custom assembly (Class Library project) within the solution.
  3. Override the module’s OnInit method and assign handlers to the DocumentEvents.LogChange.Before event.

    
    
    
     using CMS;
     using CMS.Base;
     using CMS.DataEngine;
     using CMS.DocumentEngine;
    
     // Registers the custom module into the system
     [assembly: RegisterModule(typeof(LogChangeHandlerModule))]
    
     public class LogChangeHandlerModule : Module
     {
         // Module class constructor, the system registers the module under the name "LogChangeHandlers"
         public LogChangeHandlerModule()
             : base("LogChangeHandlers")
         {
         }
    
         // Contains initialization code that is executed when the application starts
         protected override void OnInit()
         {
             base.OnInit();
    
             // Assigns a handler to the DocumentEvents.LogChange.Before event
             // This event occurs when pages are modified, before the system starts logging the changes
             DocumentEvents.LogChange.Before += LogDocumentChange_Before;
         }
     }
    
    
     
  4. Define the handler methods (inside the custom module class):

    
    
    
     // Disables logging of staging and outgoing integration tasks for the content of pages in the /Archive section of the website
     private void LogDocumentChange_Before(object sender, LogDocumentChangeEventArgs e)
     {
         // Gets the synchronized page
         TreeNode page = e.Settings.Node;
    
         // Excludes pages under the "/Archive" path from content staging and integration bus synchronization
         if (page.NodeAliasPath.StartsWith("/Archive"))
         {
             e.Using(new CMSActionContext()
             {
                 LogSynchronization = false,
                 LogIntegration = false
             }
             );
         }
     }
    
    
     
  5. Save the class and Rebuild the solution.

The custom handlers ensure that the system does not create synchronization tasks for the content and metadata of pages in the website’s /Archive section.

Excluding content by handling synchronization tasks

Content staging and the integration bus use synchronization tasks to transfer changes to the target server or application. You can cancel the creation of synchronization tasks during the following system events:

  • StagingEvents.LogTask.Before
  • IntegrationEvents.LogInternalTask.Before

Excluding content via the LogTask events provides the following advantages and disadvantages:

  • Allows you to access the data of the synchronization task inside the event handler. For example, you can disable only specific types of synchronization tasks.
  • The system needs to prepare the synchronization data for every object/page change, which requires more overhead than when excluding content through LogChange handlers.

Example

The following example demonstrates how to use the LogTask handler to disable content staging for the deletion of role objects and for content synchronization of certain pages.

  1. Open your Xperience solution in Visual Studio (using the WebApp.sln file).

  2. Create a custom module class.

    • Add the class into a custom assembly (Class Library project) within the solution.
  3. Override the module’s OnInit method and assign a handler to the StagingEvents.LogTask.Before event.

    
    
    
     using CMS;
     using CMS.DataEngine;
     using CMS.Synchronization;
     using CMS.DocumentEngine;
    
     // Registers the custom module into the system
     [assembly: RegisterModule(typeof(LogTaskHandlerModule))]
    
     public class LogTaskHandlerModule : Module
     {
         // Module class constructor, the system registers the module under the name "LogTaskHandlers"
         public LogTaskHandlerModule()
             : base("LogTaskHandlers")
         {
         }
    
         // Contains initialization code that is executed when the application starts
         protected override void OnInit()
         {
             base.OnInit();
    
             // 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;
         }
     }
    
    
     
  4. Define the handler method (inside the custom module class):

    
    
    
     private void LogTask_Before(object sender, StagingLogTaskEventArgs e)
     {
         // Handles content staging exclusion of documents
         if (e.Object is TreeNode)
         {
             // Gets the synchronized document
             TreeNode document = (TreeNode)e.Object;
    
             // Cancels the creation of content staging tasks for documents under the "/Archive" path
             if (document.NodeAliasPath.StartsWith("/Archive"))
             {
                 e.Cancel();
             }
         }
         // Handles content staging exclusion of objects
         else
         {
             // 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.RoleInfo.OBJECT_TYPE)
                  && (stagingTask.TaskType == TaskTypeEnum.DeleteObject))
             {
                 e.Cancel();
             }
         }
     }
    
    
     
  5. Save the class and Rebuild the solution.

The handler ensures that the system does not create staging tasks:

  • For changes made to pages in the website’s /Archive section
  • When a role is deleted from the system