From 66959baabee4803e2dc4004a9d6ec8b3890ce030 Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Fri, 25 Jan 2019 12:56:53 +0100 Subject: [PATCH] Reimplemented IsPublished on PublishedContent --- .../NuCache/DataSource/CultureVariation.cs | 3 +++ .../NuCache/PublishedContent.cs | 14 ++++++++++--- .../NuCache/PublishedSnapshotService.cs | 21 +++++++++++++------ 3 files changed, 29 insertions(+), 9 deletions(-) diff --git a/src/Umbraco.Web/PublishedCache/NuCache/DataSource/CultureVariation.cs b/src/Umbraco.Web/PublishedCache/NuCache/DataSource/CultureVariation.cs index c6e603f5a9..27bae6bf39 100644 --- a/src/Umbraco.Web/PublishedCache/NuCache/DataSource/CultureVariation.cs +++ b/src/Umbraco.Web/PublishedCache/NuCache/DataSource/CultureVariation.cs @@ -16,5 +16,8 @@ namespace Umbraco.Web.PublishedCache.NuCache.DataSource [JsonProperty("isDraft")] public bool IsDraft { get; set; } + + [JsonProperty("isPublished")] + public bool IsPublished { get; set; } } } diff --git a/src/Umbraco.Web/PublishedCache/NuCache/PublishedContent.cs b/src/Umbraco.Web/PublishedCache/NuCache/PublishedContent.cs index 3f57bf3340..e145f89220 100644 --- a/src/Umbraco.Web/PublishedCache/NuCache/PublishedContent.cs +++ b/src/Umbraco.Web/PublishedCache/NuCache/PublishedContent.cs @@ -296,7 +296,10 @@ namespace Umbraco.Web.PublishedCache.NuCache /// public override bool IsPublished(string culture = null) { - // fixme I don't understand this - and it does probably not do what's expected + if (!IsDraft(culture)) + { + return true; + } if (!ContentType.VariesByCulture()) { @@ -307,8 +310,13 @@ namespace Umbraco.Web.PublishedCache.NuCache if (culture == null) culture = VariationContextAccessor?.VariationContext?.Culture ?? ""; - //If the current culture is not a draft, it must be the published version - return _contentData.CultureInfos.TryGetValue(culture, out var cvar) && !cvar.IsDraft; + if (_contentData.CultureInfos.TryGetValue(culture, out var variant)) + { + return variant.IsPublished; + } + + return false; + } #endregion diff --git a/src/Umbraco.Web/PublishedCache/NuCache/PublishedSnapshotService.cs b/src/Umbraco.Web/PublishedCache/NuCache/PublishedSnapshotService.cs index 8675aefd1a..ff0d330a3c 100755 --- a/src/Umbraco.Web/PublishedCache/NuCache/PublishedSnapshotService.cs +++ b/src/Umbraco.Web/PublishedCache/NuCache/PublishedSnapshotService.cs @@ -1202,16 +1202,25 @@ namespace Umbraco.Web.PublishedCache.NuCache // sanitize - names should be ok but ... never knows if (content.GetContentType().VariesByCulture()) { - var infos = content is IContent document - ? (published - ? document.PublishCultureInfos - : document.CultureInfos) - : content.CultureInfos; + + IReadOnlyDictionary infos = content.CultureInfos; + var publishedCultures = new HashSet(); + + if (content is IContent document) + { + if (published) + { + infos = document.PublishCultureInfos; + } + + publishedCultures = new HashSet(document.PublishedCultures); + } + foreach (var (culture, info) in infos) { var cultureIsDraft = !published && content is IContent d && d.IsCultureEdited(culture); - cultureData[culture] = new CultureVariation { Name = info.Name, Date = content.GetUpdateDate(culture) ?? DateTime.MinValue, IsDraft = cultureIsDraft }; + cultureData[culture] = new CultureVariation { Name = info.Name, Date = content.GetUpdateDate(culture) ?? DateTime.MinValue, IsDraft = cultureIsDraft, IsPublished = publishedCultures.Contains(culture)}; } }