/// <summary>
        /// Extension method to Sitecore.Data.Items.Item to indicate whether an item  or a
        /// version of an item or any of its ancestors has publishing restrictions. Does
        /// not check publishing targets.
        /// </summary>
        /// <param name="me">The item to check.</param>
        /// <param name="checkAncestors">Whether to check ancestors of the item for
        /// publishing restrictions (does not check version publishing restrictions).
        /// </param>
        /// <param name="requireLatest">Whether to check if this version of the item has
        /// publishing restrictions.</param>
        /// <returns>True if the item or any of its ancestors has publishing restrictions.
        /// </returns>
        public static bool HasPublishingRestrictions(
            this Sitecore.Data.Items.Item me,
            bool checkAncestors,
            bool requireLatest)
        {
            Sitecore.Diagnostics.Assert.IsNotNull(me, "item");

            if (!me.Publishing.IsPublishable(DateTime.Now, checkAncestors))
            {
                return(true);
            }

            if (!requireLatest)
            {
                return(false);
            }

            if (!me.IsLatest())
            {
                return(true);
            }

            Sitecore.Data.Items.Item publishable =
                me.Publishing.GetValidVersion(DateTime.Now, true);

            if (publishable == null || !me.IsSameRevision(publishable))
            {
                return(true);
            }

            return(false);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Return true if this revision of the item is the latest.
        /// </summary>
        /// <param name="me">The item to check.</param>
        /// <returns>True if the revision of the item is the latest.</returns>
        public static bool IsLatest(this Sitecore.Data.Items.Item me)
        {
            Sitecore.Diagnostics.Assert.IsNotNull(me, "me");
            Sitecore.Data.Items.Item latest = me.Database.GetItem(
                me.ID,
                me.Language,
                Sitecore.Data.Version.Latest);

            if (latest == null)
            {
                return(false);
            }

            return(me.IsSameRevision(latest));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Returns the publishing targets that do not contain the specified item.
        /// </summary>
        /// <param name="targets">All publishing targets.</param>
        /// <param name="item">The item to check.</param>
        /// <param name="checkRevision">Whether to check the revision of the item.</param>
        /// <returns>A list of publishing targets that do not contain the specified item or
        /// revision.</returns>
        public static PublishingTarget[] GetTargetsWithoutItem(
            PublishingTarget[] targets,
            Sitecore.Data.Items.Item item,
            bool checkRevision)
        {
            List <PublishingTarget> without = new List <PublishingTarget>();

            foreach (PublishingTarget target in targets)
            {
                Sitecore.Data.Items.Item targetItem =
                    target.Database.GetItem(item.ID, item.Language);

                if (targetItem == null ||
                    (checkRevision && !item.IsSameRevision(targetItem)))
                {
                    without.Add(target);
                }
            }

            return(without.ToArray());
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Returns True if the publishing target contains the item.
        /// </summary>
        /// <param name="item">The item to evaluate.</param>
        /// <param name="checkRevision">Whether to check the revision identifier, or just
        /// the existence of the item.</param>
        /// <returns>True if the publishinng target contains the item.</returns>
        public bool ContainsItem(
            Sitecore.Data.Items.Item item,
            bool checkRevision)
        {
            Sitecore.Diagnostics.Assert.IsNotNull(item, "item");
            Sitecore.Data.Items.Item targetItem = this.Database.GetItem(
                item.ID,
                item.Language,
                Sitecore.Data.Version.Latest);

            if (targetItem == null)
            {
                return(false);
            }

            if (checkRevision && !item.IsSameRevision(targetItem))
            {
                return(false);
            }

            return(true);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Returns true if the database contains
        /// </summary>
        /// <param name="me">The item to check, usually in the master database.</param>
        /// <param name="database">The database to check, usually a publishing target
        /// </param>
        /// <param name="checkRevision">False to confirm item exists, True to confirm item
        /// exists and has same revision.</param>
        /// <returns>True if item exists and optionally contains the same revision.
        /// </returns>
        public static bool ExistsInDatabase(
            this Sitecore.Data.Items.Item me,
            Sitecore.Data.Database database,
            bool checkRevision)
        {
            Sitecore.Diagnostics.Assert.IsNotNull(me, "me");
            Sitecore.Diagnostics.Assert.IsNotNull(database, "database");
            Sitecore.Data.Items.Item targetItem = database.GetItem(
                me.ID,
                me.Language,
                Sitecore.Data.Version.Latest);

            if (targetItem == null)
            {
                return(false);
            }

            if (!checkRevision)
            {
                return(true);
            }

            return(me.IsSameRevision(targetItem));
        }