4

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:

pipelines

pipelines

| improve this question | | | | |
  • Could you provide structure of items, which you synced? – Andrei Paliakou Nov 30 '17 at 8:55
  • @AndreiPaliakou, i've added the mapping set above. They have been setup as item buckets under /sitecore/content/home/* and sitecore/content/site settings. Please let me know if that answers your question? – user2672 Nov 30 '17 at 9:56
4

Case

  1. Click a button "Run Pipeline Batch".
  2. The command is triggered to run Pipeline Batch and disable the button.
  3. Pipeline Batch has been completed (in your case publishing)
  4. The "Run Pipeline Batch" button is still disabled.

Why it happens?

  1. "Run Pipeline Batch" command overrides method " ShouldEnableButton".
  2. This method checks whether job finished or not.
  3. Sitecore re-render/trigger this method only if to switch to other content items or the same.
  4. It means even if Pipeline Batch has been completed the button will be disabled until Sitecore trigger the command, in our case switch to some item.
| improve this answer | | | | |
  • Thank you, that makes sense. Is there a way to programmatically trigger this method? – user2672 Nov 30 '17 at 14:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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