Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2008/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Sitecore 6.5中发布相关媒体项目,而不使用工作流_Sitecore - Fatal编程技术网

在Sitecore 6.5中发布相关媒体项目,而不使用工作流

在Sitecore 6.5中发布相关媒体项目,而不使用工作流,sitecore,Sitecore,我们的客户希望在发布页面时自动发布相关媒体项。他们没有使用工作流,这会使事情变得更简单,所以我需要找到另一种方法。目前,我已经创建了一个自定义发布管道处理器(如图所示),在这里我为web数据库启用了历史记录存储,并从中获取更改项目的列表。当循环浏览更改的项目时,我正在检查任何相关的媒体项目并发布它们 这很好,但我只是想看看是否有任何陷阱需要注意,或者是否有更好的方法来做到这一点。有人有什么想法吗?输入风险区域: 如果编辑会话在发布前30天以上,则历史记录存储中缺少条目 查找相关的媒体项既涉及链接

我们的客户希望在发布页面时自动发布相关媒体项。他们没有使用工作流,这会使事情变得更简单,所以我需要找到另一种方法。目前,我已经创建了一个自定义发布管道处理器(如图所示),在这里我为web数据库启用了历史记录存储,并从中获取更改项目的列表。当循环浏览更改的项目时,我正在检查任何相关的媒体项目并发布它们

这很好,但我只是想看看是否有任何陷阱需要注意,或者是否有更好的方法来做到这一点。有人有什么想法吗?

输入风险区域:
  • 如果编辑会话在发布前30天以上,则历史记录存储中缺少条目
  • 查找相关的媒体项既涉及链接字段,也涉及富格文本字段,可能存在到媒体的直接链接,这些链接可以处理并转换为正确格式的链接 替代解决方案
    根据编辑器的Sitecore成熟度,另一种用户模式可能是从保存管道自动发布媒体项。对于某些用户来说,这更容易理解,因为发布模型仅限于处理页面可见性

    不使用工作流的最佳方法是替换
    PublishItem
    工作流中的
    AddItemReferences
    处理器。在那里,您可以添加将与原始项目一起发布的项目类型

    这是关于这件事的亚历克斯·希巴

    这是我的本地实现

    public class AddItemReferences : Sitecore.Publishing.Pipelines.PublishItem.AddItemReferences
    {
        private readonly static ILogger _logger = AppLogger.GetNamedLogger(typeof(AddItemReferences));
    
        protected override List<Item> GetItemReferences(PublishItemContext context)
        {
            Assert.ArgumentNotNull(context, "context");
            var list = new List<Item>();
            // calling base method which processes links from FileDropArea field
            list.AddRange(base.GetItemReferences(context));
            // adding our "own" related items
            list.AddRange(GetRelatedReferences(context));
            return list;
        }
        protected virtual List<Item> GetRelatedReferences(PublishItemContext context)
        {
            Assert.ArgumentNotNull(context, "context");
            var relatedReferenceList = new List<Item>();
            if (context.PublishOptions.Mode == PublishMode.SingleItem )
            {
                try
                {
                    var sourceItem = context.PublishHelper.GetSourceItem(context.ItemId);
                    if (sourceItem.Paths.IsContentItem)
                    {
                        var itemLinks = sourceItem.Links.GetValidLinks();
                        ItemLink[] referers = Globals.LinkDatabase.GetReferers(sourceItem);
    
                        relatedReferenceList.AddRange(GetMediaItems(itemLinks));
                        relatedReferenceList.AddRange(GetAliases(referers));
                    }
                }
                catch (Exception ex)
                {
                    var options = context.PublishOptions;
                    StringBuilder msg = new StringBuilder();
                    msg.AppendLine("Publishing options");
                    msg.AppendLine("Deep: " + options.Deep);
                    msg.AppendLine("From date: " + options.FromDate);
                    msg.AppendLine("Language: " + options.Language);
                    msg.AppendLine("Mode: " + options.Mode);
                    msg.AppendLine("PublishDate: " + options.PublishDate);
                    msg.AppendLine("Targets: " + string.Join(",",options.PublishingTargets.ToArray()));
                    msg.AppendLine("Republish all: " + options.RepublishAll);
                    msg.AppendLine("Root item: " + options.RootItem);
                    msg.AppendLine("Source database: " + options.SourceDatabase.Name);
                    _logger.LogError(msg.ToString(), ex);       
                }
            }
            return relatedReferenceList;
        }
    
        private static IEnumerable<Item> GetMediaItems(ItemLink[] itemLinks)
        {
            foreach (var link in itemLinks)
            {
                var item = link.GetTargetItem();
                if (item == null)
                    continue;
    
                if (item.Paths.IsMediaItem)
                {
                    yield return item;
                }
            }
        }
    
        private static IEnumerable<Item> GetAliases(ItemLink[] referrers)
        {
            foreach (var link in referrers)
            {
                var item = link.GetSourceItem();
                if (item != null && IsAlias(item))
                    yield return item;
            }
        }
    
        private static bool IsAlias(Item item)
        {
            return item.TemplateID.Guid == DataAccessSettings.Templates.AliasTemplateId;
        }
    }
    
    公共类AddItemReferences:Sitecore.Publishing.Pipelines.PublishItem.AddItemReferences
    {
    私有只读静态ILogger_logger=AppLogger.GetNamedLogger(typeof(AddItemReferences));
    受保护的覆盖列表GetItemReferences(PublishItemContext上下文)
    {
    Assert.ArgumentNotNull(上下文,“上下文”);
    var list=新列表();
    //调用处理来自FileDropArea字段的链接的基本方法
    list.AddRange(base.GetItemReferences(context));
    //添加我们自己的相关项目
    AddRange(GetRelatedReferences(context));
    退货清单;
    }
    受保护的虚拟列表GetRelatedReferences(PublishItemContext上下文)
    {
    Assert.ArgumentNotNull(上下文,“上下文”);
    var relatedReferenceList=新列表();
    if(context.PublishOptions.Mode==PublishMode.SingleItem)
    {
    尝试
    {
    var sourceItem=context.PublishHelper.GetSourceItem(context.ItemId);
    if(sourceItem.path.IsContentItem)
    {
    var itemLinks=sourceItem.Links.GetValidLinks();
    ItemLink[]referers=Globals.LinkDatabase.GetReferers(sourceItem);
    AddRange(GetMediaItems(itemLinks));
    AddRange(getAlias(referers));
    }
    }
    捕获(例外情况除外)
    {
    var options=context.PublishOptions;
    StringBuilder msg=新的StringBuilder();
    msg.AppendLine(“发布选项”);
    msg.AppendLine(“Deep:+options.Deep”);
    msg.AppendLine(“起始日期:+options.FromDate”);
    msg.AppendLine(“语言:+options.Language”);
    msg.AppendLine(“模式:+options.Mode”);
    msg.AppendLine(“PublishDate:+options.PublishDate”);
    AppendLine(“Targets:+string.Join(,”,options.PublishingTargets.ToArray());
    msg.AppendLine(“全部重新发布:+options.repubish”);
    msg.AppendLine(“根项目:+options.RootItem”);
    msg.AppendLine(“源数据库:”+options.SourceDatabase.Name);
    _logger.LogError(msg.ToString(),ex);
    }
    }
    返回关系参照者;
    }
    私有静态IEnumerable GetMediaItems(ItemLink[]itemLinks)
    {
    foreach(itemLinks中的var链接)
    {
    var item=link.GetTargetItem();
    如果(项==null)
    继续;
    if(item.path.IsMediaItem)
    {
    收益回报项目;
    }
    }
    }
    私有静态IEnumerable GetAlias(ItemLink[]引用器)
    {
    foreach(引用程序中的var链接)
    {
    var item=link.GetSourceItem();
    如果(项目!=null&&IsAlias(项目))
    收益回报项目;
    }
    }
    私人静态bool IsAlias(项目)
    {
    return item.TemplateID.Guid==DataAccessSettings.Templates.AliasTemplateId;
    }
    }
    
    很抱歉,我还没有回答,我已经被转移到另一个项目,所以我将在下周查看。不用担心。只要有可能:)