2016-05-27 14:26:28 +02:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
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
|
|
|
|
|
|
{
|
|
|
|
|
|
// special ctor with no content data - for members
|
|
|
|
|
|
public ContentNode(int id, Guid uid, PublishedContentType contentType,
|
|
|
|
|
|
int level, string path, int sortOrder,
|
|
|
|
|
|
int parentContentId,
|
|
|
|
|
|
DateTime createDate, int creatorId)
|
|
|
|
|
|
{
|
|
|
|
|
|
Id = id;
|
|
|
|
|
|
Uid = uid;
|
|
|
|
|
|
ContentType = contentType;
|
|
|
|
|
|
Level = level;
|
|
|
|
|
|
Path = path;
|
|
|
|
|
|
SortOrder = sortOrder;
|
|
|
|
|
|
ParentContentId = parentContentId;
|
|
|
|
|
|
CreateDate = createDate;
|
|
|
|
|
|
CreatorId = creatorId;
|
|
|
|
|
|
|
|
|
|
|
|
ChildContentIds = new List<int>();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public ContentNode(int id, Guid uid, PublishedContentType contentType,
|
|
|
|
|
|
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,
|
|
|
|
|
|
IPublishedVariationContextAccessor variationContextAccessor)
|
2016-05-27 14:26:28 +02:00
|
|
|
|
: this(id, uid, level, path, sortOrder, parentContentId, createDate, creatorId)
|
|
|
|
|
|
{
|
2018-04-18 19:46:47 +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;
|
|
|
|
|
|
CreateDate = createDate;
|
|
|
|
|
|
CreatorId = creatorId;
|
|
|
|
|
|
|
|
|
|
|
|
ChildContentIds = new List<int>();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// two-phase ctor, phase 2
|
2018-04-18 19:46:47 +02:00
|
|
|
|
public void SetContentTypeAndData(PublishedContentType contentType, ContentData draftData, ContentData publishedData, IPublishedSnapshotAccessor publishedSnapshotAccessor, IPublishedVariationContextAccessor 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.");
|
|
|
|
|
|
|
|
|
|
|
|
if (draftData != null)
|
2018-04-18 19:46:47 +02:00
|
|
|
|
Draft = new PublishedContent(this, draftData, publishedSnapshotAccessor, variationContextAccessor).CreateModel();
|
2016-05-27 14:26:28 +02:00
|
|
|
|
if (publishedData != null)
|
2018-04-18 19:46:47 +02:00
|
|
|
|
Published = new PublishedContent(this, publishedData, publishedSnapshotAccessor, variationContextAccessor).CreateModel();
|
2016-05-27 14:26:28 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// clone parent
|
2017-07-12 14:09:31 +02:00
|
|
|
|
private ContentNode(ContentNode origin)
|
2016-05-27 14:26:28 +02:00
|
|
|
|
{
|
|
|
|
|
|
// everything is the same, except for the child items
|
|
|
|
|
|
// list which is a clone of the original list
|
|
|
|
|
|
|
|
|
|
|
|
Id = origin.Id;
|
|
|
|
|
|
Uid = origin.Uid;
|
|
|
|
|
|
ContentType = origin.ContentType;
|
|
|
|
|
|
Level = origin.Level;
|
|
|
|
|
|
Path = origin.Path;
|
|
|
|
|
|
SortOrder = origin.SortOrder;
|
|
|
|
|
|
ParentContentId = origin.ParentContentId;
|
|
|
|
|
|
CreateDate = origin.CreateDate;
|
|
|
|
|
|
CreatorId = origin.CreatorId;
|
|
|
|
|
|
|
|
|
|
|
|
var originDraft = origin.Draft == null ? null : PublishedContent.UnwrapIPublishedContent(origin.Draft);
|
|
|
|
|
|
var originPublished = origin.Published == null ? null : PublishedContent.UnwrapIPublishedContent(origin.Published);
|
|
|
|
|
|
|
2016-06-10 16:37:28 +02:00
|
|
|
|
Draft = originDraft == null ? null : new PublishedContent(this, originDraft).CreateModel();
|
|
|
|
|
|
Published = originPublished == null ? null : new PublishedContent(this, originPublished).CreateModel();
|
2016-05-27 14:26:28 +02:00
|
|
|
|
|
|
|
|
|
|
ChildContentIds = new List<int>(origin.ChildContentIds); // needs to be *another* list
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// clone with new content type
|
2018-04-18 19:46:47 +02:00
|
|
|
|
public ContentNode(ContentNode origin, PublishedContentType contentType, IPublishedSnapshotAccessor publishedSnapshotAccessor, IPublishedVariationContextAccessor variationContextAccessor)
|
2016-05-27 14:26:28 +02:00
|
|
|
|
{
|
|
|
|
|
|
Id = origin.Id;
|
|
|
|
|
|
Uid = origin.Uid;
|
|
|
|
|
|
ContentType = contentType; // change!
|
|
|
|
|
|
Level = origin.Level;
|
|
|
|
|
|
Path = origin.Path;
|
|
|
|
|
|
SortOrder = origin.SortOrder;
|
|
|
|
|
|
ParentContentId = origin.ParentContentId;
|
|
|
|
|
|
CreateDate = origin.CreateDate;
|
|
|
|
|
|
CreatorId = origin.CreatorId;
|
|
|
|
|
|
|
|
|
|
|
|
var originDraft = origin.Draft == null ? null : PublishedContent.UnwrapIPublishedContent(origin.Draft);
|
|
|
|
|
|
var originPublished = origin.Published == null ? null : PublishedContent.UnwrapIPublishedContent(origin.Published);
|
|
|
|
|
|
|
2018-04-18 19:46:47 +02:00
|
|
|
|
Draft = originDraft == null ? null : new PublishedContent(this, originDraft._contentData, publishedSnapshotAccessor, variationContextAccessor).CreateModel();
|
|
|
|
|
|
Published = originPublished == null ? null : new PublishedContent(this, originPublished._contentData, publishedSnapshotAccessor, variationContextAccessor).CreateModel();
|
2016-05-27 14:26:28 +02:00
|
|
|
|
|
|
|
|
|
|
ChildContentIds = origin.ChildContentIds; // can be the *same* list FIXME oh really?
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// everything that is common to both draft and published versions
|
|
|
|
|
|
// keep this as small as possible
|
|
|
|
|
|
public readonly int Id;
|
|
|
|
|
|
public readonly Guid Uid;
|
|
|
|
|
|
public PublishedContentType ContentType;
|
|
|
|
|
|
public readonly int Level;
|
|
|
|
|
|
public readonly string Path;
|
|
|
|
|
|
public readonly int SortOrder;
|
|
|
|
|
|
public readonly int ParentContentId;
|
|
|
|
|
|
public List<int> ChildContentIds;
|
|
|
|
|
|
public readonly DateTime CreateDate;
|
|
|
|
|
|
public readonly int CreatorId;
|
|
|
|
|
|
|
|
|
|
|
|
// 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
|
2016-05-27 14:26:28 +02:00
|
|
|
|
public IPublishedContent Draft;
|
|
|
|
|
|
public IPublishedContent Published;
|
|
|
|
|
|
|
2017-10-31 12:48:24 +01:00
|
|
|
|
public ContentNode CloneParent(IPublishedSnapshotAccessor publishedSnapshotAccessor)
|
2016-05-27 14:26:28 +02:00
|
|
|
|
{
|
2017-07-12 14:09:31 +02:00
|
|
|
|
return new ContentNode(this);
|
2016-05-27 14:26:28 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public ContentNodeKit ToKit()
|
|
|
|
|
|
{
|
2017-10-25 13:23:14 +02:00
|
|
|
|
var draft = Draft is PublishedContentModel draftModel
|
|
|
|
|
|
? (PublishedContent) draftModel.Unwrap()
|
|
|
|
|
|
: (PublishedContent) Draft;
|
|
|
|
|
|
|
|
|
|
|
|
var published = Published is PublishedContentModel publishedModel
|
|
|
|
|
|
? (PublishedContent) publishedModel.Unwrap()
|
|
|
|
|
|
: (PublishedContent) Published;
|
|
|
|
|
|
|
2016-05-27 14:26:28 +02:00
|
|
|
|
return new ContentNodeKit
|
|
|
|
|
|
{
|
|
|
|
|
|
Node = this,
|
|
|
|
|
|
ContentTypeId = ContentType.Id,
|
2017-07-20 11:21:28 +02:00
|
|
|
|
|
2017-10-25 13:23:14 +02:00
|
|
|
|
DraftData = draft?._contentData,
|
|
|
|
|
|
PublishedData = published?._contentData
|
2016-05-27 14:26:28 +02:00
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|