【问题标题】:How to provide email notifications/workflows for clones如何为克隆提供电子邮件通知/工作流程
【发布时间】:2011-03-31 10:38:48
【问题描述】:

我们想建立一个系统,当克隆他们的克隆的项目更新时,克隆管理员会收到电子邮件通知。将从该项目创建多个克隆,理想情况下,我们希望按语言过滤通知(因此英语克隆的管理员在法语版本更新时不会收到通知)。

有没有一种简单的方法可以在工作流中实现这些?如果是这样,我什至应该尝试将工作流操作挂钩到哪个?

我是否需要扩展或覆盖管道才能做到这一点?

交叉发布到 SDN http://sdn.sitecore.net/forum/ShowPost.aspx?PostID=34533#34533

编辑:更多信息:

如果克隆没有覆盖原始项目的字段,则在编辑原始项目字段时客户端不会收到通知。更改被直接复制 - 至少在主数据库中。但是 - 克隆仍然需要发布到 Web 数据库才能使此更改在线生效。所以我有点卡住了 - 我的用户需要执行一个操作(发布克隆)但不知道......

我真的很想能够以某种方式连接到通知事件。

【问题讨论】:

  • 很好的问题,詹姆斯!我想可以通过将您的问题作为章节来增强有关克隆的文档! :)
  • 谢谢,我当然希望如此!工作流程参考被标记为 6.0 - 6.4,但根本没有提到克隆!而且我还在为如何处理克隆部分中的内部链接而摸不着头脑......

标签: sitecore sitecore6


【解决方案1】:

回答我自己的问题 此处的代码由该线程中 SDN 上的各种海报提供: http://sdn.sitecore.net/forum//ShowPost.aspx?PostID=34012

如果为该线程做出贡献的任何人想要发布答案,那么我很乐意在应得的地方给予赞扬和代表。

首先: John West 指出有一些有趣的私有方法:

private static IEnumerable<Item> GetClonesOfVersion(Item source)
{
    Assert.ArgumentNotNull(source, "source");
    return (from clone in GetAllClones(source)
        where clone.SourceUri == source.Uri
        select clone);
}

private static IEnumerable<Item> GetAllClones(Item source)
{
    Assert.ArgumentNotNull(source, "source");
    return (from link in Globals.LinkDatabase.GetReferrers(source)
        select link.GetSourceItem() into clone
        where ((clone != null) && (clone.Source != null)) && (clone.Source.ID == source.ID)
        select clone);
}

有一张支持票要求将这些公开,否则只需将它们复制到您的项目中。

这需要与自定义工作流操作相结合,该操作应被编译并添加到源项目的工作流中。

下面这个由 Derek Roberti/Lauren Hightower 提供,用于强制接受克隆中的通知。 要提供电子邮件通知,我们需要颠倒逻辑 - 如果克隆有通知,我们不想执行操作,而是要确保在克隆没有通知时执行操作 - 即直接从源项继承已编辑的值。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Sitecore.Data;
using Sitecore.Data.Items;
using Sitecore.Data.Clones;
using Sitecore.Diagnostics;
using Sitecore.SecurityModel;
using Sitecore;
using Sitecore.Links;

namespace WorkFlowCustom
{
public class ForceCloneAccept
{
public void Process(Sitecore.Workflows.Simple.WorkflowPipelineArgs args)
{
Item workFlowItem = args.DataItem;
List itemList = GetItemClones(workFlowItem, true);

foreach (Item cloneItem in itemList)
{
List list = new List(workFlowItem.Database.NotificationProvider.GetNotifications(cloneItem));
foreach (Notification n in list)
{
if ((n != null) && (workFlowItem != null))
{
n.Accept(cloneItem);
}
}
}
}

protected virtual List GetItemClones(Item item, bool processChildren)
{
Assert.ArgumentNotNull(item, "item");
List list = new List();

using (new SecurityDisabler())
{
foreach (ItemLink link in Globals.LinkDatabase.GetReferrers(item))

{
if (!(link.SourceFieldID != FieldIDs.Source))
{
Item sourceItem = link.GetSourceItem();
if (sourceItem != null)
{
list.Add(sourceItem);
}
}
}
}
if (processChildren)
{
foreach (Item item4 in item.Children)
{
list.AddRange(this.GetItemClones(item4, true));
}

}
return list;
}

}
} 

这里有一些关于自定义工作流程和调用操作的一般性阅读: http://sdn.sitecore.net/FAQ/API/Cause%20the%20workflow%20to%20invoke%20an%20action.aspx

感谢所有提供的意见!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-04
    • 1970-01-01
    • 2021-10-11
    • 1970-01-01
    • 1970-01-01
    • 2016-11-09
    相关资源
    最近更新 更多