7

In a Sitecore 9.0.2 instance we have version 3.1.1 of the Sitecore Publishing Service setup.

When publishing items via an administrator account, or a custom workflow, the publishing jobs show up in the publishing dashboard as expected.

We have a scheduled task within Sitecore (defined in the config at /configuration/sitecore/scheduling/agent) that updates and publishes items, using the below code.

using (new Sitecore.SecurityModel.SecurityDisabler())
{
    try
    {
        var directoryItem = m_MasterDB.Items["/sitecore/content/home/directory"];

        if (directoryItem == null)
        {
            throw new NullReferenceException("The directory item does not exist in Sitecore.");
        }

        // Gets all publishing targets, using Sitecore definitions.
        var publishingTargets = PublishManager.GetPublishingTargets(directoryItem.Database);
        foreach (var publishingTarget in publishingTargets)
        {
            var targetDatabaseName = publishingTarget["Target database"];
            if (string.IsNullOrWhiteSpace(targetDatabaseName))
            {
                continue;
            }

            var targetDatabase = Sitecore.Configuration.Factory.GetDatabase(targetDatabaseName);
            if (targetDatabase == null)
            {
                continue;
            }

            var publishOptions = new PublishOptions(
                directoryItem.Database,
                targetDatabase,
                PublishMode.Smart,
                directoryItem.Language,
                DateTime.Now)
            {
                // Publish sub-items.
                Deep = true
            };

            // Perform the actual publish
            var publisher = new Publisher(publishOptions);
            publisher.Options.RootItem = directoryItem;
            publisher.PublishAsync();
        }
    }
    catch (Exception ex)
    {
        Sitecore.Diagnostics.Log.Error(ex.Message, ex, this);
    }
}

This code publishes as expected, and displays in the default Sitecore logs when it's triggered, but doesn't display in the publishing dashboard.

How would we go about getting programmatic publishes to display in the standalone publishing service's dashboard?

2 Answers 2

3

Sitecore.Publishing.PublishManager is recommended to use with SPS instead of Publisher. It will show also all publishing tasks in the Publishing Dashboard of SPS.

0

This is the code I use to do an incremental site publish for old school publishing as well as publishing service. Running publishing as below will add an entry to the publishing dashboard.

var publishAgent = new PublishAgent(SourceDb, targetDb, mode.ToString(), Languages);
publishAgent.Run();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.