Ejemplo n.º 1
0
    private void StoreOldRoute(IContent entity, OldRoutesDictionary oldRoutes)
    {
        if (!_publishedSnapshotAccessor.TryGetPublishedSnapshot(out IPublishedSnapshot? publishedSnapshot))
        {
            return;
        }

        IPublishedContentCache?contentCache  = publishedSnapshot?.Content;
        IPublishedContent?     entityContent = contentCache?.GetById(entity.Id);

        if (entityContent is null)
        {
            return;
        }

        // get the default affected cultures by going up the tree until we find the first culture variant entity (default to no cultures)
        var defaultCultures = entityContent.AncestorsOrSelf().FirstOrDefault(a => a.Cultures.Any())?.Cultures.Keys
                              .ToArray()
                              ?? Array.Empty <string>();

        foreach (IPublishedContent publishedContent in entityContent.DescendantsOrSelf(_variationContextAccessor))
        {
            // if this entity defines specific cultures, use those instead of the default ones
            IEnumerable <string> cultures =
                publishedContent.Cultures.Any() ? publishedContent.Cultures.Keys : defaultCultures;

            foreach (var culture in cultures)
            {
                var route = contentCache?.GetRouteById(publishedContent.Id, culture);
                if (!IsNotRoute(route))
                {
                    oldRoutes[new ContentIdAndCulture(publishedContent.Id, culture)] = new ContentKeyAndOldRoute(publishedContent.Key, route !);
                }
                else if (string.IsNullOrEmpty(culture))
                {
                    // Retry using all languages, if this is invariant but has a variant ancestor
                    var languages = _localizationService.GetAllLanguages();
                    foreach (var language in languages)
                    {
                        route = contentCache?.GetRouteById(publishedContent.Id, language.IsoCode);
                        if (!IsNotRoute(route))
                        {
                            oldRoutes[new ContentIdAndCulture(publishedContent.Id, language.IsoCode)] =
                                new ContentKeyAndOldRoute(publishedContent.Key, route !);
                        }
                    }
                }
            }
        }
    }
Ejemplo n.º 2
0
        private void StoreOldRoute(IContent entity, OldRoutesDictionary oldRoutes)
        {
            if (!_publishedSnapshotAccessor.TryGetPublishedSnapshot(out var publishedSnapshot))
            {
                return;
            }

            IPublishedContentCache?contentCache  = publishedSnapshot?.Content;
            IPublishedContent?     entityContent = contentCache?.GetById(entity.Id);

            if (entityContent is null)
            {
                return;
            }

            // get the default affected cultures by going up the tree until we find the first culture variant entity (default to no cultures)
            var defaultCultures = entityContent.AncestorsOrSelf()?.FirstOrDefault(a => a.Cultures.Any())?.Cultures.Keys.ToArray()
                                  ?? Array.Empty <string>();

            foreach (IPublishedContent publishedContent in entityContent.DescendantsOrSelf(_variationContextAccessor))
            {
                // if this entity defines specific cultures, use those instead of the default ones
                IEnumerable <string> cultures = publishedContent.Cultures.Any() ? publishedContent.Cultures.Keys : defaultCultures;

                foreach (var culture in cultures)
                {
                    var route = contentCache?.GetRouteById(publishedContent.Id, culture);
                    if (IsNotRoute(route))
                    {
                        continue;
                    }

                    oldRoutes[new ContentIdAndCulture(publishedContent.Id, culture)] = new ContentKeyAndOldRoute(publishedContent.Key, route !);
                }
            }
        }