Ejemplo n.º 1
0
        /// <summary>
        /// Add the items referenced by the item to the publishing queue as dictated by
        /// <see cref="PublishReferencedItems" /> and <see cref="PublishReferencedMedia" />
        /// .
        /// </summary>
        /// <param name="item">The item containing the references.</param>
        /// <param name="target">The publishing target.</param>
        /// <returns>True if the appropriate </returns>
        /// <exception cref="PublishingException"><c>PublishingException</c> - Any type of
        /// error.</exception>
        protected bool AddReferencedItemsToQueue(
            Sitecore.Data.Items.Item item,
            PublishingTarget target)
        {
            this.Logger.Info("AddReferencedItemsToQueue");
            HashSet <Sitecore.Data.ID> processed =
                new HashSet <Sitecore.Data.ID> {
                item.ID
            };

            foreach (Sitecore.Links.ItemLink link in item.GetVersionLinks())
            {
                // If the target item has already been evaluated for queueing.
                if (processed.Contains(link.TargetItemID))
                {
                    this.Logger.Info("Processed contains " + link.TargetItemID);
                    continue;
                }

                Sitecore.Data.Items.Item referenced = link.GetTargetItem();

                if (referenced != null)
                {
                    referenced = referenced.Publishing.GetValidVersion(
                        DateTime.Now,
                        true);
                }

                if (referenced == null)
                {
                    this.HandleNullReference(item, referenced, link);
                    processed.Add(link.TargetItemID);
                    continue;
                }

                if (!((referenced.Paths.IsMediaItem && this.PublishReferencedMedia) ||
                      (this.PublishReferencedItems && !referenced.Paths.IsMediaItem)))
                {
                    processed.Add(link.TargetItemID);
                    continue;
                }

                if (!this.AddToQueue(referenced, target, processed))
                {
                    string message = this.Logger.Info(
                        "Unable to publish referenced item {0}.",
                        referenced);

                    if (this.ThrowExceptions)
                    {
                        throw new PublishingException(message);
                    }

                    return(false);
                }
            }

            this.Logger.Info("AddReferencedItemsToQueue returns true");
            return(true);
        }