diff --git a/src/Umbraco.Web.UI/umbraco/config/lang/en.xml b/src/Umbraco.Web.UI/umbraco/config/lang/en.xml index af7e8856d6..ac86a39161 100644 --- a/src/Umbraco.Web.UI/umbraco/config/lang/en.xml +++ b/src/Umbraco.Web.UI/umbraco/config/lang/en.xml @@ -2063,6 +2063,10 @@ To manage your website, simply open the Umbraco back office and start adding con Media - Total XML: %0%, Total: %1%, Total invalid: %2% Content - Total XML: %0%, Total published: %1%, Total invalid: %2% + Database - The database schema is correct for this version of Umbraco + %0% problems were detected with your database schema (Check the log for details) + Some errors were detected while validating the database schema against the current version of Umbraco. + Your website's certificate is valid. Certificate validation error: '%0%' Your website's SSL certificate has expired. diff --git a/src/Umbraco.Web.UI/umbraco/config/lang/en_us.xml b/src/Umbraco.Web.UI/umbraco/config/lang/en_us.xml index e5e1aaa317..07e706dd09 100644 --- a/src/Umbraco.Web.UI/umbraco/config/lang/en_us.xml +++ b/src/Umbraco.Web.UI/umbraco/config/lang/en_us.xml @@ -2054,6 +2054,10 @@ To manage your website, simply open the Umbraco back office and start adding con Media - Total XML: %0%, Total: %1%, Total invalid: %2% Content - Total XML: %0%, Total published: %1%, Total invalid: %2% + Database - The database schema is correct for this version of Umbraco + %0% problems were detected with your database schema (Check the log for details) + Some errors were detected while validating the database schema against the current version of Umbraco. + Your website's certificate is valid. Certificate validation error: '%0%' Your website's SSL certificate has expired. diff --git a/src/Umbraco.Web/HealthCheck/Checks/DataIntegrity/DatabaseSchemaValidationHealthCheck.cs b/src/Umbraco.Web/HealthCheck/Checks/DataIntegrity/DatabaseSchemaValidationHealthCheck.cs new file mode 100644 index 0000000000..6ea562b2c7 --- /dev/null +++ b/src/Umbraco.Web/HealthCheck/Checks/DataIntegrity/DatabaseSchemaValidationHealthCheck.cs @@ -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 +{ + /// + /// U4-9544 Health check to detect if the database has any missing indexes or constraints + /// + [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 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 + }; + } + } +} diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj index 96b427d122..6dd0af493f 100644 --- a/src/Umbraco.Web/Umbraco.Web.csproj +++ b/src/Umbraco.Web/Umbraco.Web.csproj @@ -338,6 +338,7 @@ +