updates health check
This commit is contained in:
@@ -489,7 +489,8 @@ namespace Umbraco.Core.Persistence.Repositories.Implement
|
||||
|
||||
var nodesToRebuild = new Dictionary<int, List<NodeDto>>();
|
||||
var validNodes = new Dictionary<int, NodeDto>();
|
||||
var currentParentIds = new HashSet<int> { -1 };
|
||||
var rootIds = new[] {Constants.System.Root, Constants.System.RecycleBinContent, Constants.System.RecycleBinMedia};
|
||||
var currentParentIds = new HashSet<int>(rootIds);
|
||||
var prevParentIds = currentParentIds;
|
||||
var lastLevel = -1;
|
||||
|
||||
@@ -512,7 +513,8 @@ namespace Umbraco.Core.Persistence.Repositories.Implement
|
||||
|
||||
currentParentIds.Add(node.NodeId);
|
||||
|
||||
var pathParts = node.Path.Split(',');
|
||||
// paths parts without the roots
|
||||
var pathParts = node.Path.Split(',').Where(x => !rootIds.Contains(int.Parse(x))).ToArray();
|
||||
|
||||
if (!prevParentIds.Contains(node.ParentId))
|
||||
{
|
||||
@@ -520,13 +522,13 @@ namespace Umbraco.Core.Persistence.Repositories.Implement
|
||||
report.Add(node.NodeId, new ContentDataIntegrityReportEntry(ContentDataIntegrityReport.IssueType.InvalidPathAndLevelByParentId));
|
||||
AppendNodeToFix(nodesToRebuild, node);
|
||||
}
|
||||
else if (pathParts.Length < 2)
|
||||
else if (pathParts.Length == 0)
|
||||
{
|
||||
// invalid path
|
||||
report.Add(node.NodeId, new ContentDataIntegrityReportEntry(ContentDataIntegrityReport.IssueType.InvalidPathEmpty));
|
||||
AppendNodeToFix(nodesToRebuild, node);
|
||||
}
|
||||
else if (pathParts.Length - 1 != node.Level)
|
||||
else if (pathParts.Length != node.Level)
|
||||
{
|
||||
// invalid, either path or level is wrong
|
||||
report.Add(node.NodeId, new ContentDataIntegrityReportEntry(ContentDataIntegrityReport.IssueType.InvalidPathLevelMismatch));
|
||||
@@ -538,7 +540,7 @@ namespace Umbraco.Core.Persistence.Repositories.Implement
|
||||
report.Add(node.NodeId, new ContentDataIntegrityReportEntry(ContentDataIntegrityReport.IssueType.InvalidPathById));
|
||||
AppendNodeToFix(nodesToRebuild, node);
|
||||
}
|
||||
else if (pathParts[pathParts.Length - 2] != node.ParentId.ToString())
|
||||
else if (!rootIds.Contains(node.ParentId) && pathParts[pathParts.Length - 2] != node.ParentId.ToString())
|
||||
{
|
||||
// invalid path
|
||||
report.Add(node.NodeId, new ContentDataIntegrityReportEntry(ContentDataIntegrityReport.IssueType.InvalidPathByParentId));
|
||||
|
||||
@@ -45,22 +45,22 @@ namespace Umbraco.Web.HealthCheck.Checks.Data
|
||||
|
||||
private HealthCheckStatus CheckMedia(bool fix)
|
||||
{
|
||||
return CheckPaths(_fixMediaPaths, _fixMediaPathsTitle, Core.Constants.UdiEntityType.Media,
|
||||
return CheckPaths(_fixMediaPaths, _fixMediaPathsTitle, Core.Constants.UdiEntityType.Media, fix,
|
||||
() => _mediaService.CheckDataIntegrity(new ContentDataIntegrityReportOptions {FixIssues = fix}));
|
||||
}
|
||||
|
||||
private HealthCheckStatus CheckDocuments(bool fix)
|
||||
{
|
||||
return CheckPaths(_fixContentPaths, _fixContentPathsTitle, Core.Constants.UdiEntityType.Document,
|
||||
return CheckPaths(_fixContentPaths, _fixContentPathsTitle, Core.Constants.UdiEntityType.Document, fix,
|
||||
() => _contentService.CheckDataIntegrity(new ContentDataIntegrityReportOptions {FixIssues = fix}));
|
||||
}
|
||||
|
||||
private HealthCheckStatus CheckPaths(string actionAlias, string actionName, string entityType, Func<ContentDataIntegrityReport> doCheck)
|
||||
private HealthCheckStatus CheckPaths(string actionAlias, string actionName, string entityType, bool detailedReport, Func<ContentDataIntegrityReport> doCheck)
|
||||
{
|
||||
var result = doCheck();
|
||||
var report = doCheck();
|
||||
|
||||
var actions = new List<HealthCheckAction>();
|
||||
if (!result.Ok)
|
||||
if (!report.Ok)
|
||||
{
|
||||
actions.Add(new HealthCheckAction(actionAlias, Id)
|
||||
{
|
||||
@@ -68,15 +68,37 @@ namespace Umbraco.Web.HealthCheck.Checks.Data
|
||||
});
|
||||
}
|
||||
|
||||
return new HealthCheckStatus(result.Ok
|
||||
return new HealthCheckStatus(report.Ok
|
||||
? $"All {entityType} paths are valid"
|
||||
: $"There are {result.DetectedIssues.Count} invalid {entityType} paths")
|
||||
: GetInvalidReport(report, entityType, detailedReport))
|
||||
{
|
||||
ResultType = result.Ok ? StatusResultType.Success : StatusResultType.Error,
|
||||
ResultType = report.Ok ? StatusResultType.Success : StatusResultType.Error,
|
||||
Actions = actions
|
||||
};
|
||||
}
|
||||
|
||||
private static string GetInvalidReport(ContentDataIntegrityReport report, string entityType, bool detailed)
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
sb.AppendLine($"There are {report.DetectedIssues.Count} invalid {entityType} paths");
|
||||
|
||||
if (true && report.DetectedIssues.Count > 0)
|
||||
{
|
||||
sb.AppendLine("<ul>");
|
||||
foreach (var issueGroup in report.DetectedIssues.GroupBy(x => x.Value.IssueType))
|
||||
{
|
||||
var countByGroup = issueGroup.Count();
|
||||
var fixedByGroup = issueGroup.Count(x => x.Value.Fixed);
|
||||
sb.AppendLine("<li>");
|
||||
sb.AppendLine($"{countByGroup} issues of type <code>{issueGroup.Key}</code> ... {fixedByGroup} fixed");
|
||||
sb.AppendLine("</li>");
|
||||
}
|
||||
sb.AppendLine("</ul>");
|
||||
}
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
public override HealthCheckStatus ExecuteAction(HealthCheckAction action)
|
||||
{
|
||||
return action.Alias switch
|
||||
|
||||
Reference in New Issue
Block a user