1
votes

Using Sitecore 7.2:

Is there a way to change the Workflow Auto Publish to run a Smart publish rather than a Republish?

According to https://www.sitecore.net/learn/blogs/technical-blogs/reinnovations/posts/2014/03/auto-publish-workflow-action-updates.aspx there are 6 parameters that can be added (deep, related, targets, alllanguages, languages, itemlanguage), but I'm not finding any mention of changing the publish type.

EDIT: Since it's been suggested this top be closed because it's not programming, some additional details may be in order...

I had already viewed the decompiled Sitecore.Workflows.Simple.PublishAction, Sitecore.Kernel code (the default behavior of the Auto Publish) to find the parameters specified in the link above are the only parameters. So my understanding (unless I missed something) is a custom action is needed.

It seems odd to me that you can specify deep and related, but can't specify a "smart" publish, so my hope is that someone has already documented this so I don't need to reinvent the wheel.

2
I'm voting to close this question as off-topic because it is about using a web app rather than programmingPekka
This is on-topic as Sitecore implementations always require custom development in some capacity.Matthew Dresser
Short answer: No, not in the default simple workflow. Long answer: Yes, but you have to create a custom PublishAction to do it. I'll knock up an answer if you need.jammykam

2 Answers

0
votes

The PublishAction is intended to trigger only for the item in context (i.e. the item approved in workflow). In general, smart vs. republish does not have much difference at a single item level. This action triggers a different mode not normally chosen by a user: SingleItem (neither smart nor republish)

The action will attempt to publish the context item, and any related items if you specify related to be true (which I recommend). However, this will then impact performance with a full republish running.

If you specify 'deep', the action will also publish children. I do not recommend having this enabled as an approval on the Home node of your site could theoretically trigger a publish of every item in the site.

0
votes

For anyone looking for the same solution, this worked for me:

public class PublishAction
{
    public void Process(WorkflowPipelineArgs args)
    {
        Item dataItem = args.DataItem;
        Item innerItem = args.ProcessorItem.InnerItem;
        NameValueCollection parameters = WebUtil.ParseUrlParameters(innerItem["parameters"]);
        bool deep = this.GetDeep(parameters, innerItem);
        bool related = this.GetRelated(parameters, innerItem);
        bool smart = this.GetSmart(parameters, innerItem);
        Database[] targets = Enumerable.ToArray<Database>(this.GetTargets(parameters, innerItem, dataItem));
        Language[] languages = Enumerable.ToArray<Language>(this.GetLanguages(parameters, innerItem, dataItem));
        if (!Settings.Publishing.Enabled || !Enumerable.Any<Database>((IEnumerable<Database>)targets) || !Enumerable.Any<Language>((IEnumerable<Language>)languages))
            return;
        PublishManager.PublishItem(dataItem, targets, languages, deep, smart, related);

    }
    private bool GetDeep(NameValueCollection parameters, Item actionItem)
    {
        return this.GetStringValue("deep", parameters, actionItem) == "1";
    }
    private bool GetRelated(NameValueCollection parameters, Item actionItem)
    {
        return this.GetStringValue("related", parameters, actionItem) == "1";
    }
    private bool GetSmart(NameValueCollection parameters, Item actionItem)
    {
        return this.GetStringValue("smart", parameters, actionItem) == "1";
    }
    private IEnumerable<Database> GetTargets(NameValueCollection parameters, Item actionItem, Item dataItem)
    {
        using (new SecurityDisabler())
        {
            IEnumerable<string> targetNames = this.GetEnumerableValue("targets", parameters, actionItem);
            if (!Enumerable.Any<string>(targetNames))
            {
                Item obj = dataItem.Database.Items["/sitecore/system/publishing targets"];
                if (obj != null)
                    targetNames = Enumerable.Where<string>(Enumerable.Select<Item, string>((IEnumerable<Item>)obj.Children, (Func<Item, string>)(child => child["Target database"])), (Func<string, bool>)(dbName => !string.IsNullOrEmpty(dbName)));
            }
            foreach (string name in targetNames)
            {
                Database database = Factory.GetDatabase(name, false);
                if (database != null)
                    yield return database;
                else
                    Log.Warn("Unknown database in PublishAction: " + name, (object)this);
            }
        }
    }

    private IEnumerable<Language> GetLanguages(NameValueCollection parameters, Item actionItem, Item dataItem)
    {
        using (new SecurityDisabler())
        {
            IEnumerable<string> languageNames = Enumerable.Empty<string>();
            bool allLanguages = this.GetStringValue("alllanguages", parameters, dataItem) == "1";
            if (allLanguages)
            {
                Item obj = dataItem.Database.Items["/sitecore/system/languages"];
                if (obj != null)
                    languageNames = Enumerable.Select<Item, string>(Enumerable.Where<Item>((IEnumerable<Item>)obj.Children, (Func<Item, bool>)(child => child.TemplateID == TemplateIDs.Language)), (Func<Item, string>)(child => child.Name));
            }
            else
            {
                languageNames = this.GetEnumerableValue("languages", parameters, actionItem);
                string current = this.GetStringValue("itemlanguage", parameters, dataItem);
                if ((current == "1" || current == null) && !Enumerable.Contains<string>(languageNames, dataItem.Language.Name))
                    yield return dataItem.Language;
            }
            foreach (string name in languageNames)
            {
                Language language = (Language)null;
                if (Language.TryParse(name, out language))
                    yield return language;
                else
                    Log.Warn("Unknown language in PublishAction: " + name, (object)this);
            }
        }
    }

    private string GetStringValue(string name, NameValueCollection parameters, Item actionItem)
    {
        string str1 = actionItem[name];
        if (!string.IsNullOrEmpty(str1))
            return str1;
        string str2 = parameters[name];
        if (!string.IsNullOrEmpty(str2))
            return str2;
        else
            return (string)null;
    }
    private IEnumerable<string> GetEnumerableValue(string name, NameValueCollection parameters, Item actionItem)
    {
        string str1 = actionItem[name];
        if (!string.IsNullOrEmpty(str1))
        {
            return Enumerable.AsEnumerable<string>((IEnumerable<string>)str1.Split(new char[1] { '|' }, StringSplitOptions.RemoveEmptyEntries));
        }
        else
        {
            string str2 = parameters[name];
            if (string.IsNullOrEmpty(str2))
                return Enumerable.Empty<string>();
            return Enumerable.AsEnumerable<string>((IEnumerable<string>)str2.Split(new char[1] { ',' }, StringSplitOptions.RemoveEmptyEntries));
        }
    }

}