protected virtual void AddItemsToPublishingQueue(Item item1, ref List <Item> items, bool sharedOnly, bool subitems, bool recurse, Dictionary <ID, bool> deepRelatedTemplates)
        {
            items.AddRange(PublishQueue.GetParents(item1));
            items.Add(item1);
            if (subitems)
            {
                items.AddRange(item1.Children);
            }

            if (deepRelatedTemplates?.ContainsKey(item1.TemplateID) == true && recurse)
            {
                var relatedItems = GetReferences(item1, sharedOnly, deepRelatedTemplates[item1.TemplateID], recurse: false).ToArray();
                items.AddRange(relatedItems);
            }

            var relatedImages = item1.Links.GetValidLinks().Where(link => link.TargetPath.StartsWith(Constants.MediaLibraryPath))
                                .Select(link => link.GetTargetItem()).ToArray();

            if (relatedImages.Any())
            {
                var imageParents = relatedImages.SelectMany(PublishQueue.GetParents);
                items.AddRange(imageParents);
                items.AddRange(relatedImages);
            }
        }
Beispiel #2
0
        private IEnumerable <Item> GetReferences(Item item, bool sharedOnly, HashSet <ID> processedItems)
        {
            Assert.ArgumentNotNull(item, nameof(item));
            processedItems.Add(item.ID);
            var source = new List <Item>();
            var array  = item.Links.GetValidLinks().Where(link =>
                                                          item.Database.Name.Equals(link.TargetDatabaseName, StringComparison.OrdinalIgnoreCase)).ToArray();

            if (sharedOnly)
            {
                array = array.Where(link =>
                {
                    var sourceItem = link.GetSourceItem();
                    if (sourceItem == null)
                    {
                        return(false);
                    }
                    if (!ID.IsNullOrEmpty(link.SourceFieldID))
                    {
                        return(sourceItem.Fields[link.SourceFieldID].Shared);
                    }
                    return(true);
                }).ToArray();
            }
            foreach (var obj in array.Select(link => link.GetTargetItem()).Where(relatedItem => relatedItem != null)
                     .ToList())
            {
                if (DeepScan && !processedItems.Contains(obj.ID))
                {
                    source.AddRange(GetReferences(obj, sharedOnly, processedItems));
                }
                source.AddRange(PublishQueue.GetParents(obj));
                source.Add(obj);
                source.AddRange(GetAdvancedImageFieldsLinkedMediaItems(obj));
                source.AddRange(GetAdvancedImageGalleryFieldsLinkedMediaItems(obj));
            }

            return(source.Distinct(new ItemIdComparer()));
        }
Beispiel #3
0
        /// <summary>
        /// Gets the referenced items.
        /// </summary>
        /// <param name="item">The item.</param>
        /// <returns></returns>
        private IEnumerable <Item> GetReferences(Item item)
        {
            Assert.ArgumentNotNull(item, "item");
            List <Item> items = new List <Item>();

            ItemLink[] validLinks = item.Links.GetValidLinks();
            validLinks = (
                from link in validLinks
                where item.Database.Name.Equals(link.TargetDatabaseName, StringComparison.OrdinalIgnoreCase)
                select link).ToArray <ItemLink>();

            List <Item> list = (
                from link in (IEnumerable <ItemLink>) validLinks
                select link.GetTargetItem() into relatedItem
                where relatedItem != null
                select relatedItem).ToList <Item>();

            foreach (Item item1 in list)
            {
                items.AddRange(PublishQueue.GetParents(item1));
                items.Add(item1);
            }
            return(items.Distinct(new ItemIdComparer()));
        }