Example #1
0
        // Check if there are any values configured for this item in "Language Fallback Report.FieldToCheckForReporting", a Sitecore Setting in System/Settings
        // contains a comma delimited string of all the Fields that needs to be check to see if any of the field has it's own value.
        // and if any of those fields has its own value, then language item is not falling back...
        // this method will take in the language version of the item we are checking
        // and will return out the language it is ultimately falling back to, if applicable
        private bool CheckIfFallingBack(Item thisLanguageVersion, out Language languageFallingBackTo)
        {
            bool contentIsFallingBack = true;

            languageFallingBackTo = null;
            if (thisLanguageVersion != null && thisLanguageVersion.Language != null)
            {
                // default the languageFallingBackTo to this versions language
                languageFallingBackTo = thisLanguageVersion.Language;
                // get the fields to check, splitting the values on the comma
                var fallbackFieldsList = GetFieldsToCheck().Split(',');
                // loop through each field and check if the current item language version has a value for the field
                // if ANY do, then the content is not considered falling back
                // NOTE, of course this means some fields could be falling back and others not,
                // but the point of this report is to get an idea of where we have set content explicitly and what items haven't been translated yet
                // so we are assuming if any of the important specified fields do have explicit content set, then it is no longer falling back.
                foreach (var field in fallbackFieldsList)
                {
                    if (thisLanguageVersion.Fields[field] != null)
                    {
                        var hasContentInField = thisLanguageVersion.Fields[field].HasValue;
                        if (hasContentInField)
                        {
                            contentIsFallingBack = false;
                            break;
                        }
                    }
                }

                // if the content is falling back (fields are all null), check if the language has fallback set
                // if fallback is not assigned, then clearly it can't be falling back, even if no values have been set yet for the fields
                // if it does, then get what language it is set to fall back to and call this method recursively for the item in that language
                // we are going to keep going back until we find content, and that will be the language we end up returning,
                // so we know ultimately what language is being displayed
                if (contentIsFallingBack)
                {
                    var fallbackLanguage = LanguageFallbackManager.GetFallbackLanguage(thisLanguageVersion.Language, CurrentDatabase);
                    if (fallbackLanguage != null)
                    {
                        var fallbackLanguageVersion = thisLanguageVersion.Versions.GetLatestVersion(fallbackLanguage);
                        CheckIfFallingBack(fallbackLanguageVersion, out languageFallingBackTo);
                    }
                    else
                    {
                        contentIsFallingBack = false;
                    }
                }
            }
            return(contentIsFallingBack);
        }
Example #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);
        }
Example #3
0
        private void UpdateLanguageFallbackDependentItems(IProviderUpdateContext context, SitecoreIndexableItem versionIndexable, IndexEntryOperationContext operationContext)
        {
            if (operationContext == null || operationContext.NeedUpdateAllLanguages)
            {
                return;
            }
            var  item          = versionIndexable.Item;
            bool?currentValue1 = Switcher <bool?, LanguageFallbackFieldSwitcher> .CurrentValue;

            if ((!currentValue1.GetValueOrDefault() ? 1 : (!currentValue1.HasValue ? 1 : 0)) != 0)
            {
                bool?currentValue2 = Switcher <bool?, LanguageFallbackItemSwitcher> .CurrentValue;
                if ((!currentValue2.GetValueOrDefault() ? 1 : (!currentValue2.HasValue ? 1 : 0)) != 0 || StandardValuesManager.IsStandardValuesHolder(item) && item.Fields[FieldIDs.EnableItemFallback].GetValue(false) != "1")
                {
                    return;
                }
                using (new LanguageFallbackItemSwitcher(new bool?(false)))
                {
                    if (item.Fields[FieldIDs.EnableItemFallback].GetValue(true, true, false) != "1")
                    {
                        return;
                    }
                }
            }
            if (!item.Versions.IsLatestVersion())
            {
                return;
            }
            foreach (var indexable in Enumerable.Select(Enumerable.Where <Item>(Enumerable.SelectMany(LanguageFallbackManager.GetDependentLanguages(item.Language, item.Database, item.ID), language =>
            {
                var item2 = item.Database.GetItem(item.ID, language);
                if (item2 == null)
                {
                    return(new Item[0]);
                }
                return(item2.Versions.GetVersions());
            }), item1 => !IsExcludedFromIndex(item1, false)), item1 => PrepareIndexableVersion(item1, context)))
            {
                Operations.Update(indexable, context, context.Index.Configuration);
            }
        }