0
votes

I have created workflow in my sitecore project and on final state ( Approval ) I just want auto publish to a particular database. So where should I do the changes to point to database.

Thanks

2

2 Answers

1
votes

In order to perform automatic publishing, your final state should contain a workflow action, that does the job for you. You may take a look on Sample Workflow (that comes by default with Sitecore) - Approved state. It contains child item Auto Publish, that has two fields.

Type string:

Sitecore.Workflows.Simple.PublishAction, Sitecore.Kernel

sets the class that in fact does publishing. You may inherit from that class and implement your own behavior, supply extra parameters etc. I would advise you to take dotPeek or Reflector and look-up this class implementation so that you may adjust your own code.

Parameters:

deep=0

..stands for publishing child items recursively.

Update: Lets take a look on decompiled class from Sample Workflow Auto Publish action:

public class PublishAction
{
    public void Process(WorkflowPipelineArgs args)
    {
        Item dataItem = args.DataItem;
        Item innerItem = args.ProcessorItem.InnerItem;
        Database[] targets = this.GetTargets(dataItem);
        PublishManager.PublishItem(dataItem, targets, new Language[1]
  {
    dataItem.Language
  }, (this.GetDeep(innerItem) ? 1 : 0) != 0, 0 != 0);
    }

    private bool GetDeep(Item actionItem)
    {
        return actionItem["deep"] == "1" || WebUtil.ParseUrlParameters(actionItem["parameters"])["deep"] == "1";
    }

    private Database[] GetTargets(Item item)
    {
        using (new SecurityDisabler())
        {
            Item obj = item.Database.Items["/sitecore/system/publishing targets"];
            if (obj != null)
            {
                ArrayList arrayList = new ArrayList();
                foreach (BaseItem baseItem in obj.Children)
                {
                    string name = baseItem["Target database"];
                    if (name.Length > 0)
                    {
                        Database database = Factory.GetDatabase(name, false);
                        if (database != null)
                            arrayList.Add((object)database);
                        else
                            Log.Warn("Unknown database in PublishAction: " + name, (object)this);
                    }
                }
                return arrayList.ToArray(typeof(Database)) as Database[];
            }
        }
        return new Database[0];
    }
}

GetTargets() method from above default example does publishing to all targets that are specified under /sitecore/system/publishing targets path. As I mentioned above, you may create your own class with your own implementation and reference that from workflow action definition item.

1
votes

You can look into Sample workflow's Auto publish action. But in general you can create a Workflow Action with type: Sitecore.Workflows.Simple.PublishAction, Sitecore.Kernel and set parameters as deep=1&related=1&targets=somedb,web&alllanguages=1