refactor(core): extract CheckDataIntegrity to ContentCrudService
Move CheckDataIntegrity from ContentService to ContentCrudService. Add IShortStringHelper dependency to ContentCrudService. Remove IShortStringHelper from ContentService as it's no longer needed. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -315,7 +315,6 @@ namespace Umbraco.Cms.Core.DependencyInjection
|
||||
sp.GetRequiredService<IDocumentRepository>(),
|
||||
sp.GetRequiredService<IAuditService>(),
|
||||
sp.GetRequiredService<IContentTypeRepository>(),
|
||||
sp.GetRequiredService<IShortStringHelper>(),
|
||||
sp.GetRequiredService<IUserIdKeyResolver>(),
|
||||
sp.GetRequiredService<IIdKeyMap>(),
|
||||
sp.GetRequiredService<IContentCrudService>(),
|
||||
|
||||
@@ -8,6 +8,7 @@ using Umbraco.Cms.Core.Persistence.Querying;
|
||||
using Umbraco.Cms.Core.Persistence.Repositories;
|
||||
using Umbraco.Cms.Core.Scoping;
|
||||
using Umbraco.Cms.Core.Services.Changes;
|
||||
using Umbraco.Cms.Core.Strings;
|
||||
using Umbraco.Extensions;
|
||||
|
||||
namespace Umbraco.Cms.Core.Services;
|
||||
@@ -20,6 +21,7 @@ public class ContentCrudService : ContentServiceBase, IContentCrudService
|
||||
private readonly IEntityRepository _entityRepository;
|
||||
private readonly IContentTypeRepository _contentTypeRepository;
|
||||
private readonly ILanguageRepository _languageRepository;
|
||||
private readonly IShortStringHelper _shortStringHelper;
|
||||
private readonly ILogger<ContentCrudService> _logger;
|
||||
|
||||
public ContentCrudService(
|
||||
@@ -31,12 +33,14 @@ public class ContentCrudService : ContentServiceBase, IContentCrudService
|
||||
IContentTypeRepository contentTypeRepository,
|
||||
IAuditService auditService,
|
||||
IUserIdKeyResolver userIdKeyResolver,
|
||||
ILanguageRepository languageRepository)
|
||||
ILanguageRepository languageRepository,
|
||||
IShortStringHelper shortStringHelper)
|
||||
: base(provider, loggerFactory, eventMessagesFactory, documentRepository, auditService, userIdKeyResolver)
|
||||
{
|
||||
_entityRepository = entityRepository ?? throw new ArgumentNullException(nameof(entityRepository));
|
||||
_contentTypeRepository = contentTypeRepository ?? throw new ArgumentNullException(nameof(contentTypeRepository));
|
||||
_languageRepository = languageRepository ?? throw new ArgumentNullException(nameof(languageRepository));
|
||||
_shortStringHelper = shortStringHelper ?? throw new ArgumentNullException(nameof(shortStringHelper));
|
||||
_logger = loggerFactory.CreateLogger<ContentCrudService>();
|
||||
}
|
||||
|
||||
@@ -529,6 +533,31 @@ public class ContentCrudService : ContentServiceBase, IContentCrudService
|
||||
|
||||
#endregion
|
||||
|
||||
#region Data Integrity
|
||||
|
||||
/// <inheritdoc />
|
||||
public ContentDataIntegrityReport CheckDataIntegrity(ContentDataIntegrityReportOptions options)
|
||||
{
|
||||
using (ICoreScope scope = ScopeProvider.CreateCoreScope())
|
||||
{
|
||||
scope.WriteLock(Constants.Locks.ContentTree);
|
||||
|
||||
ContentDataIntegrityReport report = DocumentRepository.CheckDataIntegrity(options);
|
||||
|
||||
if (report.FixedIssues.Count > 0)
|
||||
{
|
||||
var root = new Content("root", -1, new ContentType(_shortStringHelper, -1)) { Id = -1, Key = Guid.Empty };
|
||||
scope.Notifications.Publish(new ContentTreeChangeNotification(root, TreeChangeTypes.RefreshAll, EventMessagesFactory.Get()));
|
||||
}
|
||||
|
||||
scope.Complete();
|
||||
|
||||
return report;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private Helpers
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -20,7 +20,6 @@ using Umbraco.Cms.Core.Persistence.Repositories;
|
||||
using Umbraco.Cms.Core.PropertyEditors;
|
||||
using Umbraco.Cms.Core.Scoping;
|
||||
using Umbraco.Cms.Core.Services.Changes;
|
||||
using Umbraco.Cms.Core.Strings;
|
||||
using Umbraco.Extensions;
|
||||
|
||||
namespace Umbraco.Cms.Core.Services;
|
||||
@@ -34,7 +33,6 @@ public class ContentService : RepositoryService, IContentService
|
||||
private readonly IContentTypeRepository _contentTypeRepository;
|
||||
private readonly IDocumentRepository _documentRepository;
|
||||
private readonly ILogger<ContentService> _logger;
|
||||
private readonly IShortStringHelper _shortStringHelper;
|
||||
private readonly IUserIdKeyResolver _userIdKeyResolver;
|
||||
private readonly IIdKeyMap _idKeyMap;
|
||||
private IQuery<IContent>? _queryNotTrashed;
|
||||
@@ -89,7 +87,6 @@ public class ContentService : RepositoryService, IContentService
|
||||
IDocumentRepository documentRepository,
|
||||
IAuditService auditService,
|
||||
IContentTypeRepository contentTypeRepository,
|
||||
IShortStringHelper shortStringHelper,
|
||||
IUserIdKeyResolver userIdKeyResolver,
|
||||
IIdKeyMap idKeyMap,
|
||||
IContentCrudService crudService,
|
||||
@@ -104,7 +101,6 @@ public class ContentService : RepositoryService, IContentService
|
||||
_documentRepository = documentRepository;
|
||||
_auditService = auditService;
|
||||
_contentTypeRepository = contentTypeRepository;
|
||||
_shortStringHelper = shortStringHelper;
|
||||
_userIdKeyResolver = userIdKeyResolver;
|
||||
_idKeyMap = idKeyMap;
|
||||
_logger = loggerFactory.CreateLogger<ContentService>();
|
||||
@@ -737,25 +733,7 @@ public class ContentService : RepositoryService, IContentService
|
||||
private static bool HasUnsavedChanges(IContent content) => content.HasIdentity is false || content.IsDirty();
|
||||
|
||||
public ContentDataIntegrityReport CheckDataIntegrity(ContentDataIntegrityReportOptions options)
|
||||
{
|
||||
using (ICoreScope scope = ScopeProvider.CreateCoreScope())
|
||||
{
|
||||
scope.WriteLock(Constants.Locks.ContentTree);
|
||||
|
||||
ContentDataIntegrityReport report = _documentRepository.CheckDataIntegrity(options);
|
||||
|
||||
if (report.FixedIssues.Count > 0)
|
||||
{
|
||||
// The event args needs a content item so we'll make a fake one with enough properties to not cause a null ref
|
||||
var root = new Content("root", -1, new ContentType(_shortStringHelper, -1)) { Id = -1, Key = Guid.Empty };
|
||||
scope.Notifications.Publish(new ContentTreeChangeNotification(root, TreeChangeTypes.RefreshAll, EventMessagesFactory.Get()));
|
||||
}
|
||||
|
||||
scope.Complete();
|
||||
|
||||
return report;
|
||||
}
|
||||
}
|
||||
=> CrudService.CheckDataIntegrity(options);
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
@@ -259,4 +259,15 @@ public interface IContentCrudService : IService
|
||||
void DeleteLocked(ICoreScope scope, IContent content, EventMessages evtMsgs);
|
||||
|
||||
#endregion
|
||||
|
||||
#region Data Integrity
|
||||
|
||||
/// <summary>
|
||||
/// Checks content data integrity and optionally fixes issues.
|
||||
/// </summary>
|
||||
/// <param name="options">Options for the integrity check.</param>
|
||||
/// <returns>A report of detected and fixed issues.</returns>
|
||||
ContentDataIntegrityReport CheckDataIntegrity(ContentDataIntegrityReportOptions options);
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user