2022-09-19 16:14:16 +02:00
|
|
|
using Umbraco.Cms.Core.Models.PublishedContent;
|
2021-02-18 11:06:02 +01:00
|
|
|
using Umbraco.Cms.Core.PublishedCache;
|
|
|
|
|
using Umbraco.Cms.Infrastructure.PublishedCache.DataSource;
|
2016-05-27 14:26:28 +02:00
|
|
|
|
2022-06-20 09:21:08 +02:00
|
|
|
namespace Umbraco.Cms.Infrastructure.PublishedCache;
|
|
|
|
|
|
2022-09-19 16:14:16 +02:00
|
|
|
public struct ContentNodeKit
|
|
|
|
|
{
|
|
|
|
|
[Obsolete("This will be changed to a property in future versions")]
|
|
|
|
|
public ContentNode Node = null!;
|
2021-10-19 23:11:54 +11:00
|
|
|
|
2022-09-19 16:14:16 +02:00
|
|
|
[Obsolete("This will be changed to a property in future versions")]
|
|
|
|
|
public int ContentTypeId;
|
2021-10-19 23:11:54 +11:00
|
|
|
|
2022-09-19 16:14:16 +02:00
|
|
|
[Obsolete("This will be changed to a property in future versions")]
|
|
|
|
|
public ContentData? DraftData;
|
2021-10-19 23:11:54 +11:00
|
|
|
|
2022-09-19 16:14:16 +02:00
|
|
|
[Obsolete("This will be changed to a property in future versions")]
|
|
|
|
|
public ContentData? PublishedData;
|
2016-05-27 14:26:28 +02:00
|
|
|
|
2022-06-20 09:21:08 +02:00
|
|
|
public ContentNodeKit(ContentNode node, int contentTypeId, ContentData? draftData, ContentData? publishedData)
|
|
|
|
|
{
|
|
|
|
|
Node = node;
|
|
|
|
|
ContentTypeId = contentTypeId;
|
|
|
|
|
DraftData = draftData;
|
|
|
|
|
PublishedData = publishedData;
|
|
|
|
|
}
|
2021-10-19 23:11:54 +11:00
|
|
|
|
2022-06-20 09:21:08 +02:00
|
|
|
public static ContentNodeKit Empty { get; } = default(ContentNodeKit);
|
2016-05-27 14:26:28 +02:00
|
|
|
|
2022-06-20 09:21:08 +02:00
|
|
|
public bool IsEmpty => Node == null;
|
2017-07-17 10:48:48 +02:00
|
|
|
|
2022-06-20 09:21:08 +02:00
|
|
|
public bool IsNull => ContentTypeId < 0;
|
2017-07-17 10:48:48 +02:00
|
|
|
|
2022-06-20 09:21:08 +02:00
|
|
|
public static ContentNodeKit Null { get; } = new(null!, -1, null, null);
|
2019-02-14 08:03:00 +01:00
|
|
|
|
2022-06-20 09:21:08 +02:00
|
|
|
public void Build(
|
|
|
|
|
IPublishedContentType contentType,
|
|
|
|
|
IPublishedSnapshotAccessor publishedSnapshotAccessor,
|
|
|
|
|
IVariationContextAccessor variationContextAccessor,
|
|
|
|
|
IPublishedModelFactory publishedModelFactory,
|
|
|
|
|
bool canBePublished)
|
|
|
|
|
{
|
|
|
|
|
ContentData? draftData = DraftData;
|
2019-02-14 08:03:00 +01:00
|
|
|
|
2022-06-20 09:21:08 +02:00
|
|
|
// no published data if it cannot be published (eg is masked)
|
|
|
|
|
ContentData? publishedData = canBePublished ? PublishedData : null;
|
2019-02-14 08:03:00 +01:00
|
|
|
|
2022-06-20 09:21:08 +02:00
|
|
|
// 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;
|
2016-05-27 14:26:28 +02:00
|
|
|
}
|
2019-05-29 16:48:20 +02:00
|
|
|
|
2022-06-20 09:21:08 +02:00
|
|
|
Node?.SetContentTypeAndData(contentType, draftData, publishedData, publishedSnapshotAccessor, variationContextAccessor, publishedModelFactory);
|
2016-05-27 14:26:28 +02:00
|
|
|
}
|
2022-06-20 09:21:08 +02:00
|
|
|
|
|
|
|
|
public ContentNodeKit Clone(IPublishedModelFactory publishedModelFactory)
|
|
|
|
|
=> new(new ContentNode(Node, publishedModelFactory), ContentTypeId, DraftData, PublishedData);
|
|
|
|
|
|
|
|
|
|
public ContentNodeKit Clone(IPublishedModelFactory publishedModelFactory, ContentData draftData, ContentData publishedData)
|
|
|
|
|
=> new(new ContentNode(Node, publishedModelFactory), ContentTypeId, draftData, publishedData);
|
2016-05-27 14:26:28 +02:00
|
|
|
}
|