2016-05-27 14:26:28 +02:00
|
|
|
|
using Umbraco.Core.Models.PublishedContent;
|
|
|
|
|
|
using Umbraco.Web.PublishedCache.NuCache.DataSource;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Umbraco.Web.PublishedCache.NuCache
|
|
|
|
|
|
{
|
|
|
|
|
|
// what's needed to actually build a content node
|
2020-02-06 14:40:46 +01:00
|
|
|
|
public struct ContentNodeKit
|
2016-05-27 14:26:28 +02:00
|
|
|
|
{
|
|
|
|
|
|
public ContentNode Node;
|
|
|
|
|
|
public int ContentTypeId;
|
|
|
|
|
|
public ContentData DraftData;
|
|
|
|
|
|
public ContentData PublishedData;
|
|
|
|
|
|
|
2016-05-30 19:54:36 +02:00
|
|
|
|
public bool IsEmpty => Node == null;
|
2016-05-27 14:26:28 +02:00
|
|
|
|
|
2017-07-17 10:48:48 +02:00
|
|
|
|
public bool IsNull => ContentTypeId < 0;
|
|
|
|
|
|
|
|
|
|
|
|
public static ContentNodeKit Null { get; } = new ContentNodeKit { ContentTypeId = -1 };
|
|
|
|
|
|
|
2019-01-23 14:16:42 +01:00
|
|
|
|
public void Build(
|
2019-04-15 13:04:14 +02:00
|
|
|
|
IPublishedContentType contentType,
|
2019-01-23 14:16:42 +01:00
|
|
|
|
IPublishedSnapshotAccessor publishedSnapshotAccessor,
|
|
|
|
|
|
IVariationContextAccessor variationContextAccessor,
|
2019-12-10 08:37:19 +01:00
|
|
|
|
IPublishedModelFactory publishedModelFactory,
|
2019-04-24 14:25:41 +02:00
|
|
|
|
bool canBePublished)
|
2016-05-27 14:26:28 +02:00
|
|
|
|
{
|
2019-02-14 08:03:00 +01:00
|
|
|
|
var draftData = DraftData;
|
|
|
|
|
|
|
|
|
|
|
|
// no published data if it cannot be published (eg is masked)
|
|
|
|
|
|
var publishedData = canBePublished ? PublishedData : null;
|
|
|
|
|
|
|
|
|
|
|
|
// we *must* have either published or draft data
|
|
|
|
|
|
// if it cannot be published, published data is going to be null
|
|
|
|
|
|
// therefore, ensure that draft data is not
|
|
|
|
|
|
if (draftData == null && !canBePublished)
|
|
|
|
|
|
draftData = PublishedData;
|
|
|
|
|
|
|
2019-12-10 08:37:19 +01:00
|
|
|
|
Node.SetContentTypeAndData(contentType, draftData, publishedData, publishedSnapshotAccessor, variationContextAccessor, publishedModelFactory);
|
2016-05-27 14:26:28 +02:00
|
|
|
|
}
|
2019-05-29 16:48:20 +02:00
|
|
|
|
|
2019-12-10 08:37:19 +01:00
|
|
|
|
public ContentNodeKit Clone(IPublishedModelFactory publishedModelFactory)
|
2019-05-29 16:48:20 +02:00
|
|
|
|
=> new ContentNodeKit
|
|
|
|
|
|
{
|
|
|
|
|
|
ContentTypeId = ContentTypeId,
|
|
|
|
|
|
DraftData = DraftData,
|
|
|
|
|
|
PublishedData = PublishedData,
|
2019-12-10 08:37:19 +01:00
|
|
|
|
Node = new ContentNode(Node, publishedModelFactory)
|
2019-05-29 16:48:20 +02:00
|
|
|
|
};
|
2016-05-27 14:26:28 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|