U4-9544 Added database schema validation health check and language file updates. (#2674)

This commit is contained in:
OptimisticCoder
2018-06-28 18:37:28 +01:00
committed by Sebastiaan Janssen
parent 477245ee71
commit ffd0adb0f3
4 changed files with 70 additions and 0 deletions

View File

@@ -2063,6 +2063,10 @@ To manage your website, simply open the Umbraco back office and start adding con
<key alias="xmlDataIntegrityCheckMedia">Media - Total XML: %0%, Total: %1%, Total invalid: %2%</key>
<key alias="xmlDataIntegrityCheckContent">Content - Total XML: %0%, Total published: %1%, Total invalid: %2%</key>
<key alias="databaseSchemaValidationCheckDatabaseOk">Database - The database schema is correct for this version of Umbraco</key>
<key alias="databaseSchemaValidationCheckDatabaseErrors">%0% problems were detected with your database schema (Check the log for details)</key>
<key alias="databaseSchemaValidationCheckDatabaseLogMessage">Some errors were detected while validating the database schema against the current version of Umbraco.</key>
<key alias="httpsCheckValidCertificate">Your website's certificate is valid.</key>
<key alias="httpsCheckInvalidCertificate">Certificate validation error: '%0%'</key>
<key alias="httpsCheckExpiredCertificate">Your website's SSL certificate has expired.</key>

View File

@@ -2054,6 +2054,10 @@ To manage your website, simply open the Umbraco back office and start adding con
<key alias="xmlDataIntegrityCheckMedia">Media - Total XML: %0%, Total: %1%, Total invalid: %2%</key>
<key alias="xmlDataIntegrityCheckContent">Content - Total XML: %0%, Total published: %1%, Total invalid: %2%</key>
<key alias="databaseSchemaValidationCheckDatabaseOk">Database - The database schema is correct for this version of Umbraco</key>
<key alias="databaseSchemaValidationCheckDatabaseErrors">%0% problems were detected with your database schema (Check the log for details)</key>
<key alias="databaseSchemaValidationCheckDatabaseLogMessage">Some errors were detected while validating the database schema against the current version of Umbraco.</key>
<key alias="httpsCheckValidCertificate">Your website's certificate is valid.</key>
<key alias="httpsCheckInvalidCertificate">Certificate validation error: '%0%'</key>
<key alias="httpsCheckExpiredCertificate">Your website's SSL certificate has expired.</key>

View File

@@ -0,0 +1,61 @@
using System.Collections.Generic;
using Umbraco.Core;
using Umbraco.Core.Logging;
using Umbraco.Core.Services;
namespace Umbraco.Web.HealthCheck.Checks.DataIntegrity
{
/// <summary>
/// U4-9544 Health check to detect if the database has any missing indexes or constraints
/// </summary>
[HealthCheck(
"0873D589-2064-4EA3-A152-C43417FE00A4",
"Database Schema Validation",
Description = "This checks the Umbraco database by doing a comparison of current indexes and schema items with the current state of the database and returns any problems it found. Useful to detect if the database hasn't been upgraded correctly.",
Group = "Data Integrity")]
public class DatabaseSchemaValidationHealthCheck : HealthCheck
{
private readonly DatabaseContext _databaseContext;
private readonly ILocalizedTextService _textService;
public DatabaseSchemaValidationHealthCheck(HealthCheckContext healthCheckContext) : base(healthCheckContext)
{
_databaseContext = HealthCheckContext.ApplicationContext.DatabaseContext;
_textService = healthCheckContext.ApplicationContext.Services.TextService;
}
public override HealthCheckStatus ExecuteAction(HealthCheckAction action)
{
return CheckDatabase();
}
public override IEnumerable<HealthCheckStatus> GetStatus()
{
//return the statuses
return new[] { CheckDatabase() };
}
private HealthCheckStatus CheckDatabase()
{
var results = _databaseContext.ValidateDatabaseSchema();
LogHelper.Warn(typeof(DatabaseSchemaValidationHealthCheck), _textService.Localize("databaseSchemaValidationCheckDatabaseLogMessage"));
foreach(var error in results.Errors)
{
LogHelper.Warn(typeof(DatabaseSchemaValidationHealthCheck), error.Item1 + ": " + error.Item2);
}
if(results.Errors.Count > 0)
return new HealthCheckStatus(_textService.Localize("healthcheck/databaseSchemaValidationCheckDatabaseErrors", new[] { results.Errors.Count.ToString() }))
{
ResultType = StatusResultType.Error,
View = "Umbraco.Dashboard.DatabaseSchemaValidationController"
};
return new HealthCheckStatus(_textService.Localize("healthcheck/databaseSchemaValidationCheckDatabaseOk"))
{
ResultType = StatusResultType.Success
};
}
}
}

View File

@@ -338,6 +338,7 @@
<Compile Include="Editors\CodeFileController.cs" />
<Compile Include="Editors\TourController.cs" />
<Compile Include="Features\EnabledFeatures.cs" />
<Compile Include="HealthCheck\Checks\DataIntegrity\DatabaseSchemaValidationHealthCheck.cs" />
<Compile Include="HealthCheck\Checks\Security\XssProtectionCheck.cs" />
<Compile Include="HealthCheck\Checks\Security\HstsCheck.cs" />
<Compile Include="Models\BackOfficeTourFilter.cs" />