From 38ec97bbe34f2408a40ef9f70e35d4baf79f739d Mon Sep 17 00:00:00 2001 From: Stephan Date: Thu, 24 Jan 2019 15:22:20 +0100 Subject: [PATCH] Need to refactor IsPublished --- .../Models/PublishedContent/IPublishedContent.cs | 11 +++++++++-- .../PublishedContent/PublishedContentWrapped.cs | 1 - src/Umbraco.Web/Models/PublishedContentBase.cs | 1 + .../PublishedCache/NuCache/PublishedContent.cs | 5 +++-- .../XmlPublishedCache/XmlPublishedContent.cs | 4 ++-- 5 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/Umbraco.Core/Models/PublishedContent/IPublishedContent.cs b/src/Umbraco.Core/Models/PublishedContent/IPublishedContent.cs index e50fb2c396..f613f926e9 100644 --- a/src/Umbraco.Core/Models/PublishedContent/IPublishedContent.cs +++ b/src/Umbraco.Core/Models/PublishedContent/IPublishedContent.cs @@ -156,10 +156,17 @@ namespace Umbraco.Core.Models.PublishedContent /// /// Gets a value indicating whether the content is published. /// - /// + /// + /// A content is published when it has a published version. + /// When retrieving documents from cache in non-preview mode, IsPublished is always + /// true, as only published documents are returned. When retrieving in draft mode, IsPublished + /// can either be true (document has a published version) or false (document has no + /// published version). + /// It is therefore possible for both IsDraft and IsPublished to be true at the same + /// time, meaning that the content is the draft version, and a published version exists. + /// bool IsPublished(string culture = null); - #endregion #region Tree diff --git a/src/Umbraco.Core/Models/PublishedContent/PublishedContentWrapped.cs b/src/Umbraco.Core/Models/PublishedContent/PublishedContentWrapped.cs index 42ff16bae5..8bf8cec244 100644 --- a/src/Umbraco.Core/Models/PublishedContent/PublishedContentWrapped.cs +++ b/src/Umbraco.Core/Models/PublishedContent/PublishedContentWrapped.cs @@ -114,7 +114,6 @@ namespace Umbraco.Core.Models.PublishedContent /// public virtual bool IsPublished(string culture = null) => _content.IsPublished(culture); - #endregion #region Tree diff --git a/src/Umbraco.Web/Models/PublishedContentBase.cs b/src/Umbraco.Web/Models/PublishedContentBase.cs index 12acb6b0c8..45243b86e6 100644 --- a/src/Umbraco.Web/Models/PublishedContentBase.cs +++ b/src/Umbraco.Web/Models/PublishedContentBase.cs @@ -144,6 +144,7 @@ namespace Umbraco.Web.Models /// public abstract bool IsDraft(string culture = null); + /// public abstract bool IsPublished(string culture = null); #endregion diff --git a/src/Umbraco.Web/PublishedCache/NuCache/PublishedContent.cs b/src/Umbraco.Web/PublishedCache/NuCache/PublishedContent.cs index 69c672ab98..3f57bf3340 100644 --- a/src/Umbraco.Web/PublishedCache/NuCache/PublishedContent.cs +++ b/src/Umbraco.Web/PublishedCache/NuCache/PublishedContent.cs @@ -293,8 +293,11 @@ namespace Umbraco.Web.PublishedCache.NuCache return _contentData.CultureInfos.TryGetValue(culture, out var cvar) && cvar.IsDraft; } + /// public override bool IsPublished(string culture = null) { + // fixme I don't understand this - and it does probably not do what's expected + if (!ContentType.VariesByCulture()) { return _contentData.Published; @@ -302,9 +305,7 @@ namespace Umbraco.Web.PublishedCache.NuCache // handle context culture 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; diff --git a/src/Umbraco.Web/PublishedCache/XmlPublishedCache/XmlPublishedContent.cs b/src/Umbraco.Web/PublishedCache/XmlPublishedCache/XmlPublishedContent.cs index c3cf22559d..f601114ffd 100644 --- a/src/Umbraco.Web/PublishedCache/XmlPublishedCache/XmlPublishedContent.cs +++ b/src/Umbraco.Web/PublishedCache/XmlPublishedCache/XmlPublishedContent.cs @@ -232,7 +232,7 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache public override bool IsPublished(string culture = null) { EnsureNodeInitialized(); - return _isPublished; + return _isPublished; // bah } public override IEnumerable Properties @@ -309,7 +309,7 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache name = writerName = urlName = creatorName = docTypeAlias = path = null; createDate = updateDate = default(DateTime); isDraft = false; - isPublished = false; + isPublished = false; // fixme not implemented? contentType = null; properties = null;