refactor(core): clean up remaining internal methods in ContentService
Remove or simplify internal helper methods that are no longer needed after service extraction. Removed methods: - GetAllPublished(): Was only used in tests, replaced with public query methods - QueryNotTrashed field and property: No longer needed after GetAllPublished removal - HasUnsavedChanges(): Duplicated in ContentPublishOperationService where it's used - TryGetParentKey(): Duplicated in ContentMoveOperationService where it's used Kept methods: - Audit() and AuditAsync(): Still used by MoveToRecycleBin and DeleteOfTypes Test refactoring: - DeliveryApiContentIndexHelperTests.GetExpectedNumberOfContentItems() now uses public GetPagedDescendants method instead of internal GetAllPublished 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -35,7 +35,6 @@ public class ContentService : RepositoryService, IContentService
|
||||
private readonly ILogger<ContentService> _logger;
|
||||
private readonly IUserIdKeyResolver _userIdKeyResolver;
|
||||
private readonly IIdKeyMap _idKeyMap;
|
||||
private IQuery<IContent>? _queryNotTrashed;
|
||||
private readonly Lazy<IContentCrudService> _crudServiceLazy;
|
||||
|
||||
// Property for convenient access (deferred resolution for both paths)
|
||||
@@ -128,14 +127,6 @@ public class ContentService : RepositoryService, IContentService
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region Static queries
|
||||
|
||||
// lazy-constructed because when the ctor runs, the query factory may not be ready
|
||||
private IQuery<IContent> QueryNotTrashed =>
|
||||
_queryNotTrashed ??= Query<IContent>().Where(x => x.Trashed == false);
|
||||
|
||||
#endregion
|
||||
|
||||
#region Rollback
|
||||
@@ -451,19 +442,6 @@ public class ContentService : RepositoryService, IContentService
|
||||
public IEnumerable<IContent> GetRootContent()
|
||||
=> CrudService.GetRootContent();
|
||||
|
||||
/// <summary>
|
||||
/// Gets all published content items
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
internal IEnumerable<IContent> GetAllPublished()
|
||||
{
|
||||
using (ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true))
|
||||
{
|
||||
scope.ReadLock(Constants.Locks.ContentTree);
|
||||
return _documentRepository.Get(QueryNotTrashed);
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public IEnumerable<IContent> GetContentForExpiration(DateTime date)
|
||||
=> PublishOperationService.GetContentForExpiration(date);
|
||||
@@ -691,13 +669,6 @@ public class ContentService : RepositoryService, IContentService
|
||||
public IContent? Copy(IContent content, int parentId, bool relateToOriginal, bool recursive, int userId = Constants.Security.SuperUserId)
|
||||
=> MoveOperationService.Copy(content, parentId, relateToOriginal, recursive, userId);
|
||||
|
||||
private bool TryGetParentKey(int parentId, [NotNullWhen(true)] out Guid? parentKey)
|
||||
{
|
||||
Attempt<Guid> parentKeyAttempt = _idKeyMap.GetKeyForId(parentId, UmbracoObjectTypes.Document);
|
||||
parentKey = parentKeyAttempt.Success ? parentKeyAttempt.Result : null;
|
||||
return parentKeyAttempt.Success;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool SendToPublication(IContent? content, int userId = Constants.Security.SuperUserId)
|
||||
=> PublishOperationService.SendToPublication(content, userId);
|
||||
@@ -730,8 +701,6 @@ public class ContentService : RepositoryService, IContentService
|
||||
public OperationResult Sort(IEnumerable<int>? ids, int userId = Constants.Security.SuperUserId)
|
||||
=> MoveOperationService.Sort(ids, userId);
|
||||
|
||||
private static bool HasUnsavedChanges(IContent content) => content.HasIdentity is false || content.IsDirty();
|
||||
|
||||
public ContentDataIntegrityReport CheckDataIntegrity(ContentDataIntegrityReportOptions options)
|
||||
=> CrudService.CheckDataIntegrity(options);
|
||||
|
||||
|
||||
@@ -113,8 +113,11 @@ public class DeliveryApiContentIndexHelperTests : UmbracoIntegrationTestWithCont
|
||||
|
||||
private int GetExpectedNumberOfContentItems()
|
||||
{
|
||||
var result = ContentService.GetAllPublished().Count();
|
||||
Assert.AreEqual(10, result);
|
||||
return result;
|
||||
// Count all non-trashed content items - matching the behavior of the old GetAllPublished method
|
||||
// which was actually getting all non-trashed content, not just published content
|
||||
var allContent = ContentService.GetPagedDescendants(Cms.Core.Constants.System.Root, 0, int.MaxValue, out var total);
|
||||
var nonTrashedCount = allContent.Count(c => !c.Trashed);
|
||||
Assert.AreEqual(10, nonTrashedCount);
|
||||
return nonTrashedCount;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user