Need to refactor IsPublished

This commit is contained in:
Stephan
2019-01-24 15:22:20 +01:00
parent a6d3078638
commit 38ec97bbe3
5 changed files with 15 additions and 7 deletions

View File

@@ -156,10 +156,17 @@ namespace Umbraco.Core.Models.PublishedContent
/// <summary>
/// Gets a value indicating whether the content is published.
/// </summary>
/// <param name="culture"></param>
/// <remarks>
/// <para>A content is published when it has a published version.</para>
/// <para>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).</para>
/// <para>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.</para>
/// </remarks>
bool IsPublished(string culture = null);
#endregion
#region Tree

View File

@@ -114,7 +114,6 @@ namespace Umbraco.Core.Models.PublishedContent
/// <inheritdoc />
public virtual bool IsPublished(string culture = null) => _content.IsPublished(culture);
#endregion
#region Tree

View File

@@ -144,6 +144,7 @@ namespace Umbraco.Web.Models
/// <inheritdoc />
public abstract bool IsDraft(string culture = null);
/// <inheritdoc />
public abstract bool IsPublished(string culture = null);
#endregion

View File

@@ -293,8 +293,11 @@ namespace Umbraco.Web.PublishedCache.NuCache
return _contentData.CultureInfos.TryGetValue(culture, out var cvar) && cvar.IsDraft;
}
/// <inheritdoc />
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;

View File

@@ -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<IPublishedProperty> 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;