* Updates JSON schema for Umbraco 10 with latest references for Forms and Deploy (#15918) * Ported over #15928 changes for 13.3 RC (#16023) * Ported over #15928 changes for 13.3 RC * Use GetOrAdd() * Lock dictionary initialization --------- Co-authored-by: Jason Elkin <jasonelkin86@gmail.com> * Make the API content response builder extendable (#16056) * Make the API content response builder extendable * DeliveryApiJsonTypeResolver needs to be extendable too * bump rc to regular * Bump to next minor * Add blocks in RTE telemetry (#16104) * Add blocks telemetry * Use constants and update tests * V13: Add property type information to telemetry (#16109) * Add property type counts to telemetry * Use constants and fix tests * Update description * V10: Fix for fallback file upload (#14892) (#15868) * Fix for fallback file upload (#14892) * Added check for file type * Removed unneeded null checks and fixed tabs * Cleaning * Cleanups, cleanups, and removal of unneeded null checks * Reverted removal of relationshipservice * Revert null check removals (too risky) --------- Co-authored-by: Ambert van Unen <AvanUnen@ilionx.com> Co-authored-by: Laura Neto <12862535+lauraneto@users.noreply.github.com> (cherry picked from commit0b5d1f8aa6) * Fix up formatting --------- Co-authored-by: Ambert van Unen <ambertvu@gmail.com> * Implementors using Umbraco.Tests.Integration won't have to override GetLocalizedTextService (cherry picked from commitb0016687eb) (cherry picked from commit2bb56f1b81) * Fix logic for retrieving lastKnownElement (cherry picked from commitcae106bfe8) * bump version * Bump version * Bump version * Since v13 properties can sometimes be of type IRichTextEditorIntermediateValue - this was unexpected in the XPath navigator code (#16121) * Webhook log improvements (#16200) * fix: include all headers in webhook log * feat: return webhook log status from server * feat: make webhook logs deep linkable * feat: add webhook log pagination * feat: improve webhook request/response body preview * V13: Optimize custom MVC routing (#16218) * Introduce EagerMatcherPolicy to conditionally bypass content routing * Ensure that the candidate we disable dynamic routing for is valid * Skip Umbraco endpoints * Simplify logic a bit * Move install logic to matcher * Ensure that dynamic routing is still skipped when in upgrade state * Fixup comments * Reduce nesting a bit * Don't show maintenance page when statically routed controllers are hít * Remove excess check, since installer requests are statically routed * V13: Optimize custom MVC routing (#16218) * Introduce EagerMatcherPolicy to conditionally bypass content routing * Ensure that the candidate we disable dynamic routing for is valid * Skip Umbraco endpoints * Simplify logic a bit * Move install logic to matcher * Ensure that dynamic routing is still skipped when in upgrade state * Fixup comments * Reduce nesting a bit * Don't show maintenance page when statically routed controllers are hít * Remove excess check, since installer requests are statically routed (cherry picked from commitba9ddd11da) * Property source level variation should only be applied when configured (#16270) * Property source level variation should only be applied when configured (#16270) (cherry picked from commitab32bac5d9) * Merge pull request from GHSA-j74q-mv2c-rxmp * Merge pull request from GHSA-j74q-mv2c-rxmp * Merge pull request from GHSA-j74q-mv2c-rxmp * Fix up after merge * Remove obselete test --------- Co-authored-by: Andy Butland <abutland73@gmail.com> Co-authored-by: Kenn Jacobsen <kja@umbraco.dk> Co-authored-by: Jason Elkin <jasonelkin86@gmail.com> Co-authored-by: Sven Geusens <sge@umbraco.dk> Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> Co-authored-by: Ambert van Unen <ambertvu@gmail.com> Co-authored-by: Lars-Erik <lars-erik@aabech.no> Co-authored-by: Joshua Daniel Pratt Nielsen <jdpnielsen@gmail.com> Co-authored-by: Bjarke Berg <mail@bergmania.dk> Co-authored-by: Sebastiaan Janssen <sebastiaan@umbraco.com> Co-authored-by: Rasmus John Pedersen <mail@rjp.dk>
418 lines
15 KiB
C#
418 lines
15 KiB
C#
using System.Collections.Concurrent;
|
|
using System.Xml.Serialization;
|
|
using Umbraco.Cms.Core.Cache;
|
|
using Umbraco.Cms.Core.Collections;
|
|
using Umbraco.Cms.Core.Models;
|
|
using Umbraco.Cms.Core.Models.PublishedContent;
|
|
using Umbraco.Cms.Core.PropertyEditors;
|
|
using Umbraco.Cms.Core.PublishedCache;
|
|
using Umbraco.Cms.Infrastructure.PublishedCache.DataSource;
|
|
using Umbraco.Extensions;
|
|
|
|
namespace Umbraco.Cms.Infrastructure.PublishedCache;
|
|
|
|
[Serializable]
|
|
[XmlType(Namespace = "http://umbraco.org/webservices/")]
|
|
internal class Property : PublishedPropertyBase
|
|
{
|
|
private readonly PublishedContent _content;
|
|
private readonly Guid _contentUid;
|
|
private readonly bool _isMember;
|
|
private readonly bool _isPreviewing;
|
|
|
|
private readonly IPublishedSnapshotAccessor _publishedSnapshotAccessor;
|
|
|
|
// the invariant-neutral source and inter values
|
|
private readonly object? _sourceValue;
|
|
private readonly ContentVariation _variations;
|
|
private readonly ContentVariation _sourceVariations;
|
|
|
|
// the variant and non-variant object values
|
|
private CacheValues? _cacheValues;
|
|
private bool _interInitialized;
|
|
private object? _interValue;
|
|
|
|
// the variant source and inter values
|
|
private readonly object _locko = new();
|
|
private ConcurrentDictionary<CompositeStringStringKey, SourceInterValue>? _sourceValues;
|
|
|
|
private string? _valuesCacheKey;
|
|
|
|
// initializes a published content property with no value
|
|
public Property(
|
|
IPublishedPropertyType propertyType,
|
|
PublishedContent content,
|
|
IPublishedSnapshotAccessor publishedSnapshotAccessor,
|
|
PropertyCacheLevel referenceCacheLevel = PropertyCacheLevel.Element)
|
|
: this(propertyType, content, null, publishedSnapshotAccessor, referenceCacheLevel)
|
|
{
|
|
}
|
|
|
|
// initializes a published content property with a value
|
|
public Property(
|
|
IPublishedPropertyType propertyType,
|
|
PublishedContent content,
|
|
PropertyData[]? sourceValues,
|
|
IPublishedSnapshotAccessor publishedSnapshotAccessor,
|
|
PropertyCacheLevel referenceCacheLevel = PropertyCacheLevel.Element)
|
|
: base(propertyType, referenceCacheLevel)
|
|
{
|
|
if (sourceValues != null)
|
|
{
|
|
foreach (PropertyData sourceValue in sourceValues)
|
|
{
|
|
if (sourceValue.Culture == string.Empty && sourceValue.Segment == string.Empty)
|
|
{
|
|
_sourceValue = sourceValue.Value;
|
|
}
|
|
else
|
|
{
|
|
EnsureSourceValuesInitialized();
|
|
|
|
_sourceValues![new CompositeStringStringKey(sourceValue.Culture, sourceValue.Segment)]
|
|
= new SourceInterValue
|
|
{
|
|
Culture = sourceValue.Culture,
|
|
Segment = sourceValue.Segment,
|
|
SourceValue = sourceValue.Value,
|
|
};
|
|
}
|
|
}
|
|
}
|
|
|
|
_contentUid = content.Key;
|
|
_content = content;
|
|
_isPreviewing = content.IsPreviewing;
|
|
_isMember = content.ContentType.ItemType == PublishedItemType.Member;
|
|
_publishedSnapshotAccessor = publishedSnapshotAccessor;
|
|
// this variable is used for contextualizing the variation level when calculating property values.
|
|
// it must be set to the union of variance (the combination of content type and property type variance).
|
|
_variations = propertyType.Variations | content.ContentType.Variations;
|
|
_sourceVariations = propertyType.Variations;
|
|
}
|
|
|
|
// clone for previewing as draft a published content that is published and has no draft
|
|
public Property(Property origin, PublishedContent content)
|
|
: base(origin.PropertyType, origin.ReferenceCacheLevel)
|
|
{
|
|
_sourceValue = origin._sourceValue;
|
|
_sourceValues = origin._sourceValues;
|
|
|
|
_contentUid = origin._contentUid;
|
|
_content = content;
|
|
_isPreviewing = true;
|
|
_isMember = origin._isMember;
|
|
_publishedSnapshotAccessor = origin._publishedSnapshotAccessor;
|
|
_variations = origin._variations;
|
|
_sourceVariations = origin._sourceVariations;
|
|
}
|
|
|
|
// used to cache the CacheValues of this property
|
|
internal string ValuesCacheKey => _valuesCacheKey ??=
|
|
CacheKeys.PropertyCacheValues(_contentUid, Alias, _isPreviewing);
|
|
|
|
// determines whether a property has value
|
|
public override bool HasValue(string? culture = null, string? segment = null)
|
|
{
|
|
_content.VariationContextAccessor.ContextualizeVariation(_variations, _content.Id, ref culture, ref segment);
|
|
|
|
var value = GetSourceValue(culture, segment);
|
|
var hasValue = PropertyType.IsValue(value, PropertyValueLevel.Source);
|
|
if (hasValue.HasValue)
|
|
{
|
|
return hasValue.Value;
|
|
}
|
|
|
|
value = GetInterValue(culture, segment);
|
|
hasValue = PropertyType.IsValue(value, PropertyValueLevel.Inter);
|
|
if (hasValue.HasValue)
|
|
{
|
|
return hasValue.Value;
|
|
}
|
|
|
|
CacheValue cacheValues = GetCacheValues(PropertyType.CacheLevel).For(culture, segment);
|
|
|
|
// initial reference cache level always is .Content
|
|
const PropertyCacheLevel initialCacheLevel = PropertyCacheLevel.Element;
|
|
|
|
if (!cacheValues.ObjectInitialized)
|
|
{
|
|
cacheValues.ObjectValue =
|
|
PropertyType.ConvertInterToObject(_content, initialCacheLevel, value, _isPreviewing);
|
|
cacheValues.ObjectInitialized = true;
|
|
}
|
|
|
|
value = cacheValues.ObjectValue;
|
|
return PropertyType.IsValue(value, PropertyValueLevel.Object) ?? false;
|
|
}
|
|
|
|
public override object? GetSourceValue(string? culture = null, string? segment = null)
|
|
{
|
|
_content.VariationContextAccessor.ContextualizeVariation(_sourceVariations, _content.Id, ref culture, ref segment);
|
|
|
|
// source values are tightly bound to the property/schema culture and segment configurations, so we need to
|
|
// sanitize the contextualized culture/segment states before using them to access the source values.
|
|
culture = _sourceVariations.VariesByCulture() ? culture : string.Empty;
|
|
segment = _sourceVariations.VariesBySegment() ? segment : string.Empty;
|
|
|
|
if (culture == string.Empty && segment == string.Empty)
|
|
{
|
|
return _sourceValue;
|
|
}
|
|
|
|
if (_sourceValues == null)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
return _sourceValues.TryGetValue(
|
|
new CompositeStringStringKey(culture, segment),
|
|
out SourceInterValue? sourceValue)
|
|
? sourceValue.SourceValue
|
|
: null;
|
|
}
|
|
|
|
private CacheValues GetCacheValues(PropertyCacheLevel cacheLevel)
|
|
{
|
|
CacheValues cacheValues;
|
|
IPublishedSnapshot publishedSnapshot;
|
|
IAppCache? cache;
|
|
switch (cacheLevel)
|
|
{
|
|
case PropertyCacheLevel.None:
|
|
// never cache anything
|
|
cacheValues = new CacheValues();
|
|
break;
|
|
case PropertyCacheLevel.Element:
|
|
// cache within the property object itself, ie within the content object
|
|
cacheValues = _cacheValues ??= new CacheValues();
|
|
break;
|
|
case PropertyCacheLevel.Elements:
|
|
// cache within the elements cache, unless previewing, then use the snapshot or
|
|
// elements cache (if we don't want to pollute the elements cache with short-lived
|
|
// data) depending on settings
|
|
// for members, always cache in the snapshot cache - never pollute elements cache
|
|
publishedSnapshot = _publishedSnapshotAccessor.GetRequiredPublishedSnapshot();
|
|
cache = publishedSnapshot == null
|
|
? null
|
|
: (_isPreviewing == false || PublishedSnapshotService.FullCacheWhenPreviewing) && _isMember == false
|
|
? publishedSnapshot.ElementsCache
|
|
: publishedSnapshot.SnapshotCache;
|
|
cacheValues = GetCacheValues(cache);
|
|
break;
|
|
case PropertyCacheLevel.Snapshot:
|
|
// cache within the snapshot cache
|
|
publishedSnapshot = _publishedSnapshotAccessor.GetRequiredPublishedSnapshot();
|
|
cache = publishedSnapshot?.SnapshotCache;
|
|
cacheValues = GetCacheValues(cache);
|
|
break;
|
|
default:
|
|
throw new InvalidOperationException("Invalid cache level.");
|
|
}
|
|
|
|
return cacheValues;
|
|
}
|
|
|
|
private CacheValues GetCacheValues(IAppCache? cache)
|
|
{
|
|
// no cache, don't cache
|
|
if (cache == null)
|
|
{
|
|
return new CacheValues();
|
|
}
|
|
|
|
return (CacheValues)cache.Get(ValuesCacheKey, () => new CacheValues())!;
|
|
}
|
|
|
|
private object? GetInterValue(string? culture, string? segment)
|
|
{
|
|
if (culture == string.Empty && segment == string.Empty)
|
|
{
|
|
if (_interInitialized)
|
|
{
|
|
return _interValue;
|
|
}
|
|
|
|
_interValue = PropertyType.ConvertSourceToInter(_content, _sourceValue, _isPreviewing);
|
|
_interInitialized = true;
|
|
return _interValue;
|
|
}
|
|
|
|
EnsureSourceValuesInitialized();
|
|
|
|
var k = new CompositeStringStringKey(culture, segment);
|
|
|
|
SourceInterValue vvalue = _sourceValues!.GetOrAdd(k, _ =>
|
|
new SourceInterValue
|
|
{
|
|
Culture = culture,
|
|
Segment = segment,
|
|
SourceValue = GetSourceValue(culture, segment),
|
|
});
|
|
|
|
if (vvalue.InterInitialized)
|
|
{
|
|
return vvalue.InterValue;
|
|
}
|
|
|
|
vvalue.InterValue = PropertyType.ConvertSourceToInter(_content, vvalue.SourceValue, _isPreviewing);
|
|
vvalue.InterInitialized = true;
|
|
return vvalue.InterValue;
|
|
}
|
|
|
|
public override object? GetValue(string? culture = null, string? segment = null)
|
|
{
|
|
_content.VariationContextAccessor.ContextualizeVariation(_variations, _content.Id, ref culture, ref segment);
|
|
|
|
object? value;
|
|
CacheValue cacheValues = GetCacheValues(PropertyType.CacheLevel).For(culture, segment);
|
|
|
|
// initial reference cache level always is .Content
|
|
const PropertyCacheLevel initialCacheLevel = PropertyCacheLevel.Element;
|
|
|
|
if (cacheValues.ObjectInitialized)
|
|
{
|
|
return cacheValues.ObjectValue;
|
|
}
|
|
|
|
cacheValues.ObjectValue = PropertyType.ConvertInterToObject(_content, initialCacheLevel, GetInterValue(culture, segment), _isPreviewing);
|
|
cacheValues.ObjectInitialized = true;
|
|
value = cacheValues.ObjectValue;
|
|
|
|
return value;
|
|
}
|
|
|
|
public override object? GetDeliveryApiValue(bool expanding, string? culture = null, string? segment = null)
|
|
{
|
|
_content.VariationContextAccessor.ContextualizeVariation(_variations, _content.Id, ref culture, ref segment);
|
|
|
|
object? value;
|
|
CacheValue cacheValues = GetCacheValues(expanding ? PropertyType.DeliveryApiCacheLevelForExpansion : PropertyType.DeliveryApiCacheLevel).For(culture, segment);
|
|
|
|
|
|
// initial reference cache level always is .Content
|
|
const PropertyCacheLevel initialCacheLevel = PropertyCacheLevel.Element;
|
|
|
|
object? GetDeliveryApiObject() => PropertyType.ConvertInterToDeliveryApiObject(_content, initialCacheLevel, GetInterValue(culture, segment), _isPreviewing, expanding);
|
|
value = expanding
|
|
? GetDeliveryApiExpandedObject(cacheValues, GetDeliveryApiObject)
|
|
: GetDeliveryApiDefaultObject(cacheValues, GetDeliveryApiObject);
|
|
|
|
return value;
|
|
}
|
|
|
|
private object? GetDeliveryApiDefaultObject(CacheValue cacheValues, Func<object?> getValue)
|
|
{
|
|
if (cacheValues.DeliveryApiDefaultObjectInitialized == false)
|
|
{
|
|
cacheValues.DeliveryApiDefaultObjectValue = getValue();
|
|
cacheValues.DeliveryApiDefaultObjectInitialized = true;
|
|
}
|
|
|
|
return cacheValues.DeliveryApiDefaultObjectValue;
|
|
}
|
|
|
|
private object? GetDeliveryApiExpandedObject(CacheValue cacheValues, Func<object?> getValue)
|
|
{
|
|
if (cacheValues.DeliveryApiExpandedObjectInitialized == false)
|
|
{
|
|
cacheValues.DeliveryApiExpandedObjectValue = getValue();
|
|
cacheValues.DeliveryApiExpandedObjectInitialized = true;
|
|
}
|
|
|
|
return cacheValues.DeliveryApiExpandedObjectValue;
|
|
}
|
|
|
|
#region Classes
|
|
|
|
private class CacheValue
|
|
{
|
|
public bool ObjectInitialized { get; set; }
|
|
|
|
public object? ObjectValue { get; set; }
|
|
|
|
public bool XPathInitialized { get; set; }
|
|
|
|
public object? XPathValue { get; set; }
|
|
|
|
public bool DeliveryApiDefaultObjectInitialized { get; set; }
|
|
|
|
public object? DeliveryApiDefaultObjectValue { get; set; }
|
|
|
|
public bool DeliveryApiExpandedObjectInitialized { get; set; }
|
|
|
|
public object? DeliveryApiExpandedObjectValue { get; set; }
|
|
}
|
|
|
|
private class CacheValues : CacheValue
|
|
{
|
|
private readonly object _locko = new();
|
|
private ConcurrentDictionary<CompositeStringStringKey, CacheValue>? _values;
|
|
|
|
public CacheValue For(string? culture, string? segment)
|
|
{
|
|
if (culture == string.Empty && segment == string.Empty)
|
|
{
|
|
return this;
|
|
}
|
|
|
|
if (_values == null)
|
|
{
|
|
lock (_locko)
|
|
{
|
|
_values ??= InitializeConcurrentDictionary<CompositeStringStringKey, CacheValue>();
|
|
}
|
|
}
|
|
|
|
var k = new CompositeStringStringKey(culture, segment);
|
|
|
|
CacheValue value = _values.GetOrAdd(k, _ => new CacheValue());
|
|
|
|
return value;
|
|
}
|
|
}
|
|
|
|
private class SourceInterValue
|
|
{
|
|
private string? _culture;
|
|
private string? _segment;
|
|
|
|
public string? Culture
|
|
{
|
|
get => _culture;
|
|
internal set => _culture = value?.ToLowerInvariant();
|
|
}
|
|
|
|
public string? Segment
|
|
{
|
|
get => _segment;
|
|
internal set => _segment = value?.ToLowerInvariant();
|
|
}
|
|
|
|
public object? SourceValue { get; set; }
|
|
|
|
public bool InterInitialized { get; set; }
|
|
|
|
public object? InterValue { get; set; }
|
|
}
|
|
|
|
private static ConcurrentDictionary<TKey, TValue> InitializeConcurrentDictionary<TKey, TValue>()
|
|
where TKey : notnull
|
|
=> new(-1, 5);
|
|
|
|
private void EnsureSourceValuesInitialized()
|
|
{
|
|
if (_sourceValues is not null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
lock (_locko)
|
|
{
|
|
_sourceValues ??= InitializeConcurrentDictionary<CompositeStringStringKey, SourceInterValue>();
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
}
|