("Database configuration status: Started");
- string message;
-
- var database = new UmbracoDatabase(_connectionString, ProviderName, _logger);
+ var database = _factory.GetDatabase();
// If MySQL, we're going to ensure that database calls are maintaining proper casing as to remove the necessity for checks
// for case insensitive queries. In an ideal situation (which is what we're striving for), all calls would be case sensitive.
- /*
+ /*
var supportsCaseInsensitiveQueries = SqlSyntax.SupportsCaseInsensitiveQueries(database);
if (supportsCaseInsensitiveQueries == false)
{
@@ -549,16 +381,14 @@ namespace Umbraco.Core
}
*/
- message = GetResultMessageForMySql();
-
+ var message = GetResultMessageForMySql();
var schemaResult = ValidateDatabaseSchema();
-
var installedSchemaVersion = schemaResult.DetermineInstalledVersion();
-
+
//If Configuration Status is empty and the determined version is "empty" its a new install - otherwise upgrade the existing
if (string.IsNullOrEmpty(GlobalSettings.ConfigurationStatus) && installedSchemaVersion.Equals(new Version(0, 0, 0)))
{
- var helper = new DatabaseSchemaHelper(database, _logger, SqlSyntax);
+ var helper = new DatabaseSchemaHelper(database, _logger);
helper.CreateDatabaseSchema(true, applicationContext);
message = message + "Installation completed!
";
@@ -573,9 +403,9 @@ namespace Umbraco.Core
message = "Upgrading database, this may take some time...
";
return new Result
{
- RequiresUpgrade = true,
- Message = message,
- Success = true,
+ RequiresUpgrade = true,
+ Message = message,
+ Success = true,
Percentage = "30"
};
}
@@ -593,7 +423,6 @@ namespace Umbraco.Core
{
try
{
-
var readyForInstall = CheckReadyForInstall();
if (readyForInstall.Success == false)
{
@@ -602,8 +431,8 @@ namespace Umbraco.Core
_logger.Info("Database upgrade started");
- var database = new UmbracoDatabase(_connectionString, ProviderName, _logger);
- //var supportsCaseInsensitiveQueries = SqlSyntax.SupportsCaseInsensitiveQueries(database);
+ var database = _factory.GetDatabase();
+ //var supportsCaseInsensitiveQueries = SqlSyntax.SupportsCaseInsensitiveQueries(database);
var message = GetResultMessageForMySql();
@@ -615,33 +444,33 @@ namespace Umbraco.Core
//we cannot check the migrations table if it doesn't exist, this will occur when upgrading to 7.3
if (schemaResult.ValidTables.Any(x => x.InvariantEquals("umbracoMigration")))
{
- installedMigrationVersion = schemaResult.DetermineInstalledVersionByMigrations(migrationEntryService);
+ installedMigrationVersion = schemaResult.DetermineInstalledVersionByMigrations(migrationEntryService);
}
var targetVersion = UmbracoVersion.Current;
-
+
//In some cases - like upgrading from 7.2.6 -> 7.3, there will be no migration information in the database and therefore it will
- // return a version of 0.0.0 and we don't necessarily want to run all migrations from 0 -> 7.3, so we'll just ensure that the
+ // return a version of 0.0.0 and we don't necessarily want to run all migrations from 0 -> 7.3, so we'll just ensure that the
// migrations are run for the target version
if (installedMigrationVersion == new SemVersion(new Version(0, 0, 0)) && installedSchemaVersion > new SemVersion(new Version(0, 0, 0)))
{
//set the installedMigrationVersion to be one less than the target so the latest migrations are guaranteed to execute
installedMigrationVersion = new SemVersion(targetVersion.SubtractRevision());
}
-
+
//Figure out what our current installed version is. If the web.config doesn't have a version listed, then we'll use the minimum
- // version detected between the schema installed and the migrations listed in the migration table.
+ // version detected between the schema installed and the migrations listed in the migration table.
// If there is a version in the web.config, we'll take the minimum between the listed migration in the db and what
// is declared in the web.config.
-
+
var currentInstalledVersion = string.IsNullOrEmpty(GlobalSettings.ConfigurationStatus)
//Take the minimum version between the detected schema version and the installed migration version
? new[] {installedSchemaVersion, installedMigrationVersion}.Min()
//Take the minimum version between the installed migration version and the version specified in the config
: new[] { SemVersion.Parse(GlobalSettings.ConfigurationStatus), installedMigrationVersion }.Min();
- //Ok, another edge case here. If the current version is a pre-release,
- // then we want to ensure all migrations for the current release are executed.
+ //Ok, another edge case here. If the current version is a pre-release,
+ // then we want to ensure all migrations for the current release are executed.
if (currentInstalledVersion.Prerelease.IsNullOrWhiteSpace() == false)
{
currentInstalledVersion = new SemVersion(currentInstalledVersion.GetVersion().SubtractRevision());
@@ -651,8 +480,8 @@ namespace Umbraco.Core
var runner = new MigrationRunner(migrationResolver, migrationEntryService, _logger, currentInstalledVersion, UmbracoVersion.GetSemanticVersion(), GlobalSettings.UmbracoMigrationName);
- var upgraded = runner.Execute(database, DatabaseProvider, SqlSyntax, true);
-
+ var upgraded = runner.Execute(database /*, true*/);
+
if (upgraded == false)
{
throw new ApplicationException("Upgrading failed, either an error occurred during the upgrade process or an event canceled the upgrade process, see log for full details");
@@ -716,18 +545,12 @@ namespace Umbraco.Core
private Attempt CheckReadyForInstall()
{
- if (SystemUtilities.GetCurrentTrustLevel() != AspNetHostingPermissionLevel.Unrestricted
- && ProviderName == "MySql.Data.MySqlClient")
- {
- throw new InvalidOperationException("Cannot use MySql in Medium Trust configuration");
- }
-
- if (_configured == false || (string.IsNullOrEmpty(_connectionString) || string.IsNullOrEmpty(ProviderName)))
+ if (_factory.Configured == false)
{
return Attempt.Fail(new Result
{
- Message =
- "Database configuration is invalid. Please check that the entered database exists and that the provided username and password has write access to the database.",
+ Message = "Database configuration is invalid. Please check that the entered database exists and"
+ + " that the provided username and password has write access to the database.",
Success = false,
Percentage = "10"
});
@@ -739,9 +562,9 @@ namespace Umbraco.Core
{
_logger.Error("Database configuration failed", ex);
- if (_result != null)
+ if (_databaseSchemaValidationResult != null)
{
- _logger.Info("The database schema validation produced the following summary: \n" + _result.GetSummary());
+ _logger.Info("The database schema validation produced the following summary: \n" + _databaseSchemaValidationResult.GetSummary());
}
return new Result
@@ -762,11 +585,13 @@ namespace Umbraco.Core
public string Percentage { get; set; }
}
+ #endregion
+
internal bool IsConnectionStringConfigured(ConnectionStringSettings databaseSettings)
{
var dbIsSqlCe = false;
- if (databaseSettings != null && databaseSettings.ProviderName != null)
- dbIsSqlCe = databaseSettings.ProviderName == "System.Data.SqlServerCe.4.0";
+ if (databaseSettings?.ProviderName != null)
+ dbIsSqlCe = databaseSettings.ProviderName == Constants.DbProviderNames.SqlCe;
var sqlCeDatabaseExists = false;
if (dbIsSqlCe)
{
@@ -776,7 +601,7 @@ namespace Umbraco.Core
{
var datasource = dataSourcePart.Replace("|DataDirectory|", AppDomain.CurrentDomain.GetData("DataDirectory").ToString());
var filePath = datasource.Replace("Data Source=", string.Empty);
- sqlCeDatabaseExists = File.Exists(filePath);
+ sqlCeDatabaseExists = File.Exists(filePath);
}
}
@@ -791,9 +616,10 @@ namespace Umbraco.Core
return true;
}
+ // fixme - kill!
public Sql Sql()
{
- return NPoco.Sql.BuilderFor(new SqlContext(SqlSyntax, Database));
+ return Database.Sql();
}
}
}
\ No newline at end of file
diff --git a/src/Umbraco.Core/DependencyInjection/RepositoryCompositionRoot.cs b/src/Umbraco.Core/DependencyInjection/RepositoryCompositionRoot.cs
index f6ff4f1914..b4370b886e 100644
--- a/src/Umbraco.Core/DependencyInjection/RepositoryCompositionRoot.cs
+++ b/src/Umbraco.Core/DependencyInjection/RepositoryCompositionRoot.cs
@@ -1,9 +1,4 @@
-using System;
-using System.Linq;
using LightInject;
-using Umbraco.Core.Cache;
-using Umbraco.Core.Configuration;
-using Umbraco.Core.Configuration.UmbracoSettings;
using Umbraco.Core.IO;
using Umbraco.Core.Logging;
using Umbraco.Core.Persistence;
@@ -19,24 +14,42 @@ namespace Umbraco.Core.DependencyInjection
///