Workaround for failing entity tree children (#15887)
* Workaround for failing entity tree children * Fix typo from original PR * Expose and actually use GetPagedTrashedChildren on EntityService (the default implementation on the interface is currently used). * Ensure that ID/Key mapping for recycle bins work
This commit is contained in:
@@ -27,7 +27,7 @@ public class DocumentRecycleBinControllerBase : RecycleBinControllerBase<Documen
|
||||
|
||||
protected override UmbracoObjectTypes ItemObjectType => UmbracoObjectTypes.Document;
|
||||
|
||||
protected override Guid RecycleBindRootKey => Constants.System.RecycleBinContentKey;
|
||||
protected override Guid RecycleBinRootKey => Constants.System.RecycleBinContentKey;
|
||||
|
||||
protected override DocumentRecycleBinItemResponseModel MapRecycleBinViewModel(Guid? parentId, IEntitySlim entity)
|
||||
{
|
||||
|
||||
@@ -27,7 +27,7 @@ public class MediaRecycleBinControllerBase : RecycleBinControllerBase<MediaRecyc
|
||||
|
||||
protected override UmbracoObjectTypes ItemObjectType => UmbracoObjectTypes.Media;
|
||||
|
||||
protected override Guid RecycleBindRootKey => Constants.System.RecycleBinMediaKey;
|
||||
protected override Guid RecycleBinRootKey => Constants.System.RecycleBinMediaKey;
|
||||
|
||||
protected override MediaRecycleBinItemResponseModel MapRecycleBinViewModel(Guid? parentKey, IEntitySlim entity)
|
||||
{
|
||||
|
||||
@@ -26,7 +26,7 @@ public abstract class RecycleBinControllerBase<TItem> : ContentControllerBase
|
||||
|
||||
protected abstract UmbracoObjectTypes ItemObjectType { get; }
|
||||
|
||||
protected abstract Guid RecycleBindRootKey { get; }
|
||||
protected abstract Guid RecycleBinRootKey { get; }
|
||||
|
||||
protected async Task<ActionResult<PagedViewModel<TItem>>> GetRoot(int skip, int take)
|
||||
{
|
||||
@@ -112,7 +112,7 @@ public abstract class RecycleBinControllerBase<TItem> : ContentControllerBase
|
||||
private IEntitySlim[] GetPagedRootEntities(int skip, int take, out long totalItems)
|
||||
{
|
||||
IEntitySlim[] rootEntities = _entityService
|
||||
.GetPagedTrashedChildren(RecycleBindRootKey, ItemObjectType, skip, take, out totalItems)
|
||||
.GetPagedTrashedChildren(RecycleBinRootKey, ItemObjectType, skip, take, out totalItems)
|
||||
.ToArray();
|
||||
|
||||
return rootEntities;
|
||||
|
||||
@@ -69,6 +69,7 @@ public abstract class FolderTreeControllerBase<TItem> : NamedEntityTreeControlle
|
||||
? Array.Empty<IEntitySlim>()
|
||||
: EntityService.GetPagedChildren(
|
||||
parentKey,
|
||||
new [] { FolderObjectType, ItemObjectType },
|
||||
ItemObjectType,
|
||||
skip,
|
||||
take,
|
||||
|
||||
@@ -359,8 +359,27 @@ public class EntityService : RepositoryService, IEntityService
|
||||
=> GetPagedChildren(id, objectType, pageIndex, pageSize, false, filter, ordering, out totalRecords);
|
||||
|
||||
public IEnumerable<IEntitySlim> GetPagedChildren(
|
||||
Guid? key,
|
||||
UmbracoObjectTypes objectType,
|
||||
Guid? parentKey,
|
||||
UmbracoObjectTypes childObjectType,
|
||||
int skip,
|
||||
int take,
|
||||
out long totalRecords,
|
||||
IQuery<IUmbracoEntity>? filter = null,
|
||||
Ordering? ordering = null)
|
||||
=> GetPagedChildren(
|
||||
parentKey,
|
||||
new[] { childObjectType },
|
||||
childObjectType,
|
||||
skip,
|
||||
take,
|
||||
out totalRecords,
|
||||
filter,
|
||||
ordering);
|
||||
|
||||
public IEnumerable<IEntitySlim> GetPagedChildren(
|
||||
Guid? parentKey,
|
||||
IEnumerable<UmbracoObjectTypes> parentObjectTypes,
|
||||
UmbracoObjectTypes childObjectType,
|
||||
int skip,
|
||||
int take,
|
||||
out long totalRecords,
|
||||
@@ -369,7 +388,9 @@ public class EntityService : RepositoryService, IEntityService
|
||||
{
|
||||
using ICoreScope scope = ScopeProvider.CreateCoreScope();
|
||||
|
||||
if (ResolveKey(key, objectType, out int parentId) is false)
|
||||
var parentId = 0;
|
||||
var parentIdResolved = parentObjectTypes.Any(parentObjectType => ResolveKey(parentKey, parentObjectType, out parentId));
|
||||
if (parentIdResolved is false)
|
||||
{
|
||||
totalRecords = 0;
|
||||
return Enumerable.Empty<IEntitySlim>();
|
||||
@@ -379,7 +400,7 @@ public class EntityService : RepositoryService, IEntityService
|
||||
|
||||
IEnumerable<IEntitySlim> children = GetPagedChildren(
|
||||
parentId,
|
||||
objectType,
|
||||
childObjectType,
|
||||
pageNumber,
|
||||
pageSize,
|
||||
out totalRecords,
|
||||
@@ -401,7 +422,7 @@ public class EntityService : RepositoryService, IEntityService
|
||||
Ordering? ordering = null)
|
||||
=> GetPagedChildren(id, objectType, pageIndex, pageSize, true, filter, ordering, out totalRecords);
|
||||
|
||||
IEnumerable<IEntitySlim> GetPagedTrashedChildren(
|
||||
public IEnumerable<IEntitySlim> GetPagedTrashedChildren(
|
||||
Guid? key,
|
||||
UmbracoObjectTypes objectType,
|
||||
int skip,
|
||||
|
||||
@@ -202,8 +202,27 @@ public interface IEntityService
|
||||
IEnumerable<IEntitySlim> GetDescendants(int id, UmbracoObjectTypes objectType);
|
||||
|
||||
IEnumerable<IEntitySlim> GetPagedChildren(
|
||||
Guid? key,
|
||||
UmbracoObjectTypes objectType,
|
||||
Guid? parentKey,
|
||||
UmbracoObjectTypes childObjectType,
|
||||
int skip,
|
||||
int take,
|
||||
out long totalRecords,
|
||||
IQuery<IUmbracoEntity>? filter = null,
|
||||
Ordering? ordering = null)
|
||||
=> GetPagedChildren(
|
||||
parentKey,
|
||||
new[] { childObjectType },
|
||||
childObjectType,
|
||||
skip,
|
||||
take,
|
||||
out totalRecords,
|
||||
filter,
|
||||
ordering);
|
||||
|
||||
IEnumerable<IEntitySlim> GetPagedChildren(
|
||||
Guid? parentKey,
|
||||
IEnumerable<UmbracoObjectTypes> parentObjectTypes,
|
||||
UmbracoObjectTypes childObjectType,
|
||||
int skip,
|
||||
int take,
|
||||
out long totalRecords,
|
||||
|
||||
@@ -115,6 +115,16 @@ public class IdKeyMap : IIdKeyMap, IDisposable
|
||||
|
||||
public Attempt<int> GetIdForKey(Guid key, UmbracoObjectTypes umbracoObjectType)
|
||||
{
|
||||
if (key == Constants.System.RecycleBinContentKey && umbracoObjectType == UmbracoObjectTypes.Document)
|
||||
{
|
||||
return Attempt.Succeed(Constants.System.RecycleBinContent);
|
||||
}
|
||||
|
||||
if (key == Constants.System.RecycleBinMediaKey && umbracoObjectType == UmbracoObjectTypes.Media)
|
||||
{
|
||||
return Attempt.Succeed(Constants.System.RecycleBinMedia);
|
||||
}
|
||||
|
||||
bool empty;
|
||||
|
||||
try
|
||||
@@ -232,6 +242,16 @@ public class IdKeyMap : IIdKeyMap, IDisposable
|
||||
|
||||
public Attempt<Guid> GetKeyForId(int id, UmbracoObjectTypes umbracoObjectType)
|
||||
{
|
||||
if (id == Constants.System.RecycleBinContent && umbracoObjectType == UmbracoObjectTypes.Document)
|
||||
{
|
||||
return Attempt.Succeed(Constants.System.RecycleBinContentKey);
|
||||
}
|
||||
|
||||
if (id == Constants.System.RecycleBinMedia && umbracoObjectType == UmbracoObjectTypes.Media)
|
||||
{
|
||||
return Attempt.Succeed(Constants.System.RecycleBinMediaKey);
|
||||
}
|
||||
|
||||
bool empty;
|
||||
|
||||
try
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Cms.Core;
|
||||
using Umbraco.Cms.Core.Models;
|
||||
using Umbraco.Cms.Core.Persistence.Repositories;
|
||||
using Umbraco.Cms.Core.Scoping;
|
||||
using Umbraco.Cms.Core.Services;
|
||||
|
||||
namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Core.Services;
|
||||
|
||||
[TestFixture]
|
||||
public class IdKeyMapTests
|
||||
{
|
||||
private IdKeyMap GetSubject()
|
||||
=> new IdKeyMap(Mock.Of<ICoreScopeProvider>(), Mock.Of<IIdKeyMapRepository>());
|
||||
|
||||
[Test]
|
||||
public void CanResolveContentRecycleBinIdFromKey()
|
||||
{
|
||||
var result = GetSubject().GetIdForKey(Constants.System.RecycleBinContentKey, UmbracoObjectTypes.Document);
|
||||
Assert.IsTrue(result.Success);
|
||||
Assert.AreEqual(Constants.System.RecycleBinContent, result.Result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CanResolveMediaRecycleBinIdFromKey()
|
||||
{
|
||||
var result = GetSubject().GetIdForKey(Constants.System.RecycleBinMediaKey, UmbracoObjectTypes.Media);
|
||||
Assert.IsTrue(result.Success);
|
||||
Assert.AreEqual(Constants.System.RecycleBinMedia, result.Result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CanResolveContentRecycleBinKeyFromId()
|
||||
{
|
||||
var result = GetSubject().GetKeyForId(Constants.System.RecycleBinContent, UmbracoObjectTypes.Document);
|
||||
Assert.IsTrue(result.Success);
|
||||
Assert.AreEqual(Constants.System.RecycleBinContentKey, result.Result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CanResolveMediaRecycleBinKeyFromId()
|
||||
{
|
||||
var result = GetSubject().GetKeyForId(Constants.System.RecycleBinMedia, UmbracoObjectTypes.Media);
|
||||
Assert.IsTrue(result.Success);
|
||||
Assert.AreEqual(Constants.System.RecycleBinMediaKey, result.Result);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user