Accessing The Inbuilt Sitecore Publishing Dialog With SPS Configured

by ADMIN 69 views
Iklan Headers

Introduction

In Sitecore development, the publishing process is a critical aspect of content management. The Sitecore Publishing Service (SPS) offers a robust and scalable solution for publishing content across various channels. However, there are scenarios where developers and content authors might need to access the inbuilt default Sitecore Publishing Dialog, even when SPS is configured. This article delves into how to achieve this, providing a comprehensive guide for developers and content administrators.

Understanding Sitecore Publishing Service (SPS)

The Sitecore Publishing Service is a microservice-based module that enhances the publishing capabilities of Sitecore. It provides significant improvements in performance, scalability, and reliability compared to the traditional Sitecore publishing pipeline. By offloading the publishing workload to dedicated servers, SPS ensures that the Sitecore Content Management (CM) instance remains responsive and efficient, especially during peak publishing times.

Key benefits of using Sitecore Publishing Service include:

  • Improved Performance: SPS can handle a large volume of publishing operations more efficiently than the standard Sitecore publishing pipeline.
  • Scalability: The microservices architecture allows SPS to scale horizontally, accommodating growing content needs.
  • Reliability: SPS reduces the load on the CM instance, ensuring better stability and responsiveness.
  • Parallel Publishing: SPS supports parallel publishing, enabling faster content delivery across multiple channels.

The Need for the Inbuilt Sitecore Publishing Dialog

Despite the advantages of SPS, there are situations where the inbuilt Sitecore Publishing Dialog is preferable or necessary. The default dialog offers a familiar interface for content authors and provides specific functionalities that might not be immediately available or easily accessible through SPS dashboards. Some common scenarios include:

  • Specific Publishing Options: The inbuilt dialog provides granular control over publishing options, such as publishing related items, republishing the entire site, or clearing the publishing queue.
  • Troubleshooting: When diagnosing publishing issues, the inbuilt dialog’s logging and feedback mechanisms can be invaluable.
  • Legacy Workflows: Some organizations may have existing workflows or custom functionalities that rely on the inbuilt publishing pipeline.
  • Development and Testing: During development and testing phases, developers might prefer the simplicity and direct feedback of the inbuilt dialog.

Accessing the Inbuilt Sitecore Publishing Dialog: A Step-by-Step Guide

To access the inbuilt Sitecore Publishing Dialog when SPS is configured, you need to bypass the default behavior that redirects publishing operations to the SPS dashboard. This can be achieved through configuration adjustments and code modifications. Here’s a detailed guide:

1. Configuration Adjustments

The primary method to revert to the inbuilt dialog is by modifying the Sitecore configuration files. Specifically, you need to adjust the settings related to the Sitecore Publishing Service within the Sitecore.config and related configuration files. Follow these steps:

  • Locate the Configuration Files: Navigate to the \[Your Sitecore Instance]\Website\App_Config\Modules\PublishingService directory. Here, you will find configuration files such as Sitecore.Publishing.Service.config and potentially other patch files.
  • Disable SPS Configuration: Within these files, you need to disable or comment out the configurations that redirect publishing operations to SPS. Look for settings that define the publishing mode or handlers. A common approach is to comment out the <strategies> section within the <publish> node in Sitecore.Publishing.Service.config. For example:
<!--
<publish>
    <strategies hint="list:AddPublishingStrategy">
        <strategy ref="publishingService" />
    </strategies>
</publish>
-->
  • Patch Files: If the SPS configurations are defined in patch files (which is a best practice), locate the relevant patch file and either remove or comment out the specific settings. Patch files are typically located in the \App_Config\Include or \App_Config\Modules directories.
  • Example Patch File Modification: Suppose you have a patch file named Sitecore.Publishing.Service.Custom.config with the following content:
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:set="http://www.sitecore.net/xmlconfig/set/">
  <sitecore>
    <publish>
      <strategies hint="list:AddPublishingStrategy">
        <strategy ref="publishingService" />
      </strategies>
    </publish>
  </sitecore>
</configuration>
To disable SPS, you would modify this file as follows:
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:set="http://www.sitecore.net/xmlconfig/set/">
  <sitecore>
    <publish>
      <!--
      <strategies hint="list:AddPublishingStrategy">
        <strategy ref="publishingService" />
      </strategies>
      -->
    </publish>
  </sitecore>
</configuration>
  • Verify Configuration: After making these changes, ensure that the SPS-related configurations are effectively disabled. You can verify this by checking the Sitecore logs for any errors or warnings related to publishing. Additionally, confirm that the publishing operations are no longer being redirected to the SPS dashboard.

2. Code Modifications (If Necessary)

In some cases, configuration adjustments might not be sufficient, especially if there are custom code implementations that explicitly invoke the SPS. In such scenarios, you need to modify the code to bypass the SPS and use the inbuilt publishing pipeline.

  • Identify SPS Invocations: Review your codebase for any instances where the Sitecore Publishing Service API is being used. This might include custom commands, event handlers, or scheduled tasks that trigger publishing operations.
  • Conditional Logic: Implement conditional logic to use the inbuilt publishing pipeline when necessary. This can be achieved by checking a configuration setting or a user-specific preference.
  • Example Code Modification: Suppose you have a custom command that uses the SPS to publish items:
using Sitecore.Publishing.Service;
using Sitecore.Publishing.Service.Client;
using Sitecore.Publishing.Service.Client.Responses;

public class CustomPublishCommand
{
    public void PublishItem(Guid itemId, string targetDatabase)
    {
        // SPS Publishing Code
        var client = new PublishingServiceClient(new Uri("Your SPS Endpoint"));
        var publishOptions = new PublishOptions
        {
            RootItemId = itemId,
            TargetDatabase = targetDatabase,
            // Other options
        };
        var response = client.PublishItem(publishOptions);
        // Handle Response
    }
}
To modify this code to use the inbuilt publishing pipeline, you can add a conditional check:
using Sitecore.Publishing;
using Sitecore.Data;
using Sitecore.Data.Items;
using Sitecore.Configuration;

public class CustomPublishCommand
{
    public void PublishItem(Guid itemId, string targetDatabase)
    {
        if (Settings.GetBoolSetting("UseInbuiltPublishing", false))
        {
            // Inbuilt Publishing Code
            Database sourceDb = Database.GetDatabase("master");
            Database targetDb = Database.GetDatabase(targetDatabase);
            Item item = sourceDb.GetItem(new ID(itemId));

            if (item != null)
            {
                PublishOptions publishOptions = new PublishOptions(sourceDb, targetDb, PublishMode.SingleItem, item.Language, DateTime.Now);
                Publisher publisher = new Publisher(publishOptions);
                publisher.Options.RootItem = item;
                publisher.Options.PublishRelatedItems = true; // Example Option
                publisher.Publish();
            }
        }
        else
        {
            // SPS Publishing Code (as shown previously)
        }
    }
}
In this example, the `UseInbuiltPublishing` setting in Sitecore’s configuration determines whether to use the inbuilt publishing pipeline or the SPS. You would need to define this setting in your Sitecore configuration file:
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:set="http://www.sitecore.net/xmlconfig/set/">
  <sitecore>
    <settings>
      <setting name="UseInbuiltPublishing" value="false" />
    </settings>
  </sitecore>
</configuration>

3. User Interface Adjustments (Optional)

If you want to provide a user-friendly way for content authors to switch between SPS and the inbuilt dialog, you can implement user interface (UI) adjustments. This might involve adding a custom button or a checkbox in the Sitecore Content Editor or Experience Editor.

  • Custom Command: Create a custom Sitecore command that toggles a configuration setting or a user profile property to indicate the preferred publishing method.
  • UI Element: Add a UI element (e.g., a checkbox) to the Content Editor or Experience Editor that triggers the custom command.
  • Event Handler: Implement an event handler that listens for the publishing event and redirects the operation based on the user’s preference.

4. Testing and Verification

After making the necessary configuration and code changes, it’s crucial to test and verify that the inbuilt Sitecore Publishing Dialog is accessible and functioning correctly. Follow these steps:

  • Clear Sitecore Cache: Clear the Sitecore cache to ensure that the configuration changes are applied.
  • Publish Items: Attempt to publish items using the Sitecore Content Editor or Experience Editor. Verify that the inbuilt publishing dialog appears instead of the SPS dashboard.
  • Check Logs: Review the Sitecore logs for any errors or warnings related to publishing. Ensure that there are no exceptions or issues indicating a problem with the inbuilt publishing pipeline.
  • Performance Testing: Conduct performance testing to ensure that the inbuilt publishing pipeline is functioning efficiently and not causing any performance bottlenecks.
  • User Acceptance Testing (UAT): Involve content authors and other stakeholders in the testing process to gather feedback and ensure that the changes meet their requirements.

Best Practices and Considerations

When accessing the inbuilt Sitecore Publishing Dialog when SPS is configured, consider the following best practices and considerations:

  • Configuration Management: Use patch files to manage configuration changes. This makes it easier to revert changes and maintain a clean configuration.
  • Conditional Logic: Implement conditional logic in your code to allow for flexibility in choosing the publishing method. This ensures that you can switch between SPS and the inbuilt pipeline as needed.
  • User Experience: Provide a user-friendly way for content authors to switch between publishing methods. This can improve their workflow and reduce confusion.
  • Performance Monitoring: Monitor the performance of both the SPS and the inbuilt publishing pipeline. This helps you identify any performance issues and optimize your publishing process.
  • Documentation: Document the changes you make to the configuration and code. This ensures that other developers and administrators can understand and maintain the system.

Conclusion

Accessing the inbuilt Sitecore Publishing Dialog when Sitecore Publishing Service is configured is a common requirement in many Sitecore projects. By following the steps outlined in this article, you can effectively bypass the SPS and use the inbuilt dialog for specific publishing operations. Whether it's for granular control, troubleshooting, or legacy workflow compatibility, understanding how to switch between publishing methods is essential for Sitecore developers and administrators. Remember to carefully manage your configurations, implement conditional logic in your code, and provide a seamless user experience for content authors. By adhering to best practices and thoroughly testing your changes, you can ensure a robust and flexible publishing process in your Sitecore environment. This will enable your team to efficiently manage content and deliver exceptional digital experiences across all channels. The key to a successful implementation lies in understanding the nuances of both SPS and the inbuilt publishing pipeline, and knowing when and how to leverage each for optimal results.