Sitecore工作流程自动“智能”发布

时间:2015-03-09 19:32:18

标签: sitecore sitecore7 sitecore7.2

使用Sitecore 7.2:

有没有办法更改工作流程自动发布以运行Smart publish而不是Republish

根据https://www.sitecore.net/learn/blogs/technical-blogs/reinnovations/posts/2014/03/auto-publish-workflow-action-updates.aspx,可以添加6个参数(深层,相关,目标,所有语言,语言,项目语言),但我没有发现任何改变发布类型的提及。

编辑:由于建议将此顶部关闭,因为它没有编程,因此可能会有一些额外的细节......

我已经查看过反编译的Sitecore.Workflows.Simple.PublishAction, Sitecore.Kernel代码(自动发布的默认行为),以查找上面链接中指定的参数是唯一的参数。所以我的理解(除非我遗漏了一些东西)是需要自定义动作。

对我而言,您可以指定深度和相关内容,但无法指定" smart"发表,所以我希望有人已经记录了这一点,所以我不需要重新发明轮子。

2 个答案:

答案 0 :(得分:0)

PublishAction仅用于触发上下文中的项目(即工作流程中批准的项目)。通常,智能与重新发布在单个项目级别上没有太大差异。此操作会触发用户通常不会选择的其他模式:SingleItem(既不智能也不重新发布)

如果您指定related为true(我推荐),操作将尝试发布上下文项和任何相关项。但是,这将影响性能并完全重新发布。

如果您指定' deep',该操作也会发布子项。我不建议启用此功能,因为您网站的主页节点上的批准理论上可以触发网站中每个项目的发布。

答案 1 :(得分:0)

对于寻找相同解决方案的人来说,这对我有用:

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));
        }
    }

}