Merge pull request #5246 from umbraco/v8/bugfix/5216-cache-getbyudi
Add GetById(Udi) to published caches
This commit is contained in:
@@ -381,6 +381,9 @@ namespace Umbraco.Tests.LegacyXmlPublishedCache
|
||||
}
|
||||
}
|
||||
|
||||
public override IPublishedContent GetById(bool preview, Udi nodeId)
|
||||
=> throw new NotSupportedException();
|
||||
|
||||
public override bool HasById(bool preview, int contentId)
|
||||
{
|
||||
return GetXml(preview).CreateNavigator().MoveToId(contentId.ToString(CultureInfo.InvariantCulture));
|
||||
|
||||
@@ -97,6 +97,9 @@ namespace Umbraco.Tests.LegacyXmlPublishedCache
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override IPublishedContent GetById(bool preview, Udi nodeId)
|
||||
=> throw new NotSupportedException();
|
||||
|
||||
public override bool HasById(bool preview, int contentId)
|
||||
{
|
||||
return GetUmbracoMedia(contentId) != null;
|
||||
|
||||
@@ -92,6 +92,9 @@ namespace Umbraco.Tests.PublishedContent
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override IPublishedContent GetById(bool preview, Udi nodeId)
|
||||
=> throw new NotSupportedException();
|
||||
|
||||
public override bool HasById(bool preview, int contentId)
|
||||
{
|
||||
return _content.ContainsKey(contentId);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Xml.XPath;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Models.PublishedContent;
|
||||
using Umbraco.Core.Xml;
|
||||
|
||||
@@ -29,6 +30,15 @@ namespace Umbraco.Web.PublishedCache
|
||||
/// <remarks>The value of <paramref name="preview"/> overrides defaults.</remarks>
|
||||
IPublishedContent GetById(bool preview, Guid contentId);
|
||||
|
||||
/// <summary>
|
||||
/// Gets a content identified by its Udi identifier.
|
||||
/// </summary>
|
||||
/// <param name="preview">A value indicating whether to consider unpublished content.</param>
|
||||
/// <param name="contentId">The content Udi identifier.</param>
|
||||
/// <returns>The content, or null.</returns>
|
||||
/// <remarks>The value of <paramref name="preview"/> overrides defaults.</remarks>
|
||||
IPublishedContent GetById(bool preview, Udi contentId);
|
||||
|
||||
/// <summary>
|
||||
/// Gets a content identified by its unique identifier.
|
||||
/// </summary>
|
||||
@@ -45,6 +55,14 @@ namespace Umbraco.Web.PublishedCache
|
||||
/// <remarks>Considers published or unpublished content depending on defaults.</remarks>
|
||||
IPublishedContent GetById(Guid contentId);
|
||||
|
||||
/// <summary>
|
||||
/// Gets a content identified by its unique identifier.
|
||||
/// </summary>
|
||||
/// <param name="contentId">The content unique identifier.</param>
|
||||
/// <returns>The content, or null.</returns>
|
||||
/// <remarks>Considers published or unpublished content depending on defaults.</remarks>
|
||||
IPublishedContent GetById(Udi contentId);
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the cache contains a specified content.
|
||||
/// </summary>
|
||||
|
||||
@@ -238,6 +238,18 @@ namespace Umbraco.Web.PublishedCache.NuCache
|
||||
return GetNodePublishedContent(node, preview);
|
||||
}
|
||||
|
||||
public override IPublishedContent GetById(bool preview, Udi contentId)
|
||||
{
|
||||
var guidUdi = contentId as GuidUdi;
|
||||
if (guidUdi == null)
|
||||
throw new ArgumentException($"Udi must be of type {typeof(GuidUdi).Name}.", nameof(contentId));
|
||||
|
||||
if (guidUdi.EntityType != Constants.UdiEntityType.Document)
|
||||
throw new ArgumentException($"Udi entity type must be \"{Constants.UdiEntityType.Document}\".", nameof(contentId));
|
||||
|
||||
return GetById(preview, guidUdi.Guid);
|
||||
}
|
||||
|
||||
public override bool HasById(bool preview, int contentId)
|
||||
{
|
||||
var n = _snapshot.Get(contentId);
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Xml.XPath;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Cache;
|
||||
using Umbraco.Core.Models.PublishedContent;
|
||||
using Umbraco.Core.Xml;
|
||||
@@ -44,6 +45,20 @@ namespace Umbraco.Web.PublishedCache.NuCache
|
||||
return n?.PublishedModel;
|
||||
}
|
||||
|
||||
public override IPublishedContent GetById(bool preview, Udi contentId)
|
||||
{
|
||||
var guidUdi = contentId as GuidUdi;
|
||||
if (guidUdi == null)
|
||||
throw new ArgumentException($"Udi must be of type {typeof(GuidUdi).Name}.", nameof(contentId));
|
||||
|
||||
if (guidUdi.EntityType != Constants.UdiEntityType.Media)
|
||||
throw new ArgumentException($"Udi entity type must be \"{Constants.UdiEntityType.Media}\".", nameof(contentId));
|
||||
|
||||
// ignore preview, there's only draft for media
|
||||
var n = _snapshot.Get(guidUdi.Guid);
|
||||
return n?.PublishedModel;
|
||||
}
|
||||
|
||||
public override bool HasById(bool preview, int contentId)
|
||||
{
|
||||
var n = _snapshot.Get(contentId);
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Xml.XPath;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Models.PublishedContent;
|
||||
using Umbraco.Core.Xml;
|
||||
|
||||
@@ -19,23 +20,22 @@ namespace Umbraco.Web.PublishedCache
|
||||
public abstract IPublishedContent GetById(bool preview, int contentId);
|
||||
|
||||
public IPublishedContent GetById(int contentId)
|
||||
{
|
||||
return GetById(PreviewDefault, contentId);
|
||||
}
|
||||
=> GetById(PreviewDefault, contentId);
|
||||
|
||||
public abstract IPublishedContent GetById(bool preview, Guid contentId);
|
||||
|
||||
public IPublishedContent GetById(Guid contentId)
|
||||
{
|
||||
return GetById(PreviewDefault, contentId);
|
||||
}
|
||||
=> GetById(PreviewDefault, contentId);
|
||||
|
||||
public abstract IPublishedContent GetById(bool preview, Udi contentId);
|
||||
|
||||
public IPublishedContent GetById(Udi contentId)
|
||||
=> GetById(PreviewDefault, contentId);
|
||||
|
||||
public abstract bool HasById(bool preview, int contentId);
|
||||
|
||||
public bool HasById(int contentId)
|
||||
{
|
||||
return HasById(PreviewDefault, contentId);
|
||||
}
|
||||
=> HasById(PreviewDefault, contentId);
|
||||
|
||||
public abstract IEnumerable<IPublishedContent> GetAtRoot(bool preview);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user