예제 #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);
        }
예제 #2
0
        /// <summary>
        /// Handle publishing restrictions for the specified item.
        /// </summary>
        /// <param name="item">The item to check.</param>
        /// <param name="requireLatest">Whether to require that the item specified is the
        /// latest version of the item.</param>
        /// <param name="target">The publishing target to check.</param>
        /// <returns>True if the item has publishing restrictions.</returns>
        /// <exception cref="PublishingException"><c>PublishingException</c> - Any type of
        /// error.</exception>
        protected bool HandlePublishingRestrictions(
            Sitecore.Data.Items.Item item,
            bool requireLatest,
            PublishingTarget target)
        {
            Sitecore.Diagnostics.Assert.IsNotNull(item, "item");

            if (this.HandlePublishingRestrictions(item, requireLatest))
            {
                return(true);
            }

            if (item.HasPublishingRestrictions(true, requireLatest, target))
            {
                string message = this.Logger.Info(
                    "{0} has item publishing restrictions.",
                    item.Paths.FullPath);

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

                return(true);
            }

            return(false);
        }
예제 #3
0
        /// <summary>
        /// Return a list of publishing targets corresponding to the publishing target
        /// definition items provided.
        /// </summary>
        /// <param name="items">A list of publishing target definition items.</param>
        /// <returns>A list of publishing targets corresponding to the publishing target
        /// definition items provided.</returns>
        public static PublishingTarget[] GetPublishingTargets(
            Sitecore.Data.Items.Item[] items)
        {
            PublishingTarget[] targets = new PublishingTarget[items.Length];

            for (int i = 0; i < items.Length; i++)
            {
                targets[i] = new PublishingTarget(items[i]);
            }

            return(targets);
        }
예제 #4
0
        /// <summary>
        /// Add any unpublished ancestors to the publishing queue.
        /// </summary>
        /// <param name="item">The item to check.</param>
        /// <param name="target">The publishing target to check.</param>
        /// <param name="checkRevision">If True, add the item to the publishing queue if
        /// the revision differs from that in the publishing target.</param>
        /// <param name="processed">List of IDs already processed (for optimization).
        /// </param>
        /// <returns>
        /// True if any required ancestor could not be added to the publishing queue.
        /// </returns>
        protected bool AddRequiredAncestorsToQueue(
            Sitecore.Data.Items.Item item,
            PublishingTarget target,
            bool checkRevision,
            HashSet <Sitecore.Data.ID> processed)
        {
            Sitecore.Diagnostics.Assert.IsNotNull(item, "item");
            Sitecore.Diagnostics.Assert.IsNotNull(target, "target");
            Sitecore.Diagnostics.Assert.IsNotNull(processed, "processed");
            Sitecore.Data.Items.Item ancestor = item.Parent;

            while (ancestor.Axes.Level > 1 &&
                   !target.ContainsItem(ancestor, checkRevision))
            {
                if (!this.AddToQueue(ancestor, target, processed))
                {
                    return(false);
                }

                ancestor = ancestor.Parent;
            }

            return(true);
        }
예제 #5
0
        /// <summary>
        /// Add items referenced by the specified item to the publishihng queue as
        /// specified 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 a referenced item could not be added to the publishing queue
        /// and <see cref="RequireReferencedItems" /> is true.</returns>
        /// <exception cref="PublishingException"><c>PublishingException</c> - Any type of
        /// error.</exception>
        protected bool HandleReferences(
            Sitecore.Data.Items.Item item,
            PublishingTarget target)
        {
            this.Logger.Info("HandleReferences");

            if (this.AddReferencedItemsToQueue(item, target) ||
                !this.RequireReferencedItems)
            {
                return(false);
            }

            string message = this.Logger.Warn(
                "Unable to publish all items referenced by {0}",
                item.Paths.FullPath);

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

            this.Logger.Info("HandleReferences returns true");
            return(true);
        }
예제 #6
0
        /// <summary>
        /// Add the item to the publishing queue.
        /// </summary>
        /// <param name="item">The referenced item.</param>
        /// <param name="target">The publishing target.</param>
        /// <param name="processed">A list of items already processed (for optimization).
        /// </param>
        /// <returns>True if there was an error adding the item to the publishing queue.
        /// </returns>
        /// <exception cref="PublishingException"><c>PublishingException</c> - Any type of
        /// error.</exception>
        protected bool AddToQueue(
            Sitecore.Data.Items.Item item,
            PublishingTarget target,
            HashSet <Sitecore.Data.ID> processed)
        {
            Sitecore.Diagnostics.Assert.IsNotNull(item, "item");
            Sitecore.Diagnostics.Assert.IsNotNull(target, "target");
            Sitecore.Diagnostics.Assert.IsNotNull(processed, "processed");

            // TODO: ensure items other than root not added to procesed until here
            // TODO: check publishing targets including ancestors
            if (processed.Contains(item.ID))
            {
                return(true);
            }

            processed.Add(item.ID);

            if (this.HandlePublishingRestrictions(
                    item,
                    this.RequireLatestRevision,
                    target))
            {
                return(false);
            }

            // TODO: could be a validation/warning issue as well
            if (!target.IsRelevant(item))
            {
                string message = this.Logger.Info(
                    "{0} is not relevant to publishing target {1}",
                    item,
                    target.Database.Name);

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

                return(false);
            }

            if (target.ContainsItem(item, this.RequireReferencedItems))
            {
                return(true);
            }

            if (this.PublishReferencedAncestors &&
                !this.AddRequiredAncestorsToQueue(item, target, false, processed))
            {
                string message = this.Logger.Info(
                    "Unable to publish ancestors of {0}",
                    item);

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

                return(false);
            }

            target.AddToQueue(item);
            return(true);
        }