I am working on a project where we are using DEF(Data Exchange Framework) to import data from XML feed. The import works perfectly, I need to publish the items that were created or updated. Below processor was written based on UpdateSitecoreItemStepProcessor.
It works well and publishes the items in the Pipelinecontext but the Pipeline batch job does not stop(button stays disabled) even after the items are published(checking the sitecore logs). When I switch to other content item in the content tree the Pipeline batch stops immediately. The publish works, I can see the items in the web database, its just the Pipeline Batch button stays disabled even after pipeline step has completed. Any ideas?
namespace Integration.DEF.Processors.PipelineSteps
{
[RequiredPipelineStepPlugins(new Type[] {typeof(EndpointSettings)})]
class PublishSitecoreItemStepProcessor : BasePipelineStepProcessor
{
public override void Process(PipelineStep pipelineStep, PipelineContext pipelineContext)
{
try
{
if (pipelineStep == null)
throw new ArgumentNullException(nameof(pipelineStep));
if (pipelineContext == null)
throw new ArgumentNullException(nameof(pipelineContext));
if (!CanProcess(pipelineStep, pipelineContext))
{
return;
}
else
{
var objectAsItemModels =
GetTargetObjectAsItemModels(pipelineStep, pipelineContext);
if (objectAsItemModels == null)
return;
var id = Guid.Empty;
foreach (var itemModel in objectAsItemModels)
{
FixItemModel(itemModel);
if (id == Guid.Empty)
id = itemModel.GetItemId();
PublishItem(pipelineStep, pipelineContext, id);
}
return;
}
}
catch (Exception ex)
{
var log = new ExceptionLog();
var entry = new ExceptionDetail { Component = "DEF Import" };
entry.SetExceptionDetail(ex);
log.LogException(entry);
}
}
protected virtual void FixItemModel(ItemModel itemModel)
{
if (itemModel == null)
return;
foreach (var index in itemModel.Keys.ToArray<string>())
{
var obj = itemModel[index];
if (obj != null)
itemModel[index] = (object) obj.ToString();
}
}
protected virtual IEnumerable<ItemModel> GetTargetObjectAsItemModels(PipelineStep pipelineStep,
PipelineContext pipelineContext)
{
if (!pipelineContext.HasSynchronizationSettings())
return (IEnumerable<ItemModel>) null;
var synchronizationSettings = pipelineContext.GetSynchronizationSettings();
if (synchronizationSettings == null)
return (IEnumerable<ItemModel>) null;
if (synchronizationSettings.Target == null)
return (IEnumerable<ItemModel>) null;
var itemModelList = new List<ItemModel>();
var target1 = synchronizationSettings.Target as ItemModel;
try
{
if (target1 != null)
{
itemModelList.Add(target1);
}
else
{
var target2 =
synchronizationSettings.Target as IDictionary<string, ItemModel>;
if (target2 != null)
{
foreach (var key in (IEnumerable<string>) target2.Keys)
itemModelList.Add(target2[key]);
}
}
if (itemModelList.Count == 0)
pipelineContext.Logger.Error(
"The target object is not compatible with the pipeline step processor.");
}
catch (Exception ex)
{
var log = new ExceptionLog();
var entry = new ExceptionDetail {Component = "DEF Import"};
entry.SetExceptionDetail(ex);
log.LogException(entry);
}
return (IEnumerable<ItemModel>) itemModelList;
}
private void PublishItem(PipelineStep pipelineStep, PipelineContext pipelineContext, Guid id)
{
try
{
var ItemId = ID.Parse((object)id);
Database masterdb = Database.GetDatabase(Util.dbcontext.master.ToString());
Database webdb = Database.GetDatabase(Util.dbcontext.web.ToString());
var item = masterdb.GetItem(ItemId);
if (item != null)
{
var publishOptions =
new PublishOptions(item.Database,
webdb,
PublishMode.SingleItem,
item.Language,
DateTime.Now);
var publisher = new Publisher(publishOptions);
publisher.Options.RootItem = item;
publisher.Options.Deep = true;
publisher.Publish();
pipelineContext.Logger.Debug("Item was published. (id: {0})", (object)id);
}
}
catch (Exception ex)
{
var log = new ExceptionLog();
var entry = new ExceptionDetail { Component = "PublishSitecoreItemStepProcessor" };
entry.SetExceptionDetail(ex);
log.LogException(entry);
}
}
}
}
UPDATED: