2020-12-10 18:09:32 +11:00
|
|
|
using System.Collections.Generic;
|
2016-05-26 19:20:33 +02:00
|
|
|
using System.Linq;
|
2020-12-21 17:41:12 +11:00
|
|
|
using System.Threading.Tasks;
|
2020-09-21 15:11:40 +02:00
|
|
|
using Microsoft.Extensions.Logging;
|
2021-02-09 10:22:42 +01:00
|
|
|
using Umbraco.Cms.Core.Cache;
|
|
|
|
|
using Umbraco.Cms.Core.Configuration.Models;
|
|
|
|
|
using Umbraco.Cms.Core.Hosting;
|
|
|
|
|
using Umbraco.Cms.Core.Models;
|
|
|
|
|
using Umbraco.Cms.Core.Models.PublishedContent;
|
2021-02-12 13:36:50 +01:00
|
|
|
using Umbraco.Cms.Core.Persistence.Repositories;
|
2021-02-09 10:22:42 +01:00
|
|
|
using Umbraco.Cms.Core.PublishedCache;
|
|
|
|
|
using Umbraco.Cms.Core.Runtime;
|
2021-02-15 11:41:12 +01:00
|
|
|
using Umbraco.Cms.Core.Scoping;
|
2021-02-09 10:22:42 +01:00
|
|
|
using Umbraco.Cms.Core.Services;
|
|
|
|
|
using Umbraco.Cms.Core.Strings;
|
|
|
|
|
using Umbraco.Cms.Core.Web;
|
2016-05-26 17:12:04 +02:00
|
|
|
|
2019-01-30 17:50:13 +11:00
|
|
|
namespace Umbraco.Tests.LegacyXmlPublishedCache
|
2016-05-26 17:12:04 +02:00
|
|
|
{
|
|
|
|
|
/// <summary>
|
2017-10-31 12:48:24 +01:00
|
|
|
/// Implements a published snapshot service.
|
2016-05-26 17:12:04 +02:00
|
|
|
/// </summary>
|
2020-12-21 17:04:29 +11:00
|
|
|
internal class XmlPublishedSnapshotService : IPublishedSnapshotService
|
2016-05-26 17:12:04 +02:00
|
|
|
{
|
|
|
|
|
private readonly XmlStore _xmlStore;
|
|
|
|
|
private readonly RoutesCache _routesCache;
|
2018-02-09 14:34:28 +01:00
|
|
|
private readonly IPublishedContentTypeFactory _publishedContentTypeFactory;
|
2016-05-26 17:12:04 +02:00
|
|
|
private readonly PublishedContentTypeCache _contentTypeCache;
|
|
|
|
|
private readonly IDomainService _domainService;
|
|
|
|
|
private readonly IMediaService _mediaService;
|
2016-07-20 12:44:15 +02:00
|
|
|
private readonly IUserService _userService;
|
2019-01-17 11:01:23 +01:00
|
|
|
private readonly IAppCache _requestCache;
|
2020-09-08 13:03:43 +02:00
|
|
|
private readonly GlobalSettings _globalSettings;
|
2018-04-30 21:29:49 +02:00
|
|
|
private readonly IDefaultCultureAccessor _defaultCultureAccessor;
|
2019-01-10 12:44:57 +11:00
|
|
|
private readonly IEntityXmlSerializer _entitySerializer;
|
2019-12-19 10:43:00 +01:00
|
|
|
private readonly IVariationContextAccessor _variationContextAccessor;
|
2019-01-23 14:16:42 +01:00
|
|
|
private readonly IUmbracoContextAccessor _umbracoContextAccessor;
|
2016-05-26 17:12:04 +02:00
|
|
|
|
|
|
|
|
#region Constructors
|
|
|
|
|
|
2016-05-26 19:20:33 +02:00
|
|
|
// used in WebBootManager + tests
|
2020-12-21 17:04:29 +11:00
|
|
|
public XmlPublishedSnapshotService(
|
|
|
|
|
ServiceContext serviceContext,
|
2017-10-17 17:43:15 +02:00
|
|
|
IPublishedContentTypeFactory publishedContentTypeFactory,
|
2017-05-30 19:41:37 +02:00
|
|
|
IScopeProvider scopeProvider,
|
2019-01-17 11:01:23 +01:00
|
|
|
IAppCache requestCache,
|
2020-12-21 17:04:29 +11:00
|
|
|
IPublishedSnapshotAccessor publishedSnapshotAccessor,
|
|
|
|
|
IVariationContextAccessor variationContextAccessor,
|
2019-01-23 14:16:42 +01:00
|
|
|
IUmbracoContextAccessor umbracoContextAccessor,
|
2020-12-21 17:04:29 +11:00
|
|
|
IDocumentRepository documentRepository,
|
|
|
|
|
IMediaRepository mediaRepository,
|
|
|
|
|
IMemberRepository memberRepository,
|
2018-04-30 21:29:49 +02:00
|
|
|
IDefaultCultureAccessor defaultCultureAccessor,
|
2020-09-21 15:11:40 +02:00
|
|
|
ILoggerFactory loggerFactory,
|
2020-09-08 13:03:43 +02:00
|
|
|
GlobalSettings globalSettings,
|
2019-11-20 13:38:41 +01:00
|
|
|
IHostingEnvironment hostingEnvironment,
|
2020-03-26 15:39:20 +11:00
|
|
|
IApplicationShutdownRegistry hostingLifetime,
|
2019-12-18 18:55:00 +01:00
|
|
|
IShortStringHelper shortStringHelper,
|
2019-01-10 12:44:57 +11:00
|
|
|
IEntityXmlSerializer entitySerializer,
|
2016-09-01 19:06:08 +02:00
|
|
|
MainDom mainDom,
|
2020-12-21 17:04:29 +11:00
|
|
|
bool testing = false,
|
|
|
|
|
bool enableRepositoryEvents = true)
|
2019-01-23 14:16:42 +01:00
|
|
|
: this(serviceContext, publishedContentTypeFactory, scopeProvider, requestCache,
|
|
|
|
|
publishedSnapshotAccessor, variationContextAccessor, umbracoContextAccessor,
|
2017-12-14 17:04:44 +01:00
|
|
|
documentRepository, mediaRepository, memberRepository,
|
2018-04-30 21:29:49 +02:00
|
|
|
defaultCultureAccessor,
|
2021-04-22 20:25:25 +10:00
|
|
|
loggerFactory, globalSettings, hostingEnvironment, hostingLifetime, shortStringHelper, entitySerializer, null, mainDom, testing, enableRepositoryEvents)
|
2019-01-23 14:16:42 +01:00
|
|
|
{
|
|
|
|
|
_umbracoContextAccessor = umbracoContextAccessor;
|
|
|
|
|
}
|
2016-05-26 17:12:04 +02:00
|
|
|
|
2016-05-26 19:20:33 +02:00
|
|
|
// used in some tests
|
2020-12-21 17:04:29 +11:00
|
|
|
internal XmlPublishedSnapshotService(
|
|
|
|
|
ServiceContext serviceContext,
|
2017-10-17 17:43:15 +02:00
|
|
|
IPublishedContentTypeFactory publishedContentTypeFactory,
|
2017-05-30 19:41:37 +02:00
|
|
|
IScopeProvider scopeProvider,
|
2019-01-17 11:01:23 +01:00
|
|
|
IAppCache requestCache,
|
2020-12-21 17:04:29 +11:00
|
|
|
IPublishedSnapshotAccessor publishedSnapshotAccessor,
|
|
|
|
|
IVariationContextAccessor variationContextAccessor,
|
2019-01-23 14:16:42 +01:00
|
|
|
IUmbracoContextAccessor umbracoContextAccessor,
|
2020-12-21 17:04:29 +11:00
|
|
|
IDocumentRepository documentRepository,
|
|
|
|
|
IMediaRepository mediaRepository,
|
|
|
|
|
IMemberRepository memberRepository,
|
2018-04-30 21:29:49 +02:00
|
|
|
IDefaultCultureAccessor defaultCultureAccessor,
|
2020-09-21 15:11:40 +02:00
|
|
|
ILoggerFactory loggerFactory,
|
2020-09-08 13:03:43 +02:00
|
|
|
GlobalSettings globalSettings,
|
2019-11-20 13:38:41 +01:00
|
|
|
IHostingEnvironment hostingEnvironment,
|
2020-03-26 15:39:20 +11:00
|
|
|
IApplicationShutdownRegistry hostingLifetime,
|
2019-12-18 18:55:00 +01:00
|
|
|
IShortStringHelper shortStringHelper,
|
2019-01-10 12:44:57 +11:00
|
|
|
IEntityXmlSerializer entitySerializer,
|
2017-07-20 11:21:28 +02:00
|
|
|
PublishedContentTypeCache contentTypeCache,
|
2016-09-01 19:06:08 +02:00
|
|
|
MainDom mainDom,
|
2020-12-21 17:04:29 +11:00
|
|
|
bool testing,
|
|
|
|
|
bool enableRepositoryEvents)
|
2016-05-26 17:12:04 +02:00
|
|
|
{
|
|
|
|
|
_routesCache = new RoutesCache();
|
2018-02-09 14:34:28 +01:00
|
|
|
_publishedContentTypeFactory = publishedContentTypeFactory;
|
2016-05-26 17:12:04 +02:00
|
|
|
_contentTypeCache = contentTypeCache
|
2020-09-21 15:11:40 +02:00
|
|
|
?? new PublishedContentTypeCache(serviceContext.ContentTypeService, serviceContext.MediaTypeService, serviceContext.MemberTypeService, publishedContentTypeFactory, loggerFactory.CreateLogger<PublishedContentTypeCache>());
|
2016-05-26 17:12:04 +02:00
|
|
|
|
2019-01-10 12:44:57 +11:00
|
|
|
_xmlStore = new XmlStore(serviceContext.ContentTypeService, serviceContext.ContentService, scopeProvider, _routesCache,
|
|
|
|
|
_contentTypeCache, publishedSnapshotAccessor, mainDom, testing, enableRepositoryEvents,
|
2020-03-25 15:06:22 +11:00
|
|
|
documentRepository, mediaRepository, memberRepository, entitySerializer, hostingEnvironment, hostingLifetime, shortStringHelper);
|
2016-05-26 17:12:04 +02:00
|
|
|
|
|
|
|
|
_domainService = serviceContext.DomainService;
|
|
|
|
|
_mediaService = serviceContext.MediaService;
|
2016-07-20 12:44:15 +02:00
|
|
|
_userService = serviceContext.UserService;
|
2018-04-30 21:29:49 +02:00
|
|
|
_defaultCultureAccessor = defaultCultureAccessor;
|
2019-12-19 10:43:00 +01:00
|
|
|
_variationContextAccessor = variationContextAccessor;
|
2016-05-26 17:12:04 +02:00
|
|
|
_requestCache = requestCache;
|
2019-01-23 14:16:42 +01:00
|
|
|
_umbracoContextAccessor = umbracoContextAccessor;
|
2018-04-06 13:51:54 +10:00
|
|
|
_globalSettings = globalSettings;
|
2019-01-10 12:44:57 +11:00
|
|
|
_entitySerializer = entitySerializer;
|
2016-05-26 17:12:04 +02:00
|
|
|
}
|
|
|
|
|
|
2020-12-21 17:04:29 +11:00
|
|
|
public void Dispose()
|
2016-05-26 17:12:04 +02:00
|
|
|
{
|
|
|
|
|
_xmlStore.Dispose();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
2020-12-21 17:04:29 +11:00
|
|
|
public IPublishedSnapshot CreatePublishedSnapshot(string previewToken)
|
2016-05-26 17:12:04 +02:00
|
|
|
{
|
|
|
|
|
// use _requestCache to store recursive properties lookup, etc. both in content
|
|
|
|
|
// and media cache. Life span should be the current request. Or, ideally
|
|
|
|
|
// the current caches, but that would mean creating an extra cache (StaticCache
|
|
|
|
|
// probably) so better use RequestCache.
|
|
|
|
|
|
2018-04-30 21:29:49 +02:00
|
|
|
var domainCache = new DomainCache(_domainService, _defaultCultureAccessor);
|
2016-05-26 17:12:04 +02:00
|
|
|
|
2018-04-27 11:38:50 +10:00
|
|
|
return new PublishedSnapshot(
|
2020-12-10 18:09:32 +11:00
|
|
|
new PublishedContentCache(_xmlStore, domainCache, _requestCache, _globalSettings, _contentTypeCache, _routesCache, _variationContextAccessor, previewToken),
|
2019-12-19 10:43:00 +01:00
|
|
|
new PublishedMediaCache(_xmlStore, _mediaService, _userService, _requestCache, _contentTypeCache, _entitySerializer, _umbracoContextAccessor, _variationContextAccessor),
|
Published members cleanup (#10159)
* Getting new netcore PublicAccessChecker in place
* Adds full test coverage for PublicAccessChecker
* remove PublicAccessComposer
* adjust namespaces, ensure RoleManager works, separate public access controller, reduce content controller
* Implements the required methods on IMemberManager, removes old migrated code
* Updates routing to be able to re-route, Fixes middleware ordering ensuring endpoints are last, refactors pipeline options, adds public access middleware, ensures public access follows all hops
* adds note
* adds note
* Cleans up ext methods, ensures that members identity is added on both front-end and back ends. updates how UmbracoApplicationBuilder works in that it explicitly starts endpoints at the time of calling.
* Changes name to IUmbracoEndpointBuilder
* adds note
* Fixing tests, fixing error describers so there's 2x one for back office, one for members, fixes TryConvertTo, fixes login redirect
* fixing build
* Updates user manager to correctly validate password hashing and injects the IBackOfficeUserPasswordChecker
* Merges PR
* Fixes up build and notes
* Implements security stamp and email confirmed for members, cleans up a bunch of repo/service level member groups stuff, shares user store code between members and users and fixes the user identity object so we arent' tracking both groups and roles.
* Security stamp for members is now working
* Fixes keepalive, fixes PublicAccessMiddleware to not throw, updates startup code to be more clear and removes magic that registers middleware.
* adds note
* removes unused filter, fixes build
* fixes WebPath and tests
* Looks up entities in one query
* remove usings
* Fix test, remove stylesheet
* Set status code before we write to response to avoid error
* Ensures that users and members are validated when logging in. Shares more code between users and members.
* merge changes
* oops
* Reducing and removing published member cache
* Fixes RepositoryCacheKeys to ensure the keys are normalized
* oops didn't mean to commit this
* Fix casing issues with caching, stop boxing value types for all cache operations, stop re-creating string keys in DefaultRepositoryCachePolicy
* oops didn't mean to comit this
* bah, far out this keeps getting recommitted. sorry
* cannot inject IPublishedMemberCache and cannot have IPublishedMember
* splits out files, fixes build
* fix tests
* removes membership provider classes
* removes membership provider classes
* updates the identity map definition
* reverts commented out lines
* reverts commented out lines
Co-authored-by: Bjarke Berg <mail@bergmania.dk>
2021-04-22 21:21:43 +10:00
|
|
|
new PublishedMemberCache(_contentTypeCache, _variationContextAccessor),
|
2016-05-26 17:12:04 +02:00
|
|
|
domainCache);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#region Xml specific
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the underlying XML store.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public XmlStore XmlStore => _xmlStore;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the underlying RoutesCache.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public RoutesCache RoutesCache => _routesCache;
|
|
|
|
|
|
|
|
|
|
public bool VerifyContentAndPreviewXml()
|
|
|
|
|
{
|
|
|
|
|
return XmlStore.VerifyContentAndPreviewXml();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void RebuildContentAndPreviewXml()
|
|
|
|
|
{
|
|
|
|
|
XmlStore.RebuildContentAndPreviewXml();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool VerifyMediaXml()
|
|
|
|
|
{
|
|
|
|
|
return XmlStore.VerifyMediaXml();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void RebuildMediaXml()
|
|
|
|
|
{
|
|
|
|
|
XmlStore.RebuildMediaXml();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool VerifyMemberXml()
|
|
|
|
|
{
|
|
|
|
|
return XmlStore.VerifyMemberXml();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void RebuildMemberXml()
|
|
|
|
|
{
|
|
|
|
|
XmlStore.RebuildMemberXml();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Change management
|
|
|
|
|
|
2020-12-21 17:04:29 +11:00
|
|
|
public void Notify(ContentCacheRefresher.JsonPayload[] payloads, out bool draftChanged, out bool publishedChanged)
|
2016-05-26 17:12:04 +02:00
|
|
|
{
|
|
|
|
|
_xmlStore.Notify(payloads, out draftChanged, out publishedChanged);
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-21 17:04:29 +11:00
|
|
|
public void Notify(MediaCacheRefresher.JsonPayload[] payloads, out bool anythingChanged)
|
2016-05-26 17:12:04 +02:00
|
|
|
{
|
|
|
|
|
foreach (var payload in payloads)
|
|
|
|
|
PublishedMediaCache.ClearCache(payload.Id);
|
|
|
|
|
|
|
|
|
|
anythingChanged = true;
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-21 17:04:29 +11:00
|
|
|
public void Notify(ContentTypeCacheRefresher.JsonPayload[] payloads)
|
2016-05-26 17:12:04 +02:00
|
|
|
{
|
|
|
|
|
_xmlStore.Notify(payloads);
|
|
|
|
|
if (payloads.Any(x => x.ItemType == typeof(IContentType).Name))
|
|
|
|
|
_routesCache.Clear();
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-21 17:04:29 +11:00
|
|
|
public void Notify(DataTypeCacheRefresher.JsonPayload[] payloads)
|
2016-05-26 17:12:04 +02:00
|
|
|
{
|
2018-02-09 14:34:28 +01:00
|
|
|
_publishedContentTypeFactory.NotifyDataTypeChanges(payloads.Select(x => x.Id).ToArray());
|
2016-05-26 17:12:04 +02:00
|
|
|
_xmlStore.Notify(payloads);
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-21 17:04:29 +11:00
|
|
|
public void Notify(DomainCacheRefresher.JsonPayload[] payloads)
|
2016-05-26 17:12:04 +02:00
|
|
|
{
|
|
|
|
|
_routesCache.Clear();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
2020-01-30 20:05:16 +01:00
|
|
|
|
2020-12-21 17:04:29 +11:00
|
|
|
public void Rebuild(int groupSize = 5000, IReadOnlyCollection<int> contentTypeIds = null, IReadOnlyCollection<int> mediaTypeIds = null, IReadOnlyCollection<int> memberTypeIds = null) { }
|
|
|
|
|
|
2020-12-21 17:41:12 +11:00
|
|
|
public Task CollectAsync() => Task.CompletedTask;
|
2016-05-26 17:12:04 +02:00
|
|
|
}
|
|
|
|
|
}
|