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?