2016-05-27 14:26:28 +02:00
|
|
|
|
using System;
|
|
|
|
|
|
using Umbraco.Core.Models.PublishedContent;
|
|
|
|
|
|
using Umbraco.Web.PublishedCache.NuCache.DataSource;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Umbraco.Web.PublishedCache.NuCache
|
|
|
|
|
|
{
|
|
|
|
|
|
// represents a content "node" ie a pair of draft + published versions
|
|
|
|
|
|
// internal, never exposed, to be accessed from ContentStore (only!)
|
|
|
|
|
|
internal class ContentNode
|
|
|
|
|
|
{
|
2019-04-22 17:51:07 +02:00
|
|
|
|
// special ctor for root pseudo node
|
|
|
|
|
|
public ContentNode()
|
2019-04-22 19:49:49 +02:00
|
|
|
|
{
|
|
|
|
|
|
FirstChildContentId = -1;
|
2019-08-19 23:22:27 +10:00
|
|
|
|
LastChildContentId = -1;
|
2019-04-22 19:49:49 +02:00
|
|
|
|
NextSiblingContentId = -1;
|
2019-08-19 23:22:27 +10:00
|
|
|
|
PreviousSiblingContentId = -1;
|
2019-04-22 19:49:49 +02:00
|
|
|
|
}
|
2019-04-22 17:51:07 +02:00
|
|
|
|
|
2016-05-27 14:26:28 +02:00
|
|
|
|
// special ctor with no content data - for members
|
2019-04-15 13:04:14 +02:00
|
|
|
|
public ContentNode(int id, Guid uid, IPublishedContentType contentType,
|
2016-05-27 14:26:28 +02:00
|
|
|
|
int level, string path, int sortOrder,
|
|
|
|
|
|
int parentContentId,
|
|
|
|
|
|
DateTime createDate, int creatorId)
|
2019-04-22 19:49:49 +02:00
|
|
|
|
: this()
|
2016-05-27 14:26:28 +02:00
|
|
|
|
{
|
|
|
|
|
|
Id = id;
|
|
|
|
|
|
Uid = uid;
|
|
|
|
|
|
ContentType = contentType;
|
|
|
|
|
|
Level = level;
|
|
|
|
|
|
Path = path;
|
|
|
|
|
|
SortOrder = sortOrder;
|
|
|
|
|
|
ParentContentId = parentContentId;
|
|
|
|
|
|
CreateDate = createDate;
|
|
|
|
|
|
CreatorId = creatorId;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-04-15 13:04:14 +02:00
|
|
|
|
public ContentNode(int id, Guid uid, IPublishedContentType contentType,
|
2016-05-27 14:26:28 +02:00
|
|
|
|
int level, string path, int sortOrder,
|
|
|
|
|
|
int parentContentId,
|
|
|
|
|
|
DateTime createDate, int creatorId,
|
2016-05-30 19:54:36 +02:00
|
|
|
|
ContentData draftData, ContentData publishedData,
|
2018-04-18 19:46:47 +02:00
|
|
|
|
IPublishedSnapshotAccessor publishedSnapshotAccessor,
|
2019-04-24 14:25:41 +02:00
|
|
|
|
IVariationContextAccessor variationContextAccessor)
|
2016-05-27 14:26:28 +02:00
|
|
|
|
: this(id, uid, level, path, sortOrder, parentContentId, createDate, creatorId)
|
|
|
|
|
|
{
|
2019-04-24 14:25:41 +02:00
|
|
|
|
SetContentTypeAndData(contentType, draftData, publishedData, publishedSnapshotAccessor, variationContextAccessor);
|
2016-05-27 14:26:28 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 2-phases ctor, phase 1
|
|
|
|
|
|
public ContentNode(int id, Guid uid,
|
|
|
|
|
|
int level, string path, int sortOrder,
|
|
|
|
|
|
int parentContentId,
|
|
|
|
|
|
DateTime createDate, int creatorId)
|
|
|
|
|
|
{
|
|
|
|
|
|
Id = id;
|
|
|
|
|
|
Uid = uid;
|
|
|
|
|
|
Level = level;
|
|
|
|
|
|
Path = path;
|
|
|
|
|
|
SortOrder = sortOrder;
|
|
|
|
|
|
ParentContentId = parentContentId;
|
2019-04-22 17:51:07 +02:00
|
|
|
|
FirstChildContentId = -1;
|
2019-08-19 23:22:27 +10:00
|
|
|
|
LastChildContentId = -1;
|
2019-04-22 17:51:07 +02:00
|
|
|
|
NextSiblingContentId = -1;
|
2019-08-19 23:22:27 +10:00
|
|
|
|
PreviousSiblingContentId = -1;
|
2016-05-27 14:26:28 +02:00
|
|
|
|
CreateDate = createDate;
|
|
|
|
|
|
CreatorId = creatorId;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// two-phase ctor, phase 2
|
2019-04-24 14:25:41 +02:00
|
|
|
|
public void SetContentTypeAndData(IPublishedContentType contentType, ContentData draftData, ContentData publishedData, IPublishedSnapshotAccessor publishedSnapshotAccessor, IVariationContextAccessor variationContextAccessor)
|
2016-05-27 14:26:28 +02:00
|
|
|
|
{
|
|
|
|
|
|
ContentType = contentType;
|
|
|
|
|
|
|
|
|
|
|
|
if (draftData == null && publishedData == null)
|
|
|
|
|
|
throw new ArgumentException("Both draftData and publishedData cannot be null at the same time.");
|
|
|
|
|
|
|
2019-09-13 09:55:53 +02:00
|
|
|
|
_publishedSnapshotAccessor = publishedSnapshotAccessor;
|
|
|
|
|
|
_variationContextAccessor = variationContextAccessor;
|
2019-01-28 20:07:22 +01:00
|
|
|
|
|
2019-09-13 09:55:53 +02:00
|
|
|
|
_draftData = draftData;
|
|
|
|
|
|
_publishedData = publishedData;
|
2016-05-27 14:26:28 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-04-22 17:51:07 +02:00
|
|
|
|
// clone
|
|
|
|
|
|
public ContentNode(ContentNode origin, IPublishedContentType contentType = null)
|
2016-05-27 14:26:28 +02:00
|
|
|
|
{
|
|
|
|
|
|
Id = origin.Id;
|
|
|
|
|
|
Uid = origin.Uid;
|
2019-04-22 17:51:07 +02:00
|
|
|
|
ContentType = contentType ?? origin.ContentType;
|
2016-05-27 14:26:28 +02:00
|
|
|
|
Level = origin.Level;
|
|
|
|
|
|
Path = origin.Path;
|
|
|
|
|
|
SortOrder = origin.SortOrder;
|
|
|
|
|
|
ParentContentId = origin.ParentContentId;
|
2019-04-22 17:51:07 +02:00
|
|
|
|
FirstChildContentId = origin.FirstChildContentId;
|
2019-08-19 23:22:27 +10:00
|
|
|
|
LastChildContentId = origin.LastChildContentId;
|
2019-04-22 17:51:07 +02:00
|
|
|
|
NextSiblingContentId = origin.NextSiblingContentId;
|
2019-08-19 23:22:27 +10:00
|
|
|
|
PreviousSiblingContentId = origin.PreviousSiblingContentId;
|
2016-05-27 14:26:28 +02:00
|
|
|
|
CreateDate = origin.CreateDate;
|
|
|
|
|
|
CreatorId = origin.CreatorId;
|
|
|
|
|
|
|
2019-09-13 09:55:53 +02:00
|
|
|
|
_draftData = origin._draftData;
|
|
|
|
|
|
_publishedData = origin._publishedData;
|
2019-09-16 16:22:05 +10:00
|
|
|
|
_publishedSnapshotAccessor = origin._publishedSnapshotAccessor;
|
|
|
|
|
|
_variationContextAccessor = origin._variationContextAccessor;
|
2016-05-27 14:26:28 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// everything that is common to both draft and published versions
|
|
|
|
|
|
// keep this as small as possible
|
|
|
|
|
|
public readonly int Id;
|
|
|
|
|
|
public readonly Guid Uid;
|
2019-04-15 13:04:14 +02:00
|
|
|
|
public IPublishedContentType ContentType;
|
2016-05-27 14:26:28 +02:00
|
|
|
|
public readonly int Level;
|
|
|
|
|
|
public readonly string Path;
|
|
|
|
|
|
public readonly int SortOrder;
|
|
|
|
|
|
public readonly int ParentContentId;
|
2019-04-22 17:51:07 +02:00
|
|
|
|
public int FirstChildContentId;
|
2019-08-19 23:22:27 +10:00
|
|
|
|
public int LastChildContentId;
|
2019-04-22 17:51:07 +02:00
|
|
|
|
public int NextSiblingContentId;
|
2019-08-19 23:22:27 +10:00
|
|
|
|
public int PreviousSiblingContentId;
|
2016-05-27 14:26:28 +02:00
|
|
|
|
public readonly DateTime CreateDate;
|
|
|
|
|
|
public readonly int CreatorId;
|
|
|
|
|
|
|
2019-09-13 09:55:53 +02:00
|
|
|
|
private ContentData _draftData;
|
|
|
|
|
|
private ContentData _publishedData;
|
|
|
|
|
|
private IVariationContextAccessor _variationContextAccessor;
|
|
|
|
|
|
private IPublishedSnapshotAccessor _publishedSnapshotAccessor;
|
|
|
|
|
|
|
|
|
|
|
|
public bool HasPublished => _publishedData != null;
|
|
|
|
|
|
public bool HasPublishedCulture(string culture) => _publishedData != null && _publishedData.CultureInfos.ContainsKey(culture);
|
2019-01-28 14:15:47 +01:00
|
|
|
|
|
2016-05-27 14:26:28 +02:00
|
|
|
|
// draft and published version (either can be null, but not both)
|
2017-10-25 13:23:14 +02:00
|
|
|
|
// are models not direct PublishedContent instances
|
2019-09-13 09:55:53 +02:00
|
|
|
|
private IPublishedContent _draftModel;
|
|
|
|
|
|
private IPublishedContent _publishedModel;
|
|
|
|
|
|
|
|
|
|
|
|
private IPublishedContent GetModel(ref IPublishedContent model, ContentData contentData)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (model != null) return model;
|
|
|
|
|
|
if (contentData == null) return null;
|
|
|
|
|
|
|
|
|
|
|
|
// create the model - we want to be fast, so no lock here: we may create
|
|
|
|
|
|
// more than 1 instance, but the lock below ensures we only ever return
|
|
|
|
|
|
// 1 unique instance - and locking is a nice explicit way to ensure this
|
|
|
|
|
|
|
|
|
|
|
|
var m = new PublishedContent(this, contentData, _publishedSnapshotAccessor, _variationContextAccessor).CreateModel();
|
|
|
|
|
|
|
|
|
|
|
|
// locking 'this' is not a best-practice but ContentNode is internal and
|
|
|
|
|
|
// we know what we do, so it is fine here and avoids allocating an object
|
|
|
|
|
|
lock (this)
|
|
|
|
|
|
{
|
|
|
|
|
|
return model = model ?? m;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public IPublishedContent DraftModel => GetModel(ref _draftModel, _draftData);
|
|
|
|
|
|
|
|
|
|
|
|
public IPublishedContent PublishedModel => GetModel(ref _publishedModel, _publishedData);
|
2016-05-27 14:26:28 +02:00
|
|
|
|
|
|
|
|
|
|
public ContentNodeKit ToKit()
|
2019-04-22 17:51:07 +02:00
|
|
|
|
=> new ContentNodeKit
|
|
|
|
|
|
{
|
|
|
|
|
|
Node = this,
|
|
|
|
|
|
ContentTypeId = ContentType.Id,
|
|
|
|
|
|
|
2019-09-13 09:55:53 +02:00
|
|
|
|
DraftData = _draftData,
|
|
|
|
|
|
PublishedData = _publishedData
|
2019-04-22 17:51:07 +02:00
|
|
|
|
};
|
2016-05-27 14:26:28 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|