Merge branch temp8 into temp8-di2690
This commit is contained in:
@@ -152,7 +152,7 @@ namespace Umbraco.Web.PublishedCache.NuCache
|
||||
var urlSegment = n.GetUrlSegment(culture);
|
||||
var hasDomains = _domainHelper.NodeHasDomains(n.Id);
|
||||
while (hasDomains == false && n != null) // n is null at root
|
||||
{
|
||||
{
|
||||
// no segment indicates this is not published when this is a variant
|
||||
if (urlSegment.IsNullOrWhiteSpace()) return null;
|
||||
|
||||
@@ -178,7 +178,7 @@ namespace Umbraco.Web.PublishedCache.NuCache
|
||||
var path = "/" + string.Join("/", pathParts); // will be "/" or "/foo" or "/foo/bar" etc
|
||||
//prefix the root node id containing the domain if it exists (this is a standard way of creating route paths)
|
||||
//and is done so that we know the ID of the domain node for the path
|
||||
var route = (n?.Id.ToString(CultureInfo.InvariantCulture) ?? "") + path;
|
||||
var route = (n?.Id.ToString(CultureInfo.InvariantCulture) ?? "") + path;
|
||||
|
||||
return route;
|
||||
}
|
||||
@@ -228,24 +228,14 @@ namespace Umbraco.Web.PublishedCache.NuCache
|
||||
|
||||
public override IPublishedContent GetById(bool preview, int contentId)
|
||||
{
|
||||
var n = _snapshot.Get(contentId);
|
||||
if (n == null) return null;
|
||||
|
||||
// both .Draft and .Published cannot be null at the same time
|
||||
return preview
|
||||
? n.Draft ?? GetPublishedContentAsPreviewing(n.Published)
|
||||
: n.Published;
|
||||
var node = _snapshot.Get(contentId);
|
||||
return GetNodePublishedContent(node, preview);
|
||||
}
|
||||
|
||||
public override IPublishedContent GetById(bool preview, Guid contentId)
|
||||
{
|
||||
var n = _snapshot.Get(contentId);
|
||||
if (n == null) return null;
|
||||
|
||||
// both .Draft and .Published cannot be null at the same time
|
||||
return preview
|
||||
? n.Draft ?? GetPublishedContentAsPreviewing(n.Published)
|
||||
: n.Published;
|
||||
var node = _snapshot.Get(contentId);
|
||||
return GetNodePublishedContent(node, preview);
|
||||
}
|
||||
|
||||
public override bool HasById(bool preview, int contentId)
|
||||
@@ -279,14 +269,24 @@ namespace Umbraco.Web.PublishedCache.NuCache
|
||||
var c = _snapshot.GetAtRoot();
|
||||
|
||||
// both .Draft and .Published cannot be null at the same time
|
||||
return c.Select(n => preview
|
||||
? n.Draft ?? GetPublishedContentAsPreviewing(n.Published)
|
||||
: n.Published).WhereNotNull().OrderBy(x => x.SortOrder);
|
||||
return c.Select(n => GetNodePublishedContent(n, preview)).WhereNotNull().OrderBy(x => x.SortOrder);
|
||||
}
|
||||
|
||||
private static IPublishedContent GetNodePublishedContent(ContentNode node, bool preview)
|
||||
{
|
||||
if (node == null)
|
||||
return null;
|
||||
|
||||
// both .Draft and .Published cannot be null at the same time
|
||||
|
||||
return preview
|
||||
? node.Draft ?? GetPublishedContentAsDraft(node.Published)
|
||||
: node.Published;
|
||||
}
|
||||
|
||||
// gets a published content as a previewing draft, if preview is true
|
||||
// this is for published content when previewing
|
||||
internal static IPublishedContent GetPublishedContentAsPreviewing(IPublishedContent content /*, bool preview*/)
|
||||
private static IPublishedContent GetPublishedContentAsDraft(IPublishedContent content /*, bool preview*/)
|
||||
{
|
||||
if (content == null /*|| preview == false*/) return null; //content;
|
||||
|
||||
@@ -295,7 +295,7 @@ namespace Umbraco.Web.PublishedCache.NuCache
|
||||
// case we need to unwrap to get to the original IPublishedContentOrMedia.
|
||||
|
||||
var inner = PublishedContent.UnwrapIPublishedContent(content);
|
||||
return inner.AsPreviewingModel();
|
||||
return inner.AsDraft();
|
||||
}
|
||||
|
||||
public override bool HasContent(bool preview)
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using Newtonsoft.Json;
|
||||
using System.Collections.Generic;
|
||||
using Umbraco.Core.Serialization;
|
||||
|
||||
namespace Umbraco.Web.PublishedCache.NuCache.DataSource
|
||||
{
|
||||
@@ -9,9 +10,11 @@ namespace Umbraco.Web.PublishedCache.NuCache.DataSource
|
||||
internal class ContentNestedData
|
||||
{
|
||||
[JsonProperty("properties")]
|
||||
[JsonConverter(typeof(CaseInsensitiveDictionaryConverter<PropertyData[]>))]
|
||||
public Dictionary<string, PropertyData[]> PropertyData { get; set; }
|
||||
|
||||
[JsonProperty("cultureData")]
|
||||
[JsonConverter(typeof(CaseInsensitiveDictionaryConverter<CultureVariation>))]
|
||||
public Dictionary<string, CultureVariation> CultureData { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,5 +13,8 @@ namespace Umbraco.Web.PublishedCache.NuCache.DataSource
|
||||
|
||||
[JsonProperty("date")]
|
||||
public DateTime Date { get; set; }
|
||||
|
||||
[JsonProperty("isDraft")]
|
||||
public bool IsDraft { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -182,27 +182,30 @@ namespace Umbraco.Web.PublishedCache.NuCache.DataSource
|
||||
ContentData d = null;
|
||||
ContentData p = null;
|
||||
|
||||
if (dto.EditData == null)
|
||||
if (dto.Edited)
|
||||
{
|
||||
if (Debugger.IsAttached)
|
||||
throw new Exception("Missing cmsContentNu edited content for node " + dto.Id + ", consider rebuilding.");
|
||||
Current.Logger.Warn<DatabaseDataSource>("Missing cmsContentNu edited content for node {NodeId}, consider rebuilding.", dto.Id);
|
||||
}
|
||||
else
|
||||
{
|
||||
var nested = DeserializeNestedData(dto.EditData);
|
||||
|
||||
d = new ContentData
|
||||
if (dto.EditData == null)
|
||||
{
|
||||
Name = dto.EditName,
|
||||
Published = false,
|
||||
TemplateId = dto.EditTemplateId,
|
||||
VersionId = dto.VersionId,
|
||||
VersionDate = dto.EditVersionDate,
|
||||
WriterId = dto.EditWriterId,
|
||||
Properties = nested.PropertyData,
|
||||
CultureInfos = nested.CultureData
|
||||
};
|
||||
if (Debugger.IsAttached)
|
||||
throw new Exception("Missing cmsContentNu edited content for node " + dto.Id + ", consider rebuilding.");
|
||||
Current.Logger.Warn<DatabaseDataSource>("Missing cmsContentNu edited content for node {NodeId}, consider rebuilding.", dto.Id);
|
||||
}
|
||||
else
|
||||
{
|
||||
var nested = DeserializeNestedData(dto.EditData);
|
||||
|
||||
d = new ContentData
|
||||
{
|
||||
Name = dto.EditName,
|
||||
Published = false,
|
||||
TemplateId = dto.EditTemplateId,
|
||||
VersionId = dto.VersionId,
|
||||
VersionDate = dto.EditVersionDate,
|
||||
WriterId = dto.EditWriterId,
|
||||
Properties = nested.PropertyData,
|
||||
CultureInfos = nested.CultureData
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
if (dto.Published)
|
||||
|
||||
@@ -29,7 +29,7 @@ namespace Umbraco.Web.PublishedCache.NuCache.Navigable
|
||||
XmlString(i++, _content.WriterId),
|
||||
XmlString(i++, _content.CreatorId),
|
||||
XmlString(i++, _content.UrlSegment),
|
||||
XmlString(i, _content.IsDraft)
|
||||
XmlString(i, _content.IsDraft())
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -273,8 +273,27 @@ namespace Umbraco.Web.PublishedCache.NuCache
|
||||
/// <inheritdoc />
|
||||
public override PublishedItemType ItemType => _contentNode.ContentType.ItemType;
|
||||
|
||||
// fixme
|
||||
// was => _contentData.Published == false;
|
||||
/// <inheritdoc />
|
||||
public override bool IsDraft => _contentData.Published == false;
|
||||
public override bool IsDraft(string culture = null)
|
||||
{
|
||||
// if this is the 'published' published content, nothing can be draft
|
||||
if (_contentData.Published)
|
||||
return false;
|
||||
|
||||
// not the 'published' published content, and does not vary = must be draft
|
||||
if (!ContentType.VariesByCulture())
|
||||
return true;
|
||||
|
||||
// handle context culture
|
||||
if (culture == null)
|
||||
culture = VariationContextAccessor?.VariationContext?.Culture ?? "";
|
||||
|
||||
// not the 'published' published content, and varies
|
||||
// = depends on the culture
|
||||
return _contentData.CultureInfos.TryGetValue(culture, out var cvar) && cvar.IsDraft;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -410,7 +429,7 @@ namespace Umbraco.Web.PublishedCache.NuCache
|
||||
private string AsPreviewingCacheKey => _asPreviewingCacheKey ?? (_asPreviewingCacheKey = CacheKeys.PublishedContentAsPreviewing(Key));
|
||||
|
||||
// used by ContentCache
|
||||
internal IPublishedContent AsPreviewingModel()
|
||||
internal IPublishedContent AsDraft()
|
||||
{
|
||||
if (IsPreviewing)
|
||||
return this;
|
||||
|
||||
@@ -1206,7 +1206,8 @@ namespace Umbraco.Web.PublishedCache.NuCache
|
||||
|
||||
foreach (var (culture, info) in infos)
|
||||
{
|
||||
cultureData[culture] = new CultureVariation { Name = info.Name, Date = content.GetUpdateDate(culture) ?? DateTime.MinValue };
|
||||
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 };
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user