private static Url BuildUrl(List <Link> links, SitemapItem sitemapItem, bool languageFallbackEnabled)
        {
            var matchedItem = links.FirstOrDefault(link => link.Item == sitemapItem.Item);

            if (matchedItem == null)
            {
                Logger.Warn(
                    $"Unable to retrieve item from alternate links: {sitemapItem.Item.Paths.FullPath}, language: {sitemapItem.Item.Language.Name}");
                return(null);
            }

            var loc = matchedItem.Href;

            var sitemapGetModifiedDateArgs = new SitemapGetModifiedDateArgs(sitemapItem.Item, DateTime.MinValue, languageFallbackEnabled);

            CorePipeline.Run("sitemap.GetModifiedDate", sitemapGetModifiedDateArgs);

            var lastmod = sitemapGetModifiedDateArgs.LastModified;

            if (lastmod == DateTime.MinValue)
            {
                Logger.Warn(
                    $"No modified date found for item: {sitemapItem.Item.Paths.FullPath}, language: {sitemapItem.Item.Language.Name}");
                return(null);
            }

            var url = new Url
            {
                Loc     = loc,
                Lastmod = lastmod.ToString("yyyy-MM-dd"),
                Link    = links
            };

            return(url);
        }
Exemplo n.º 2
0
        public void Process(SitemapGetModifiedDateArgs args)
        {
            Assert.ArgumentNotNull(args, nameof(args));

            if (args.Item.Versions.Count > 0)
            {
                using (new ContextItemSwitcher(args.Item))
                    using (new SiteContextSwitcher(Factory.GetSite("shell")))
                    {
                        var defaultDevice = args.Item.Database.Resources.Devices.GetAll()
                                            .First(d => d.Name.ToLower() == "default");
                        var dependentItems =
                            ItemUtility.GetItemsFromLayoutDefinedDatasources(args.Item, defaultDevice, args.Item.Language);
                        if (!dependentItems.Any())
                        {
                            args.LastModified = args.Item.Statistics.Updated;
                            return;
                        }

                        var dependentUpdatedDate = dependentItems.Max(x => x.Statistics.Updated);
                        args.LastModified = args.Item.Statistics.Updated.CompareTo(dependentUpdatedDate) > 0
                        ? args.Item.Statistics.Updated
                        : dependentUpdatedDate;
                        return;
                    }
            }

            if (!args.LanguageFallbackEnabled)
            {
                args.LastModified = DateTime.MinValue;
                return;
            }

            var fallbackLanguage = LanguageFallbackManager.GetFallbackLanguage(args.Item.Language, args.Item.Database);

            if (fallbackLanguage == null)
            {
                args.LastModified = DateTime.MinValue;
                return;
            }

            args.Item = args.Item.Database.GetItem(args.Item.ID, fallbackLanguage);
            Process(args);
        }