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