Merge pull request #4205 from umbraco/temp8-fixmes-add-ispublished-to-ipublished-content
Added IsPublished(culture) to IPublishedContent
This commit is contained in:
@@ -153,8 +153,12 @@ namespace Umbraco.Core.Models.PublishedContent
|
||||
/// </remarks>
|
||||
bool IsDraft(string culture = null);
|
||||
|
||||
// fixme/task - consider having an IsPublished flag too
|
||||
// so that when IsDraft is true, we can check whether there is a published version?
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the content is published.
|
||||
/// </summary>
|
||||
/// <param name="culture"></param>
|
||||
bool IsPublished(string culture = null);
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
@@ -111,6 +111,10 @@ namespace Umbraco.Core.Models.PublishedContent
|
||||
/// <inheritdoc />
|
||||
public virtual bool IsDraft(string culture = null) => _content.IsDraft(culture);
|
||||
|
||||
/// <inheritdoc />
|
||||
public virtual bool IsPublished(string culture = null) => _content.IsPublished(culture);
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region Tree
|
||||
|
||||
@@ -94,6 +94,7 @@ namespace Umbraco.Tests.Benchmarks
|
||||
Guid key, version;
|
||||
string name, urlName, writerName, creatorName, docTypeAlias, path;
|
||||
bool isDraft;
|
||||
bool isPublished;
|
||||
DateTime createDate, updateDate;
|
||||
PublishedContentType publishedContentType;
|
||||
Dictionary<string, IPublishedProperty> properties;
|
||||
@@ -104,7 +105,7 @@ namespace Umbraco.Tests.Benchmarks
|
||||
OriginalInitializeNode(_xml10.DocumentElement, false, false,
|
||||
out id, out key, out template, out sortOrder, out name, out writerName, out urlName,
|
||||
out creatorName, out creatorId, out writerId, out docTypeAlias, out nodeType, out path,
|
||||
out version, out createDate, out updateDate, out level, out isDraft, out publishedContentType,
|
||||
out version, out createDate, out updateDate, out level, out isDraft, out isPublished, out publishedContentType,
|
||||
out properties);
|
||||
}
|
||||
|
||||
@@ -114,7 +115,7 @@ namespace Umbraco.Tests.Benchmarks
|
||||
OriginalInitializeNode(_xml100.DocumentElement, false, false,
|
||||
out id, out key, out template, out sortOrder, out name, out writerName, out urlName,
|
||||
out creatorName, out creatorId, out writerId, out docTypeAlias, out nodeType, out path,
|
||||
out version, out createDate, out updateDate, out level, out isDraft, out publishedContentType,
|
||||
out version, out createDate, out updateDate, out level, out isDraft, out isPublished, out publishedContentType,
|
||||
out properties);
|
||||
}
|
||||
|
||||
@@ -124,7 +125,7 @@ namespace Umbraco.Tests.Benchmarks
|
||||
OriginalInitializeNode(_xml1000.DocumentElement, false, false,
|
||||
out id, out key, out template, out sortOrder, out name, out writerName, out urlName,
|
||||
out creatorName, out creatorId, out writerId, out docTypeAlias, out nodeType, out path,
|
||||
out version, out createDate, out updateDate, out level, out isDraft, out publishedContentType,
|
||||
out version, out createDate, out updateDate, out level, out isDraft, out isPublished, out publishedContentType,
|
||||
out properties);
|
||||
}
|
||||
|
||||
@@ -134,7 +135,7 @@ namespace Umbraco.Tests.Benchmarks
|
||||
OriginalInitializeNode(_xml10000.DocumentElement, false, false,
|
||||
out id, out key, out template, out sortOrder, out name, out writerName, out urlName,
|
||||
out creatorName, out creatorId, out writerId, out docTypeAlias, out nodeType, out path,
|
||||
out version, out createDate, out updateDate, out level, out isDraft, out publishedContentType,
|
||||
out version, out createDate, out updateDate, out level, out isDraft, out isPublished, out publishedContentType,
|
||||
out properties);
|
||||
}
|
||||
|
||||
@@ -144,7 +145,7 @@ namespace Umbraco.Tests.Benchmarks
|
||||
XmlPublishedContent.InitializeNode(null, _xml10.DocumentElement, false,
|
||||
out id, out key, out template, out sortOrder, out name, out writerName, out urlName,
|
||||
out creatorName, out creatorId, out writerId, out docTypeAlias, out nodeType, out path,
|
||||
out createDate, out updateDate, out level, out isDraft, out publishedContentType,
|
||||
out createDate, out updateDate, out level, out isDraft, out isPublished, out publishedContentType,
|
||||
out properties, GetPublishedContentType);
|
||||
}
|
||||
|
||||
@@ -154,7 +155,7 @@ namespace Umbraco.Tests.Benchmarks
|
||||
XmlPublishedContent.InitializeNode(null, _xml100.DocumentElement, false,
|
||||
out id, out key, out template, out sortOrder, out name, out writerName, out urlName,
|
||||
out creatorName, out creatorId, out writerId, out docTypeAlias, out nodeType, out path,
|
||||
out createDate, out updateDate, out level, out isDraft, out publishedContentType,
|
||||
out createDate, out updateDate, out level, out isDraft, out isPublished,out publishedContentType,
|
||||
out properties, GetPublishedContentType);
|
||||
}
|
||||
|
||||
@@ -164,7 +165,7 @@ namespace Umbraco.Tests.Benchmarks
|
||||
XmlPublishedContent.InitializeNode(null, _xml1000.DocumentElement, false,
|
||||
out id, out key, out template, out sortOrder, out name, out writerName, out urlName,
|
||||
out creatorName, out creatorId, out writerId, out docTypeAlias, out nodeType, out path,
|
||||
out createDate, out updateDate, out level, out isDraft, out publishedContentType,
|
||||
out createDate, out updateDate, out level, out isDraft, out isPublished,out publishedContentType,
|
||||
out properties, GetPublishedContentType);
|
||||
}
|
||||
|
||||
@@ -174,7 +175,7 @@ namespace Umbraco.Tests.Benchmarks
|
||||
XmlPublishedContent.InitializeNode(null, _xml10000.DocumentElement, false,
|
||||
out id, out key, out template, out sortOrder, out name, out writerName, out urlName,
|
||||
out creatorName, out creatorId, out writerId, out docTypeAlias, out nodeType, out path,
|
||||
out createDate, out updateDate, out level, out isDraft, out publishedContentType,
|
||||
out createDate, out updateDate, out level, out isDraft, out isPublished,out publishedContentType,
|
||||
out properties, GetPublishedContentType);
|
||||
}
|
||||
|
||||
@@ -182,7 +183,7 @@ namespace Umbraco.Tests.Benchmarks
|
||||
internal static void OriginalInitializeNode(XmlNode xmlNode, bool legacy, bool isPreviewing,
|
||||
out int id, out Guid key, out int template, out int sortOrder, out string name, out string writerName, out string urlName,
|
||||
out string creatorName, out int creatorId, out int writerId, out string docTypeAlias, out int docTypeId, out string path,
|
||||
out Guid version, out DateTime createDate, out DateTime updateDate, out int level, out bool isDraft,
|
||||
out Guid version, out DateTime createDate, out DateTime updateDate, out int level, out bool isDraft, out bool isPublished,
|
||||
out PublishedContentType contentType, out Dictionary<string, IPublishedProperty> properties)
|
||||
{
|
||||
//initialize the out params with defaults:
|
||||
@@ -193,6 +194,7 @@ namespace Umbraco.Tests.Benchmarks
|
||||
name = writerName = urlName = creatorName = docTypeAlias = path = null;
|
||||
createDate = updateDate = default(DateTime);
|
||||
isDraft = false;
|
||||
isPublished = true;
|
||||
contentType = null;
|
||||
properties = null;
|
||||
|
||||
|
||||
@@ -262,6 +262,7 @@ namespace Umbraco.Tests.Published
|
||||
// ReSharper disable UnassignedGetOnlyAutoProperty
|
||||
public override PublishedItemType ItemType { get; }
|
||||
public override bool IsDraft(string culture = null) => false;
|
||||
public override bool IsPublished(string culture = null) => true;
|
||||
public override IPublishedContent Parent { get; }
|
||||
public override IEnumerable<IPublishedContent> Children { get; }
|
||||
public override PublishedContentType ContentType { get; }
|
||||
|
||||
@@ -217,6 +217,7 @@ namespace Umbraco.Tests.PublishedContent
|
||||
public Guid Version { get; set; }
|
||||
public int Level { get; set; }
|
||||
public bool IsDraft(string culture = null) => false;
|
||||
public bool IsPublished(string culture = null) => true;
|
||||
|
||||
public IEnumerable<IPublishedProperty> Properties { get; set; }
|
||||
|
||||
|
||||
@@ -192,6 +192,7 @@ namespace Umbraco.Tests.PublishedContent
|
||||
|
||||
public PublishedItemType ItemType { get { return PublishedItemType.Content; } }
|
||||
public bool IsDraft(string culture = null) => false;
|
||||
public bool IsPublished(string culture = null) => true;
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
@@ -48,6 +48,7 @@ namespace Umbraco.Tests.TestHelpers.Stubs
|
||||
public string GetUrl(string culture = null) => throw new NotSupportedException();
|
||||
public PublishedItemType ItemType => ContentType.ItemType;
|
||||
public bool IsDraft(string culture = null) => false;
|
||||
public bool IsPublished(string culture = null) => true;
|
||||
public IPublishedContent Parent { get; set; }
|
||||
public IEnumerable<IPublishedContent> Children { get; set; }
|
||||
|
||||
|
||||
@@ -144,6 +144,8 @@ namespace Umbraco.Web.Models
|
||||
/// <inheritdoc />
|
||||
public abstract bool IsDraft(string culture = null);
|
||||
|
||||
public abstract bool IsPublished(string culture = null);
|
||||
|
||||
#endregion
|
||||
|
||||
#region Tree
|
||||
|
||||
@@ -293,6 +293,23 @@ namespace Umbraco.Web.PublishedCache.NuCache
|
||||
return _contentData.CultureInfos.TryGetValue(culture, out var cvar) && cvar.IsDraft;
|
||||
}
|
||||
|
||||
public override bool IsPublished(string culture = null)
|
||||
{
|
||||
if (!ContentType.VariesByCulture())
|
||||
{
|
||||
return _contentData.Published;
|
||||
}
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Tree
|
||||
|
||||
@@ -78,6 +78,8 @@ namespace Umbraco.Web.PublishedCache
|
||||
|
||||
public override bool IsDraft(string culture = null) => false;
|
||||
|
||||
public override bool IsPublished(string culture = null) => true;
|
||||
|
||||
public override IPublishedContent Parent => null;
|
||||
|
||||
public override IEnumerable<IPublishedContent> Children => Enumerable.Empty<IPublishedContent>();
|
||||
|
||||
@@ -179,6 +179,8 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
|
||||
|
||||
public override bool IsDraft(string culture = null) => false;
|
||||
|
||||
public override bool IsPublished(string culture = null) => true;
|
||||
|
||||
public override IEnumerable<IPublishedProperty> Properties => _properties;
|
||||
|
||||
public override IEnumerable<IPublishedContent> Children => _getChildren.Value;
|
||||
|
||||
@@ -63,6 +63,7 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
|
||||
private int _sortOrder;
|
||||
private int _level;
|
||||
private bool _isDraft;
|
||||
private bool _isPublished;
|
||||
|
||||
public override IEnumerable<IPublishedContent> Children
|
||||
{
|
||||
@@ -228,6 +229,12 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
|
||||
return _isDraft; // bah
|
||||
}
|
||||
|
||||
public override bool IsPublished(string culture = null)
|
||||
{
|
||||
EnsureNodeInitialized();
|
||||
return _isPublished;
|
||||
}
|
||||
|
||||
public override IEnumerable<IPublishedProperty> Properties
|
||||
{
|
||||
get
|
||||
@@ -280,7 +287,7 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
|
||||
InitializeNode(this, _xmlNode, _isPreviewing,
|
||||
out _id, out _key, out _template, out _sortOrder, out _name, out _writerName,
|
||||
out _urlName, out _creatorName, out _creatorId, out _writerId, out _docTypeAlias, out _docTypeId, out _path,
|
||||
out _createDate, out _updateDate, out _level, out _isDraft, out _contentType, out _properties,
|
||||
out _createDate, out _updateDate, out _level, out _isDraft, out _isPublished, out _contentType, out _properties,
|
||||
_contentTypeCache.Get);
|
||||
|
||||
_nodeInitialized = true;
|
||||
@@ -290,7 +297,7 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
|
||||
internal static void InitializeNode(XmlPublishedContent node, XmlNode xmlNode, bool isPreviewing,
|
||||
out int id, out Guid key, out int template, out int sortOrder, out string name, out string writerName, out string urlName,
|
||||
out string creatorName, out int creatorId, out int writerId, out string docTypeAlias, out int docTypeId, out string path,
|
||||
out DateTime createDate, out DateTime updateDate, out int level, out bool isDraft,
|
||||
out DateTime createDate, out DateTime updateDate, out int level, out bool isDraft,out bool isPublished,
|
||||
out PublishedContentType contentType, out Dictionary<string, IPublishedProperty> properties,
|
||||
Func<PublishedItemType, string, PublishedContentType> getPublishedContentType)
|
||||
{
|
||||
@@ -302,6 +309,7 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
|
||||
name = writerName = urlName = creatorName = docTypeAlias = path = null;
|
||||
createDate = updateDate = default(DateTime);
|
||||
isDraft = false;
|
||||
isPublished = false;
|
||||
contentType = null;
|
||||
properties = null;
|
||||
|
||||
|
||||
@@ -469,6 +469,11 @@ namespace umbraco
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public bool IsPublished(string culture = null)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public IPublishedContent Parent
|
||||
{
|
||||
get { return _parent; }
|
||||
|
||||
Reference in New Issue
Block a user